com.worklight.wlclient.api
Class WLAuthorizationManager
- java.lang.Object
-
- com.worklight.wlclient.api.WLAuthorizationManager
-
public class WLAuthorizationManager extends java.lang.Object
This class manages the OAuth interaction between the client and the authorization server.
-
-
Method Summary
Methods Modifier and Type Method and Description void
clearAccessToken(AccessToken accessToken)
Clears the provided access token.
Note: When failing to access a resource with an obtained token, call theclearAccessToken
method to clear the invalid token before callingWLAuthorizationManager.obtainAccessToken(String, WLAccessTokenListener)
to obtain a new access token.java.net.URL
getAuthorizationServerUrl()
Returns the URL of the current authorization server.static WLAuthorizationManager
getInstance()
Returns the singleton instance of theWLAuthorizationManager
class.java.lang.String
getResourceScope(java.net.HttpURLConnection httpURLConnection)
Returns the scope of the protected resource for the provided HTTP connection.
Note: Call this method only for a connection for whichWLAuthorizationManager.isAuthorizationRequired(HttpURLConnection)
returnstrue
, indicating that the target resource is protected.java.lang.String
getResourceScope(java.util.Map headers)
Returns the scope of the protected resource for the provided response headers.
Note: Call this method only for response headers for whichWLAuthorizationManager.isAuthorizationRequired(int, Map)
returnstrue
, indicating that the resource is protected.boolean
isAuthorizationRequired(java.net.HttpURLConnection httpURLConnection)
Checks whether the provided HTTP connection represents a protected resource that requires authorization.boolean
isAuthorizationRequired(int status, java.util.Map headers)
Checks whether the provided response status and headers represent a protected resource that requires authorization.void
login(java.lang.String securityCheck, JSONObject credentials, WLLoginResponseListener listener)
Logs into the specified security check.void
logout(java.lang.String securityCheck, WLLogoutResponseListener listener)
Logs out of the specified security check.void
obtainAccessToken(java.lang.String scope, WLAccessTokenListener listener)
Obtains an access token for the specified resource scope from the MobileFirst authorization server.void
setAuthorizationServerUrl(java.net.URL url)
Sets the URL of the authorization server.
-
-
-
Method Detail
-
getInstance
public static WLAuthorizationManager getInstance()
Returns the singleton instance of theWLAuthorizationManager
class.- Returns:
- The singleton instance of
WLAuthorizationManager
.
-
getResourceScope
public java.lang.String getResourceScope(java.net.HttpURLConnection httpURLConnection)
Returns the scope of the protected resource for the provided HTTP connection.
Note: Call this method only for a connection for whichWLAuthorizationManager.isAuthorizationRequired(HttpURLConnection)
returnstrue
, indicating that the target resource is protected.- Parameters:
httpURLConnection
- HTTP connection for a request to access a protected resource.- Returns:
- The protecting scope of the target resource, as returned in the
WWW-Authenticate
HTTP response header.
-
getResourceScope
public java.lang.String getResourceScope(java.util.Map headers)
Returns the scope of the protected resource for the provided response headers.
Note: Call this method only for response headers for whichWLAuthorizationManager.isAuthorizationRequired(int, Map)
returnstrue
, indicating that the resource is protected.- Parameters:
headers
- Response headers for a request to access a protected resource.- Returns:
- The protecting scope of the target resource, as returned in the
WWW-Authenticate
HTTP response header.
-
isAuthorizationRequired
public boolean isAuthorizationRequired(java.net.HttpURLConnection httpURLConnection)
Checks whether the provided HTTP connection represents a protected resource that requires authorization.- Parameters:
httpURLConnection
- HTTP connection for a request to access a resource.- Returns:
true
if access to the target resource requires authorization, orfalse
otherwise.
-
isAuthorizationRequired
public boolean isAuthorizationRequired(int status, java.util.Map headers)
Checks whether the provided response status and headers represent a protected resource that requires authorization.- Parameters:
status
- Response status code.headers
- Response headers for a request to access a resource.- Returns:
true
if access to the target resource requires authorization, orfalse
otherwise.
-
obtainAccessToken
public void obtainAccessToken(java.lang.String scope, WLAccessTokenListener listener)
Obtains an access token for the specified resource scope from the MobileFirst authorization server.- Parameters:
scope
- Scope for which to obtain the access token.listener
- Access-token listener whoseonSuccess
oronFailure
methods are called upon request completion.
-
clearAccessToken
public void clearAccessToken(AccessToken accessToken)
Clears the provided access token.
Note: When failing to access a resource with an obtained token, call theclearAccessToken
method to clear the invalid token before callingWLAuthorizationManager.obtainAccessToken(String, WLAccessTokenListener)
to obtain a new access token.- Parameters:
accessToken
- Access token to clear.
-
login
public void login(java.lang.String securityCheck, JSONObject credentials, WLLoginResponseListener listener)
Logs into the specified security check.- Parameters:
securityCheck
- Name of the security check to log into.credentials
- Credentials for logging into the specified security check.listener
- Login listener whose methods are called upon request completion.
-
logout
public void logout(java.lang.String securityCheck, WLLogoutResponseListener listener)
Logs out of the specified security check.- Parameters:
securityCheck
- Name of the security check to log out of.listener
- Logout listener whose methods are called upon request completion.
-
setAuthorizationServerUrl
public void setAuthorizationServerUrl(java.net.URL url)
Sets the URL of the authorization server. When this method is not called, the MobileFirst Server URL is used.- Parameters:
url
- URL of the authorization server to set.
-
getAuthorizationServerUrl
public java.net.URL getAuthorizationServerUrl()
Returns the URL of the current authorization server.- Returns:
- The URL of the current authorization server.
-
-