Package com.bfo.netkeystore.server
Class BasicAuthorization
java.lang.Object
com.bfo.netkeystore.server.Authorization
com.bfo.netkeystore.server.BasicAuthorization
An implementation of Authorization that supports "basic" authentication.
-
Field Summary
Fields inherited from class com.bfo.netkeystore.server.Authorization
ANONYMOUS, OPEN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthorize(HttpExchange exchange) Authorize the HTTP exchange.voidconfigure(Json config) The configuration should include a "users" list which contains zero or more objects with properties including "name", "plaintext" and "credentials"voidinitialize(HttpServer htserver, String prefix, Json info) Initialize the HttpServer on startup.protected JWTVerify the user/password.protected voidlogout(JWT principal) Log out the specified userbooleanmatches(Principal principal, Credential credential) Return true if the specified credential is usable by this user.voidSet the Server this Authorization is working fortype()Returns "basic"
-
Constructor Details
-
BasicAuthorization
public BasicAuthorization()
-
-
Method Details
-
type
Returns "basic"- Specified by:
typein classAuthorization- Returns:
- the type
-
setServer
Description copied from class:AuthorizationSet the Server this Authorization is working for- Specified by:
setServerin classAuthorization- Parameters:
server- the server
-
matches
Description copied from class:AuthorizationReturn true if the specified credential is usable by this user. This is a secondary test to the one built-in to the server, which checks the "users" property on each key. It could be extended to match X.509 certificates on the key to the SSL client certificate, for example. The default implementation always returns true.- Specified by:
matchesin classAuthorization- Parameters:
principal- the principalcredential- the credential- Returns:
- true if the key can be used by this principal
-
configure
public void configure(Json config) The configuration should include a "users" list which contains zero or more objects with properties including "name", "plaintext" and "credentials"- Specified by:
configurein classAuthorization- Parameters:
config- the server configuration
-
initialize
Description copied from class:AuthorizationInitialize the HttpServer on startup.- Specified by:
initializein classAuthorization- Parameters:
htserver- the HttpServer to add methods or configure TLS authentication onprefix- the base prefix for any methods being added - typically this is something like "/csc/v1".info- a template for the info response, which can have values added to it - for example, adding "auth/login" to the "methods" list
-
authorize
Description copied from class:AuthorizationAuthorize the HTTP exchange. Return the Principal if authorized and normal processing should continue, or null if this method has intercepted the exchange and sent a 401 error due to authorization failure.- Specified by:
authorizein classAuthorization- Parameters:
exchange- the HttpExchange- Returns:
- the Principal, which may be
Authorization.ANONYMOUS, aJWT, aX500Principalor something else - Throws:
IOException- for IOException
-
logout
protected void logout(JWT principal) Log out the specified user- Parameters:
principal- the principal
-
login
Verify the user/password. If verified, return the list of credentials they can access, or null if they can access all of them. A custom implementation could overrride this method to use an external source for this data- Parameters:
userid- the userpassword- the password- Returns:
- the JWT representing the user, or null if the login details are invalid
- Throws:
RuntimeException- if the login is invalid
-