- java.lang.Object
-
- org.refcodes.web.BasicCredentials
-
- org.refcodes.web.BasicAuthCredentials
-
- All Implemented Interfaces:
org.refcodes.mixin.CredentialsAccessor,org.refcodes.mixin.IdentityAccessor,org.refcodes.mixin.SecretAccessor,org.refcodes.mixin.Validatable<BasicCredentials>,AuthTypeAccessor,AuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
- Direct Known Subclasses:
BasicAuthCredentialsBuilder
public class BasicAuthCredentials extends BasicCredentials implements AuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
TheBasicAuthCredentialsdefines a type for representing a Basic-Authentication credentials Header-Field. Parse the Header-Field viafromHttpAuthorization(String)and feed it with the header'sHeaderField.AUTHORIZATIONfield's value. To create the according Header-Field's value from theBasicAuthCredentialstype, calltoHttpAuthorization().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.web.AuthTypeAccessor
AuthTypeAccessor.AuthTypeBuilder<B extends AuthTypeAccessor.AuthTypeBuilder<B>>, AuthTypeAccessor.AuthTypeMutator, AuthTypeAccessor.AuthTypeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.CredentialsAccessor
org.refcodes.mixin.CredentialsAccessor.CredentialsBuilder<B extends org.refcodes.mixin.CredentialsAccessor.CredentialsBuilder<B>>, org.refcodes.mixin.CredentialsAccessor.CredentialsMutator, org.refcodes.mixin.CredentialsAccessor.CredentialsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.IdentityAccessor
org.refcodes.mixin.IdentityAccessor.IdentityBuilder<B extends org.refcodes.mixin.IdentityAccessor.IdentityBuilder<B>>, org.refcodes.mixin.IdentityAccessor.IdentityMutator, org.refcodes.mixin.IdentityAccessor.IdentityProperty
-
-
Field Summary
Fields Modifier and Type Field Description static charDELIMITER_BASIC_AUTHstatic charDELIMITER_CREDENTIALS-
Fields inherited from class org.refcodes.web.BasicCredentials
_identity, _secret
-
-
Constructor Summary
Constructors Constructor Description BasicAuthCredentials()Instantiates a newBasicAuthCredentialsinstance.BasicAuthCredentials(String aIdentity, String aSecret)Instantiates a newBasicAuthCredentialsinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)voidfromHttpAuthorization(String aHttpAuthorization)Initializes thisAuthTypeCredentialsinstance from theHeaderField.AUTHORIZATIONHeader-Fields's value.AuthTypegetAuthType()Retrieves theAuthTypefrom the Authorization-Type property (or null if there are none such credentials).StringgetIdentity()StringgetSecret()inthashCode()StringtoHttpAuthorization()Creates aHeaderField.AUTHORIZATIONHTTP Header-Field value from theAuthTypeCredentialsinstance.StringtoString()voidvalidate(String aUserName, String aSecret)Validates the provided user-name and secret with thisBasicAuthCredentialsviaBasicCredentials.isValid(String, String).voidvalidate(BasicCredentials aCredentials)Validates the providedBasicCredentialswith thisBasicAuthCredentialsviaBasicCredentials.isValid(BasicCredentials).BasicAuthCredentialswithHttpAuthorization(String aHttpAuthorization)Initializes thisAuthTypeCredentialsinstance from theHeaderField.AUTHORIZATIONHeader-Fields's value.-
Methods inherited from class org.refcodes.web.BasicCredentials
isValid, isValid
-
-
-
-
Field Detail
-
DELIMITER_BASIC_AUTH
public static final char DELIMITER_BASIC_AUTH
- See Also:
- Constant Field Values
-
DELIMITER_CREDENTIALS
public static final char DELIMITER_CREDENTIALS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicAuthCredentials
public BasicAuthCredentials()
Instantiates a newBasicAuthCredentialsinstance.
-
BasicAuthCredentials
public BasicAuthCredentials(String aIdentity, String aSecret)
Instantiates a newBasicAuthCredentialsinstance.- Parameters:
aIdentity- the user nameaSecret- the secret
-
-
Method Detail
-
validate
public void validate(BasicCredentials aCredentials) throws ForbiddenException
Validates the providedBasicCredentialswith thisBasicAuthCredentialsviaBasicCredentials.isValid(BasicCredentials). In case the providedBasicCredentialsare not valid, then aForbiddenExceptionis thrown.- Specified by:
validatein interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>- Parameters:
aCredentials- TheBasicCredentialsto be verified.- Throws:
ForbiddenException- thrown in case the providedBasicCredentialsdo not match.
-
validate
public void validate(String aUserName, String aSecret) throws ForbiddenException
Validates the provided user-name and secret with thisBasicAuthCredentialsviaBasicCredentials.isValid(String, String). In case the provided credentials are not valid, then aForbiddenExceptionis thrown.- Parameters:
aUserName- The user-name part to be tested if it fits with the thisBasicCredentialsinstance.aSecret- The secret part to be tested if it fits with the thisBasicCredentialsinstance.- Throws:
ForbiddenException- thrown in case the providedBasicCredentialsdo not match.
-
withHttpAuthorization
public BasicAuthCredentials withHttpAuthorization(String aHttpAuthorization) throws IllegalArgumentException
Initializes thisAuthTypeCredentialsinstance from theHeaderField.AUTHORIZATIONHeader-Fields's value.- Specified by:
withHttpAuthorizationin interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>- Parameters:
aHttpAuthorization- TheHeaderField.AUTHORIZATIONheader field's value- Returns:
- the t
- Throws:
IllegalArgumentException- The value does not conform the the HTTP Authorization Header-Field's Basic-Authentication format.
-
getAuthType
public AuthType getAuthType()
Retrieves theAuthTypefrom the Authorization-Type property (or null if there are none such credentials).- Specified by:
getAuthTypein interfaceAuthTypeAccessor- Returns:
- The
AuthTypestored by the Basic-Authentication credentials property (or null if there are none such credentials).
-
getIdentity
public String getIdentity()
- Specified by:
getIdentityin interfaceorg.refcodes.mixin.IdentityAccessor- Overrides:
getIdentityin classBasicCredentials
-
getSecret
public String getSecret()
- Specified by:
getSecretin interfaceorg.refcodes.mixin.SecretAccessor- Overrides:
getSecretin classBasicCredentials
-
fromHttpAuthorization
public void fromHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentialsinstance from theHeaderField.AUTHORIZATIONHeader-Fields's value.- Specified by:
fromHttpAuthorizationin interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>- Parameters:
aHttpAuthorization- TheHeaderField.AUTHORIZATIONheader field's value
-
toHttpAuthorization
public String toHttpAuthorization()
Creates aHeaderField.AUTHORIZATIONHTTP Header-Field value from theAuthTypeCredentialsinstance.- Specified by:
toHttpAuthorizationin interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>- Returns:
- The according HTTP Header-Field's value.
-
-