org.spiffyui.client.rest
Class AuthUtil

java.lang.Object
  extended by org.spiffyui.client.rest.AuthUtil
All Implemented Interfaces:
RESTAuthProvider, RESTAuthConstants

public class AuthUtil
extends java.lang.Object
implements RESTAuthProvider

This is the default class for handling authentication during REST calls.

The default authentication handler follows the Novell standards for REST authentication. This class implements that handler. You can override this class and create your own authentication handler to satisfy any authentication scheme your application may require.


Field Summary
protected static LoginStringHelper HELPER
          The string helper for providing strings to the login dialog
 
Fields inherited from interface org.spiffyui.client.rest.util.RESTAuthConstants
AUTH_LOGOUT_URL_TOKEN, AUTH_URL_TOKEN, GONE, INVALID_AUTH_HEADER, INVALID_INPUT, INVALID_JSON, INVALID_LOGIN_REQUEST, INVALID_LOGOUT_REQUEST, INVALID_TS_URL, MULTIPLE_ACCOUNTS, NO_PRIVILEGE, NOTFOUND_TS_URL, PASSWORD_TOKEN, USER_TOKEN, USERNAME_TOKEN
 
Constructor Summary
AuthUtil()
          Create a new AuthUtil
 
Method Summary
 void finishRESTCall(java.lang.Object callBackKey)
          Once the login is completed we need to perform the original REST request with the new user token.
 java.lang.String getServletContext()
          Gets the servlet context from the current URL.
protected  LoginStringHelper getStringHelper()
          Provide the LoginStringHelper class for use with the login panel.
 void login(java.lang.String username, java.lang.String password, java.lang.String authUrl, RESTObjectCallBack<java.lang.String> callback)
          Performs login for the specified user credentials.
 void logout(RESTObjectCallBack<java.lang.String> callback)
          Logout the current user.
 void showLogin(RESTCallback callback, java.lang.String tokenServerUrl, Response response, RESTException exception)
           Show the login dialog.
 void showLogin(RESTCallback callback, java.lang.String tokenServerUrl, java.lang.String code)
          Show the login dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HELPER

protected static final LoginStringHelper HELPER
The string helper for providing strings to the login dialog

Constructor Detail

AuthUtil

public AuthUtil()
Create a new AuthUtil

Method Detail

showLogin

public void showLogin(RESTCallback callback,
                      java.lang.String tokenServerUrl,
                      Response response,
                      RESTException exception)

Show the login dialog.

This method is called when a REST call results in a 401 which requires login. The default implementation of this method shows a login dialog, but it could redirect to another page or simply show an error message.

Parameters:
callback - the callback for the original REST call
tokenServerUrl - the URL for the authentication server
response - the server response that came with this 401
exception - the RESTException representation of the JSON response from the server if available

showLogin

public void showLogin(RESTCallback callback,
                      java.lang.String tokenServerUrl,
                      java.lang.String code)
Show the login dialog.

Specified by:
showLogin in interface RESTAuthProvider
Parameters:
callback - the callback for the original REST call
tokenServerUrl - the URL for the authentication server
code - the error code

getStringHelper

protected LoginStringHelper getStringHelper()
Provide the LoginStringHelper class for use with the login panel.

Returns:
the LoginStringHelper

finishRESTCall

public void finishRESTCall(java.lang.Object callBackKey)
Once the login is completed we need to perform the original REST request with the new user token.

Specified by:
finishRESTCall in interface RESTAuthProvider
Parameters:
callBackKey - the callback object of the original REST call

logout

public void logout(RESTObjectCallBack<java.lang.String> callback)
Logout the current user. This clears all local variables, removes the session cookie, and issues the logout request to the server.

Specified by:
logout in interface RESTAuthProvider
Parameters:
callback - the REST callback to indicate the call is completed

login

public void login(java.lang.String username,
                  java.lang.String password,
                  java.lang.String authUrl,
                  RESTObjectCallBack<java.lang.String> callback)
Performs login for the specified user credentials.

Specified by:
login in interface RESTAuthProvider
Parameters:
username - the username
password - the password
authUrl - the URL of the authentication server
callback - the REST callback for the original REST call

getServletContext

public java.lang.String getServletContext()
Gets the servlet context from the current URL. The context is assumed to be the string after the first single forward slash and before the next forward slash.

Specified by:
getServletContext in interface RESTAuthProvider
Returns:
the current server servlet context