- java.lang.Object
-
- org.refcodes.web.BearerAuthCredentials
-
- All Implemented Interfaces:
org.refcodes.mixin.TokenAccessor
,org.refcodes.mixin.Validatable<TokenCredentials>
,AuthTypeAccessor
,AuthTypeCredentials<BearerAuthCredentials,TokenCredentials>
,TokenCredentials
public class BearerAuthCredentials extends Object implements TokenCredentials, AuthTypeCredentials<BearerAuthCredentials,TokenCredentials>
TheBearerAuthCredentials
defines a type for representing a Bearer-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 theBearerAuthCredentials
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
-
-
Field Summary
Fields Modifier and Type Field Description static char
DELIMITER_AUTH_TYPE
-
Constructor Summary
Constructors Constructor Description BearerAuthCredentials()
Instantiates a new bearer auth credentials impl.BearerAuthCredentials(String aToken)
Instantiates a new bearer auth credentials impl.
-
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
getToken()
int
hashCode()
String
toHttpAuthorization()
Creates aHeaderField.AUTHORIZATION
HTTP Header-Field value from theAuthTypeCredentials
instance.String
toString()
void
validate(String aToken)
Validates the provided user-name and secret with thisBearerAuthCredentials
viaTokenCredentials.isValid(String)
.void
validate(TokenCredentials aCredentials)
Validates the providedTokenCredentials
with thisBearerAuthCredentials
viaTokenCredentials.isValid(TokenCredentials)
.BearerAuthCredentials
withHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.web.TokenCredentials
isValid, isValid
-
-
-
-
Field Detail
-
DELIMITER_AUTH_TYPE
public static final char DELIMITER_AUTH_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BearerAuthCredentials
public BearerAuthCredentials()
Instantiates a new bearer auth credentials impl.
-
BearerAuthCredentials
public BearerAuthCredentials(String aToken)
Instantiates a new bearer auth credentials impl.- Parameters:
aToken
- the secret
-
-
Method Detail
-
validate
public void validate(TokenCredentials aCredentials) throws ForbiddenException
Validates the providedTokenCredentials
with thisBearerAuthCredentials
viaTokenCredentials.isValid(TokenCredentials)
. In case the providedTokenCredentials
are not valid, then aForbiddenException
is thrown.- Specified by:
validate
in interfaceAuthTypeCredentials<BearerAuthCredentials,TokenCredentials>
- Parameters:
aCredentials
- TheTokenCredentials
to be verified.- Throws:
ForbiddenException
- thrown in case the providedTokenCredentials
do not match.
-
validate
public void validate(String aToken) throws ForbiddenException
Validates the provided user-name and secret with thisBearerAuthCredentials
viaTokenCredentials.isValid(String)
. In case the provided credentials are not valid, then aForbiddenException
is thrown.- Parameters:
aToken
- The secret part to be tested if it fits with the thisTokenCredentials
instance.- Throws:
ForbiddenException
- thrown in case the providedTokenCredentials
do not match.
-
withHttpAuthorization
public BearerAuthCredentials withHttpAuthorization(String aHttpAuthorization) throws IllegalArgumentException
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.- Specified by:
withHttpAuthorization
in interfaceAuthTypeCredentials<BearerAuthCredentials,TokenCredentials>
- 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).
-
getToken
public String getToken()
- Specified by:
getToken
in interfaceorg.refcodes.mixin.TokenAccessor
-
fromHttpAuthorization
public void fromHttpAuthorization(String aHttpAuthorization)
Initializes thisAuthTypeCredentials
instance from theHeaderField.AUTHORIZATION
Header-Fields's value.- Specified by:
fromHttpAuthorization
in interfaceAuthTypeCredentials<BearerAuthCredentials,TokenCredentials>
- 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<BearerAuthCredentials,TokenCredentials>
- Returns:
- The according HTTP Header-Field's value.
-
-