Class JwtHttpSecuritySource<C>
- java.lang.Object
-
- net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
-
- net.officefloor.web.jwt.JwtHttpSecuritySource<C>
-
- All Implemented Interfaces:
HttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
,HttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
public class JwtHttpSecuritySource<C> extends AbstractHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows> implements HttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
HttpSecuritySource
for JWT.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JwtHttpSecuritySource.Flows
Flow keys.static class
JwtHttpSecuritySource.JwtClaims
JWT claims.static class
JwtHttpSecuritySource.JwtHeader
JWT header.static interface
JwtHttpSecuritySource.JwtValidateKeysFactory
Allows overriding the creation ofJwtValidateKey
instances.-
Nested classes/interfaces inherited from class net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource
AbstractHttpSecuritySource.DependencyLabeller, AbstractHttpSecuritySource.Labeller, AbstractHttpSecuritySource.MetaDataContext<A,AC extends java.io.Serializable,C,O extends java.lang.Enum<O>,F extends java.lang.Enum<F>>, AbstractHttpSecuritySource.SpecificationContext
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AUTHENTICATION_SCHEME_BEARER
Authentication scheme Bearer.static long
DEFAULT_CLOCK_SKEW
Default value forPROPERTY_CLOCK_SKEW
.static long
DEFAULT_STARTUP_TIMEOUT
Default value forPROEPRTY_STARTUP_TIMEOUT
.static java.lang.String
PROEPRTY_STARTUP_TIMEOUT
Property
name for the startup timeout in milliseconds.static java.lang.String
PROPERTY_CLAIMS_CLASS
Property
name for the claimsClass
to be loaded with claim information of JWT.static java.lang.String
PROPERTY_CLOCK_SKEW
Property
name for the clock skew in seconds.-
Fields inherited from class net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource
UTF_8
-
-
Constructor Summary
Constructors Constructor Description JwtHttpSecuritySource()
-
Method Summary
-
Methods inherited from class net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource
getSpecification, init, stop
-
-
-
-
Field Detail
-
AUTHENTICATION_SCHEME_BEARER
public static final java.lang.String AUTHENTICATION_SCHEME_BEARER
Authentication scheme Bearer.- See Also:
- Constant Field Values
-
PROPERTY_CLAIMS_CLASS
public static final java.lang.String PROPERTY_CLAIMS_CLASS
Property
name for the claimsClass
to be loaded with claim information of JWT.- See Also:
- Constant Field Values
-
PROEPRTY_STARTUP_TIMEOUT
public static final java.lang.String PROEPRTY_STARTUP_TIMEOUT
Property
name for the startup timeout in milliseconds.This is the time that
HttpRequest
instances are held up waiting the for the initialJwtValidateKey
instances to be loaded.- See Also:
- Constant Field Values
-
DEFAULT_STARTUP_TIMEOUT
public static final long DEFAULT_STARTUP_TIMEOUT
Default value forPROEPRTY_STARTUP_TIMEOUT
.- See Also:
- Constant Field Values
-
PROPERTY_CLOCK_SKEW
public static final java.lang.String PROPERTY_CLOCK_SKEW
Property
name for the clock skew in seconds.- See Also:
- Constant Field Values
-
DEFAULT_CLOCK_SKEW
public static final long DEFAULT_CLOCK_SKEW
Default value forPROPERTY_CLOCK_SKEW
.- See Also:
- Constant Field Values
-
-
Method Detail
-
setOverrideKeys
public static void setOverrideKeys(JwtHttpSecuritySource.JwtValidateKeysFactory validateKeysFactory)
Uses the
JwtHttpSecuritySource.JwtValidateKeysFactory
for keys.This is typically used for testing to allow overriding the
JwtValidateKey
instances being used.- Parameters:
validateKeysFactory
-JwtHttpSecuritySource.JwtValidateKeysFactory
. May benull
to not override.- Throws:
T
- If failure inAbstractExternalOverride.ContextRunnable
.
-
loadSpecification
protected void loadSpecification(AbstractHttpSecuritySource.SpecificationContext context)
Description copied from class:AbstractHttpSecuritySource
Overridden to load specifications.- Specified by:
loadSpecification
in classAbstractHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
- Specifications.
-
loadMetaData
protected void loadMetaData(AbstractHttpSecuritySource.MetaDataContext<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows> context) throws java.lang.Exception
Description copied from class:AbstractHttpSecuritySource
Overridden to load meta-data.- Specified by:
loadMetaData
in classAbstractHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
- Meta-data.- Throws:
java.lang.Exception
- If fails to load the meta-data.
-
sourceHttpSecurity
public HttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows> sourceHttpSecurity(HttpSecurityContext context) throws HttpException
Description copied from interface:HttpSecuritySource
Sources theHttpSecurity
.- Specified by:
sourceHttpSecurity
in interfaceHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
-HttpSecurity
.- Returns:
HttpSecurity
.- Throws:
HttpException
- If fails to source theHttpSecurity
.
-
start
public void start(HttpSecurityExecuteContext<JwtHttpSecuritySource.Flows> context) throws java.lang.Exception
Description copied from interface:HttpSecuritySource
Called once after
HttpSecuritySource.init(HttpSecuritySourceContext)
to indicate thisHttpSecuritySource
should start execution.On invocation of this method,
ProcessState
instances may be invoked via theHttpSecurityExecuteContext
.- Specified by:
start
in interfaceHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Overrides:
start
in classAbstractHttpSecuritySource<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
-HttpSecurityExecuteContext
to use in starting thisHttpSecuritySource
.- Throws:
java.lang.Exception
- Should theHttpSecuritySource
fail to start execution.
-
createAuthentication
public HttpAuthentication<java.lang.Void> createAuthentication(AuthenticationContext<JwtHttpAccessControl<C>,java.lang.Void> context)
Description copied from interface:HttpSecurity
Creates the custom authentication.- Specified by:
createAuthentication
in interfaceHttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
-AuthenticateContext
.- Returns:
- Custom authentication.
-
ratify
public boolean ratify(java.lang.Void credentials, RatifyContext<JwtHttpAccessControl<C>> context)
Description copied from interface:HttpSecurity
Ratifies whether enough information is available to undertake authentication.
As authentication will likely require communication with external services (LDAP store, database, etc), this method allows checking whether enough information is available to undertake the authentication. The purpose is to avoid the
ManagedFunction
depending on dependencies of authentication subsequently causing execution by differentTeam
. This is especially as the majority ofHttpRequest
servicing will use theHttpSession
to cache details and not require the authentication dependencies causing the swap inTeam
.- Specified by:
ratify
in interfaceHttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
credentials
- Credentials.context
-RatifyContext
.- Returns:
true
should enough information be available to undertake authentication.false
if not enough information is available for authentication.
-
authenticate
public void authenticate(java.lang.Void credentials, AuthenticateContext<JwtHttpAccessControl<C>,None,JwtHttpSecuritySource.Flows> context) throws HttpException
Description copied from interface:HttpSecurity
Undertakes authentication.- Specified by:
authenticate
in interfaceHttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
credentials
- Credentials.context
-AuthenticateContext
.- Throws:
HttpException
- If failure in communicating to necessary security services.
-
challenge
public void challenge(ChallengeContext<None,JwtHttpSecuritySource.Flows> context) throws HttpException
Description copied from interface:HttpSecurity
Triggers the authentication challenge to the client.- Specified by:
challenge
in interfaceHttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
-ChallengeContext
.- Throws:
HttpException
- If failure in communicating to necessary security services.
-
logout
public void logout(LogoutContext<None,JwtHttpSecuritySource.Flows> context) throws HttpException
Description copied from interface:HttpSecurity
Logs out.- Specified by:
logout
in interfaceHttpSecurity<HttpAuthentication<java.lang.Void>,JwtHttpAccessControl<C>,java.lang.Void,None,JwtHttpSecuritySource.Flows>
- Parameters:
context
-LogoutContext
.- Throws:
HttpException
- If failure in communicating to necessary security services.
-
-