- 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>
TheBasicAuthCredentials
defines a type for representing a Basic-Authentication credentials Header-Field. Parse the Header-Field viafromHttpAuthorization(String)
and feed it with the header'sHeaderField.AUTHORIZATION
field's value. To create the according Header-Field's value from theBasicAuthCredentials
type, 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 char
DELIMITER_BASIC_AUTH
static char
DELIMITER_CREDENTIALS
-
Fields inherited from class org.refcodes.web.BasicCredentials
_identity, _secret
-
-
Constructor Summary
Constructors Constructor Description BasicAuthCredentials()
Instantiates a newBasicAuthCredentials
instance.BasicAuthCredentials(String aIdentity, String aSecret)
Instantiates a newBasicAuthCredentials
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
void
fromHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.AuthType
getAuthType()
Retrieves theAuthType
from the Authorization-Type property (or null if there are none such credentials).String
getIdentity()
String
getSecret()
int
hashCode()
String
toHttpAuthorization()
Creates aHeaderField.AUTHORIZATION
HTTP Header-Field value from theAuthTypeCredentials
instance.String
toString()
void
validate(String aUserName, String aSecret)
Validates the provided user-name and secret with thisBasicAuthCredentials
viaBasicCredentials.isValid(String, String)
.void
validate(BasicCredentials aCredentials)
Validates the providedBasicCredentials
with thisBasicAuthCredentials
viaBasicCredentials.isValid(BasicCredentials)
.BasicAuthCredentials
withHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-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 newBasicAuthCredentials
instance.
-
BasicAuthCredentials
public BasicAuthCredentials(String aIdentity, String aSecret)
Instantiates a newBasicAuthCredentials
instance.- Parameters:
aIdentity
- the user nameaSecret
- the secret
-
-
Method Detail
-
validate
public void validate(BasicCredentials aCredentials) throws ForbiddenException
Validates the providedBasicCredentials
with thisBasicAuthCredentials
viaBasicCredentials.isValid(BasicCredentials)
. In case the providedBasicCredentials
are not valid, then aForbiddenException
is thrown.- Specified by:
validate
in interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
- Parameters:
aCredentials
- TheBasicCredentials
to be verified.- Throws:
ForbiddenException
- thrown in case the providedBasicCredentials
do not match.
-
validate
public void validate(String aUserName, String aSecret) throws ForbiddenException
Validates the provided user-name and secret with thisBasicAuthCredentials
viaBasicCredentials.isValid(String, String)
. In case the provided credentials are not valid, then aForbiddenException
is thrown.- Parameters:
aUserName
- The user-name part to be tested if it fits with the thisBasicCredentials
instance.aSecret
- The secret part to be tested if it fits with the thisBasicCredentials
instance.- Throws:
ForbiddenException
- thrown in case the providedBasicCredentials
do not match.
-
withHttpAuthorization
public BasicAuthCredentials withHttpAuthorization(String aHttpAuthorization) throws IllegalArgumentException
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.- Specified by:
withHttpAuthorization
in interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
- Parameters:
aHttpAuthorization
- TheHeaderField.AUTHORIZATION
header 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 theAuthType
from the Authorization-Type property (or null if there are none such credentials).- Specified by:
getAuthType
in interfaceAuthTypeAccessor
- Returns:
- The
AuthType
stored by the Basic-Authentication credentials property (or null if there are none such credentials).
-
getIdentity
public String getIdentity()
- Specified by:
getIdentity
in interfaceorg.refcodes.mixin.IdentityAccessor
- Overrides:
getIdentity
in classBasicCredentials
-
getSecret
public String getSecret()
- Specified by:
getSecret
in interfaceorg.refcodes.mixin.SecretAccessor
- Overrides:
getSecret
in classBasicCredentials
-
fromHttpAuthorization
public void fromHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.- Specified by:
fromHttpAuthorization
in interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
- Parameters:
aHttpAuthorization
- TheHeaderField.AUTHORIZATION
header field's value
-
toHttpAuthorization
public String toHttpAuthorization()
Creates aHeaderField.AUTHORIZATION
HTTP Header-Field value from theAuthTypeCredentials
instance.- Specified by:
toHttpAuthorization
in interfaceAuthTypeCredentials<BasicAuthCredentials,BasicCredentials>
- Returns:
- The according HTTP Header-Field's value.
-
-