Class MockChallengeHttpSecuritySource
- java.lang.Object
-
- net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None>
-
- net.officefloor.web.security.scheme.MockChallengeHttpSecuritySource
-
- All Implemented Interfaces:
HttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>,HttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None>
@TestSource public class MockChallengeHttpSecuritySource extends AbstractHttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None> implements HttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>
Mock
HttpSecuritySourceto use for testing with challenges.It provides a
MockAuthenticationandMockAccessControlby the followingBasicauthentication scheme, except that:- authentication is obtained by user name and password being the same
- the
MockAccessControlis provided the user name as a role (allows logging in with various roles for testing). Multiple roles can be specified by the user name being a comma separate list.
- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
-
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.StringAUTHENTICATION_SCHEMEAuthentication scheme reported to the application via theHttpAccessControl.static java.lang.StringPROPERTY_REALMName ofPropertyto configure the realm.-
Fields inherited from class net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource
UTF_8
-
-
Constructor Summary
Constructors Constructor Description MockChallengeHttpSecuritySource()Default constructor.MockChallengeHttpSecuritySource(java.lang.String realm)Instantiate with the realm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidauthenticate(java.lang.Void credentials, AuthenticateContext<MockAccessControl,None,None> context)Undertakes authentication.voidchallenge(ChallengeContext<None,None> context)Triggers the authentication challenge to the client.MockAuthenticationcreateAuthentication(AuthenticationContext<MockAccessControl,java.lang.Void> context)Creates the custom authentication.static java.lang.StringgetHeaderChallengeValue(java.lang.String realm)Obtains theWWW-AuthenticateHttpHeadervalue.protected voidloadMetaData(AbstractHttpSecuritySource.MetaDataContext<MockAuthentication,MockAccessControl,java.lang.Void,None,None> context)Overridden to load meta-data.protected voidloadSpecification(AbstractHttpSecuritySource.SpecificationContext context)Overridden to load specifications.voidlogout(LogoutContext<None,None> context)Logs out.booleanratify(java.lang.Void credentials, RatifyContext<MockAccessControl> context)Ratifies whether enough information is available to undertake authentication.HttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>sourceHttpSecurity(HttpSecurityContext context)Sources theHttpSecurity.-
Methods inherited from class net.officefloor.web.spi.security.impl.AbstractHttpSecuritySource
getSpecification, init, start, stop
-
-
-
-
Field Detail
-
PROPERTY_REALM
public static final java.lang.String PROPERTY_REALM
Name ofPropertyto configure the realm.- See Also:
- Constant Field Values
-
AUTHENTICATION_SCHEME
public static final java.lang.String AUTHENTICATION_SCHEME
Authentication scheme reported to the application via theHttpAccessControl.- See Also:
- Constant Field Values
-
-
Method Detail
-
getHeaderChallengeValue
public static java.lang.String getHeaderChallengeValue(java.lang.String realm)
Obtains theWWW-AuthenticateHttpHeadervalue.- Parameters:
realm- Realm.- Returns:
WWW-AuthenticateHttpHeadervalue.
-
loadSpecification
protected void loadSpecification(AbstractHttpSecuritySource.SpecificationContext context)
Description copied from class:AbstractHttpSecuritySourceOverridden to load specifications.- Specified by:
loadSpecificationin classAbstractHttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context- Specifications.
-
loadMetaData
protected void loadMetaData(AbstractHttpSecuritySource.MetaDataContext<MockAuthentication,MockAccessControl,java.lang.Void,None,None> context) throws java.lang.Exception
Description copied from class:AbstractHttpSecuritySourceOverridden to load meta-data.- Specified by:
loadMetaDatain classAbstractHttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context- Meta-data.- Throws:
java.lang.Exception- If fails to load the meta-data.
-
sourceHttpSecurity
public HttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None> sourceHttpSecurity(HttpSecurityContext context) throws HttpException
Description copied from interface:HttpSecuritySourceSources theHttpSecurity.- Specified by:
sourceHttpSecurityin interfaceHttpSecuritySource<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context-HttpSecurity.- Returns:
HttpSecurity.- Throws:
HttpException- If fails to source theHttpSecurity.
-
createAuthentication
public MockAuthentication createAuthentication(AuthenticationContext<MockAccessControl,java.lang.Void> context)
Description copied from interface:HttpSecurityCreates the custom authentication.- Specified by:
createAuthenticationin interfaceHttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context-AuthenticateContext.- Returns:
- Custom authentication.
-
ratify
public boolean ratify(java.lang.Void credentials, RatifyContext<MockAccessControl> context)Description copied from interface:HttpSecurityRatifies 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
ManagedFunctiondepending on dependencies of authentication subsequently causing execution by differentTeam. This is especially as the majority ofHttpRequestservicing will use theHttpSessionto cache details and not require the authentication dependencies causing the swap inTeam.- Specified by:
ratifyin interfaceHttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
credentials- Credentials.context-RatifyContext.- Returns:
trueshould enough information be available to undertake authentication.falseif not enough information is available for authentication.
-
authenticate
public void authenticate(java.lang.Void credentials, AuthenticateContext<MockAccessControl,None,None> context) throws HttpExceptionDescription copied from interface:HttpSecurityUndertakes authentication.- Specified by:
authenticatein interfaceHttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
credentials- Credentials.context-AuthenticateContext.- Throws:
HttpException- If failure in communicating to necessary security services.
-
challenge
public void challenge(ChallengeContext<None,None> context) throws HttpException
Description copied from interface:HttpSecurityTriggers the authentication challenge to the client.- Specified by:
challengein interfaceHttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context-ChallengeContext.- Throws:
HttpException- If failure in communicating to necessary security services.
-
logout
public void logout(LogoutContext<None,None> context) throws HttpException
Description copied from interface:HttpSecurityLogs out.- Specified by:
logoutin interfaceHttpSecurity<MockAuthentication,MockAccessControl,java.lang.Void,None,None>- Parameters:
context-LogoutContext.- Throws:
HttpException- If failure in communicating to necessary security services.
-
-