Class OAuthAuthorization
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Error code passed as ahttpRequest
parameter attribute with a namereason
, in case of faild authorization.static final String
Error code passed as ahttpRequest
parameter attribute with a namereason
in case of failed authorization when the passed access token does not exist or when it has already expired.static final String
Error code passed as ahttpRequest
parameter attribute with a namereason
in case of failed authorization when the access token is not passed as an HTTP "Authorization" request header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic OAuthAuthorization
Returns OAuth Authorization object that is used to perform the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token.abstract boolean
isAuthorized
(HttpServletRequest httpRequest) This method is only for authentication purpose with the given Access Token.abstract boolean
isAuthorized
(HttpServletRequest httpRequest, String scope) Performs the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token, compares them with the passed scopes and checks the Token validity.abstract boolean
isAuthorized
(HttpServletRequest httpRequest, Set<String> scopes) Performs the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token, compares them with the passed scopes and checks the Token validity.abstract boolean
isAuthorized
(String scope) Performs the protected resource access check by retrieving the scopes from the currently logged in user and comparing them with the passed scope.abstract boolean
isAuthorized
(Set<String> scopes) Performs the protected resource access check by retrieving the scopes from the currently logged in user and comparing them with the passed scopes.
-
Field Details
-
ACCESS_FORBIDDEN
Error code passed as ahttpRequest
parameter attribute with a namereason
, in case of faild authorization.- See Also:
-
MISSING_ACCESS_TOKEN
Error code passed as ahttpRequest
parameter attribute with a namereason
in case of failed authorization when the access token is not passed as an HTTP "Authorization" request header.- See Also:
-
INVALID_ACCESS_TOKEN
Error code passed as ahttpRequest
parameter attribute with a namereason
in case of failed authorization when the passed access token does not exist or when it has already expired.- See Also:
-
-
Constructor Details
-
OAuthAuthorization
public OAuthAuthorization()
-
-
Method Details
-
getOAuthAuthorizationService
Returns OAuth Authorization object that is used to perform the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token.- Returns:
- Returns OAuthAuthorization object
-
isAuthorized
This method is only for authentication purpose with the given Access Token. Use this method for accessing a public resource, accessible for any scope. Access token must be passed by using the HTTP "Authorization" request header field. The value of this header must be the token type and access token value. The currently supported token type is"bearer"
.For example the header could look like:
"Authorization: Bearer mF_9.B5f-4.1JqM"
- Parameters:
httpRequest
-- Returns:
- true - Resource access request is successful and the authentication
with access token is successful. On success two attributes are
passed in the request:
"user_id"
- Id of the user that performs the request and"client_id"
- Id of the client for which the access token is issued.false - Resource access request fails. The passed token is not available or expired for the current client. In this case the error's reason can be retrieve from request's attributes with a name
"reason"
. - Throws:
OAuthSystemException
- In case of communication errors between the OAuth Resource Server and the Authorization Server.
-
isAuthorized
public abstract boolean isAuthorized(HttpServletRequest httpRequest, String scope) throws OAuthSystemException Performs the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token, compares them with the passed scopes and checks the Token validity. Access token must be passed by using the HTTP "Authorization" request header field. The value of this header must be the token type and access token value. The currently supported token type is"bearer"
.For example the header could look like:
"Authorization: Bearer mF_9.B5f-4.1JqM"
- Parameters:
httpRequest
-scope
- - Scope for which the protected resource access is performed- Returns:
- true - Resource access request is successful. This means that all
scopes passed as an input parameter are access token scopes and the
token has not expired.
On success two attributes are passed in the request:"user_id"
- Id of the user that performs the request and"client_id"
- Id of the client for which the access token is issued.false - Resource access request fails. In this case the error's reason can be retrieve from request's attributes with a name
"reason"
. - Throws:
OAuthSystemException
- In case of communication errors between the OAuth Resource Server and the Authorization Server.
-
isAuthorized
Performs the protected resource access check by retrieving the scopes from the currently logged in user and comparing them with the passed scope.- Parameters:
scope
- - Scope for which the protected resource access is performed- Returns:
- true - Resource access request is successful. This means that the
scope passed as an input parameter was granted to the currently
logged in user.
false - Resource access request fails.
- Throws:
OAuthSystemException
- In case of communication errors between the OAuth Resource Server and the Authorization Server.
-
isAuthorized
public abstract boolean isAuthorized(HttpServletRequest httpRequest, Set<String> scopes) throws OAuthSystemException Performs the protected resource access check by retrieving from the Authorization Server the scopes associated with the given Access Token, compares them with the passed scopes and checks the Token validity. Access token must be passed by using the HTTP "Authorization" request header field. The value of this header must be the token type and access token value. The currently supported token type is"bearer"
.For example the header could look like:
"Authorization: Bearer mF_9.B5f-4.1JqM"
- Parameters:
httpRequest
-scopes
- - Scopes for which the protected resource access is performed.- Returns:
- true - Resource access request is successful. This means that all
scopes passed as an input parameter are access token scopes and the
token has not expired.
On success two attributes are passed in the request:"user_id"
- Id of the user that performs the request and"client_id"
- Id of the client for which the access token is issued.false - Resource access request fails. In this case the error's reason can be retrieve from request's attributes with a name
"reason"
. - Throws:
OAuthSystemException
- In case of communication errors between the OAuth Resource Server and the Authorization Server.
-
isAuthorized
Performs the protected resource access check by retrieving the scopes from the currently logged in user and comparing them with the passed scopes.- Parameters:
scopes
- - Scopes for which the protected resource access is performed.- Returns:
- true - Resource access request is successful. This means that all
scopes passed as an input parameter were granted to the currently
logged in user.
false - Resource access request fails.
- Throws:
OAuthSystemException
- In case of communication errors between the OAuth Resource Server and the Authorization Server.
-