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.void
The configuration should include a "users" list which contains zero or more objects with properties including "name", "plaintext" and "credentials"void
initialize
(HttpServer htserver, String prefix, Json info) Initialize the HttpServer on startup.protected JWT
Verify the user/password.protected void
Log out the specified userboolean
matches
(Principal principal, Credential credential) Return true if the specified credential is usable by this user.void
Set the Server this Authorization is working fortype()
Returns "basic"
-
Constructor Details
-
BasicAuthorization
public BasicAuthorization()
-
-
Method Details
-
type
Returns "basic"- Specified by:
type
in classAuthorization
- Returns:
- the type
-
setServer
Description copied from class:Authorization
Set the Server this Authorization is working for- Specified by:
setServer
in classAuthorization
- Parameters:
server
- the server
-
matches
Description copied from class:Authorization
Return 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:
matches
in classAuthorization
- Parameters:
principal
- the principalcredential
- the credential- Returns:
- true if the key can be used by this principal
-
configure
The configuration should include a "users" list which contains zero or more objects with properties including "name", "plaintext" and "credentials"- Specified by:
configure
in classAuthorization
- Parameters:
config
- the server configuration
-
initialize
Description copied from class:Authorization
Initialize the HttpServer on startup.- Specified by:
initialize
in 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:Authorization
Authorize 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:
authorize
in classAuthorization
- Parameters:
exchange
- the HttpExchange- Returns:
- the Principal, which may be
Authorization.ANONYMOUS
, aJWT
, aX500Principal
or something else - Throws:
IOException
- for IOException
-
logout
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
-