Class AuthContext
- java.lang.Object
-
- com.sun.identity.authentication.internal.AuthContext
-
public final class AuthContext extends Object
The AuthContext provides the implementation for authenticating users using the JAAS technology. It complementsLoginContextprovided by JAAS by supporting organization environments that cannot handle sessions, for example, HTTP/HTML.A typical caller instantiates this class and starts the login process. The caller then obtains an array of
Callbackobjects, which contains the information required by the authentication plug-in module. The caller requests information from the user. On receiving the information from the user, the caller submits the same to this class. If more information is required, the above process continues until all the information required by the plug-ins has been supplied. The caller then checks if the user has successfully been authenticated. If successfully authenticated, the caller can then get theSubjectfor the user; if not successfully authenticated, the caller obtains the LoginException.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringapplicationNamestatic intAUTH_COMPLETEDThis login status indicates that the user has been successfully logged out.static intAUTH_FAILEDThis login status indicates that the login process has failed.static intAUTH_IN_PROGRESSThis login status indicates that the login process is in progress.static intAUTH_NOT_STARTEDThis login status indicates that the login process has not started yet.static intAUTH_SUCCESSThis login status indicates that the login process has succeeded.protected StringauthComponentNameprotected static DebugauthDebugprotected static StringauthDebugNameprotected static StringauthKeyNameprotected Callback[]informationRequiredprotected LoginContextloginContextprotected LoginExceptionloginExceptionprotected intloginStatusprotected AuthLoginThreadloginThreadprotected static I18nmyAuthI18nprotected StringorganizationNameprotected Callback[]submittedInformationprotected SSOTokentoken
-
Constructor Summary
Constructors Modifier Constructor Description AuthContext()Constructor to get an instance ofAuthContext.AuthContext(String orgName)Constructor to get an instance of this class given the organization nameorgName.protectedAuthContext(String orgName, AuthSubject subject)Constructor to get an instance of this class given the organization nameorgNamethe user would like to access, and the principal'ssubjectthe user would like to be authenticated as.AuthContext(String orgName, Principal principal, char[] password)Constructor to get an instance of this class given the organization nameorgNamethe user would like to access, thejava.security.Principalthe user would like to be authenticated as, and thepasswordfor the user.AuthContext(Principal principal, char[] password)Constructor to get an authenticated instance of this class given thejava.security.Principalthe user would like to be authenticated as, and thepasswordfor the user.AuthContext(Principal principal, char[] password, String hostname, int port)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected StringgetApplicationName()AuthPrincipalgetAuthPrincipal()Deprecated.Use getPrincipal() insteadLoginExceptiongetLoginException()Returns login exception, if any, during the authentication process.intgetLoginStatus()Returns the current state of the login process.StringgetOrganizationName()Method to get organization name that was set during construction of this instance.PrincipalgetPrincipal()Returns the (first)AuthPrincipalin theSubject.protected SetgetPrincipals()Method to get the set ofAuthPrincipals in theSubject.Callback[]getRequirements()Returns an array ofCallbackobjects that must be populated by the user and returned back.SSOTokengetSSOToken()Method to get the Single-Sign-On (SSO) Token.protected AuthSubjectgetSubject()Returns the set of Principals the user has been authenticated as.booleanhasMoreRequirements()Returns true if the login process requires more information from the user to complete the authentication.voidlogout()Logs the user out.protected voidreset()Method to reset this instance ofAuthContextobject, so that a new login process can be initiated.protected voidreset(AuthSubject subject)Method to reset this instance ofAuthContextobject, so that a new login process can be initiated for the givenSubject.protected voidsetLoginStatus(int status)Method to set the login status.voidstartLogin()Method to start the login process.voidsubmitRequiredInformation(Callback[] info)Submits the populatedCallbackobjects to the authentication plug-in modules.
-
-
-
Field Detail
-
AUTH_NOT_STARTED
public static final int AUTH_NOT_STARTED
This login status indicates that the login process has not started yet. Basically, it means that the methodstartLoginhas not been called.- See Also:
- Constant Field Values
-
AUTH_IN_PROGRESS
public static final int AUTH_IN_PROGRESS
This login status indicates that the login process is in progress. Basically, it means that thestartLoginmethod has been called and that this object is waiting for the user to send authentication information.- See Also:
- Constant Field Values
-
AUTH_SUCCESS
public static final int AUTH_SUCCESS
This login status indicates that the login process has succeeded.- See Also:
- Constant Field Values
-
AUTH_FAILED
public static final int AUTH_FAILED
This login status indicates that the login process has failed.- See Also:
- Constant Field Values
-
AUTH_COMPLETED
public static final int AUTH_COMPLETED
This login status indicates that the user has been successfully logged out.- See Also:
- Constant Field Values
-
authComponentName
protected final String authComponentName
- See Also:
- Constant Field Values
-
authKeyName
protected static final String authKeyName
- See Also:
- Constant Field Values
-
authDebugName
protected static final String authDebugName
- See Also:
- Constant Field Values
-
authDebug
protected static Debug authDebug
-
organizationName
protected String organizationName
-
applicationName
protected String applicationName
-
loginStatus
protected int loginStatus
-
loginException
protected LoginException loginException
-
informationRequired
protected Callback[] informationRequired
-
submittedInformation
protected Callback[] submittedInformation
-
loginThread
protected AuthLoginThread loginThread
-
loginContext
protected LoginContext loginContext
-
token
protected SSOToken token
-
myAuthI18n
protected static I18n myAuthI18n
-
-
Constructor Detail
-
AuthContext
public AuthContext() throws LoginExceptionConstructor to get an instance ofAuthContext. Caller would then usegetRequirements()andsubmitRequirements()to pass the credentials needed for authentication by the plugin modules.- Throws:
LoginException
-
AuthContext
public AuthContext(Principal principal, char[] password) throws LoginException
Constructor to get an authenticated instance of this class given thejava.security.Principalthe user would like to be authenticated as, and thepasswordfor the user.- Parameters:
principal- name of the user to be authenticatedpassword- password for the user- Throws:
LoginException
-
AuthContext
public AuthContext(Principal principal, char[] password, String hostname, int port) throws LoginException
- Throws:
LoginException
-
AuthContext
public AuthContext(String orgName, Principal principal, char[] password) throws LoginException
Constructor to get an instance of this class given the organization nameorgNamethe user would like to access, thejava.security.Principalthe user would like to be authenticated as, and thepasswordfor the user.- Parameters:
orgName- name of the user's organizationprincipal- name of the user to be authenticatedpassword- password for the user- Throws:
LoginException
-
AuthContext
protected AuthContext(String orgName, AuthSubject subject) throws LoginException
Constructor to get an instance of this class given the organization nameorgNamethe user would like to access, and the principal'ssubjectthe user would like to be authenticated as.- Throws:
LoginException
-
AuthContext
public AuthContext(String orgName) throws LoginException
Constructor to get an instance of this class given the organization nameorgName. The plug-in modules would then query for the user name and related information.- Parameters:
orgName- organization name.- Throws:
LoginException
-
-
Method Detail
-
reset
protected void reset() throws LoginExceptionMethod to reset this instance ofAuthContextobject, so that a new login process can be initiated. Authenticates the user to the same organization or resource this object was instantiated with. If this object was instantiated with aSubject, it will be ignored.- Throws:
LoginException
-
reset
protected void reset(AuthSubject subject) throws LoginException
Method to reset this instance ofAuthContextobject, so that a new login process can be initiated for the givenSubject. Authenticates the user to the same organization or resource this object was instantiated with.- Throws:
LoginException
-
getSubject
protected AuthSubject getSubject()
Returns the set of Principals the user has been authenticated as. This can be invoked only after successful authentication. If the authentication fails, this will returnnull.
-
startLogin
public void startLogin() throws LoginExceptionMethod to start the login process. This method will read the plug-ins configured for the application and initialize them.- Throws:
LoginException
-
hasMoreRequirements
public boolean hasMoreRequirements()
Returns true if the login process requires more information from the user to complete the authentication.- Returns:
- true if the login process requires more information from the user to complete the authentication.
-
getRequirements
public Callback[] getRequirements()
Returns an array ofCallbackobjects that must be populated by the user and returned back. These objects are requested by the authentication plug-ins, and these are usually displayed to the user. The user then provides the requested information for it to be authenticated.- Returns:
- an array of
Callbackobjects that must be populated by the user and returned back.
-
submitRequiredInformation
public void submitRequiredInformation(Callback[] info)
Submits the populatedCallbackobjects to the authentication plug-in modules. Called aftergetInformationRequiredmethod and obtaining user's response to these requests.- Parameters:
info- array ofCallbackobjects.
-
logout
public void logout() throws LoginExceptionLogs the user out.- Throws:
LoginException
-
getLoginException
public LoginException getLoginException()
Returns login exception, if any, during the authentication process. Typically set when the login fails.- Returns:
- login exception.
-
getLoginStatus
public int getLoginStatus()
Returns the current state of the login process. Possible states are listed above.- Returns:
- the current state of the login process.
-
setLoginStatus
protected void setLoginStatus(int status)
Method to set the login status. Used internally and not visible outside this package.
-
getPrincipal
public Principal getPrincipal()
Returns the (first)AuthPrincipalin theSubject. Returns the firstPrincipal, if more than one exists.- Returns:
- the (first)
AuthPrincipalin theSubject.
-
getAuthPrincipal
public AuthPrincipal getAuthPrincipal()
Deprecated.Use getPrincipal() insteadMethod to get the (first)AuthPrincipalin theSubject. Returns the firstPrincipal, if more than one exists.
-
getPrincipals
protected Set getPrincipals()
Method to get the set ofAuthPrincipals in theSubject.
-
getOrganizationName
public String getOrganizationName()
Method to get organization name that was set during construction of this instance.- Returns:
- organization name;
nullif it was not initialized during construction of this instance
-
getApplicationName
protected String getApplicationName()
-
getSSOToken
public SSOToken getSSOToken() throws InvalidAuthContextException
Method to get the Single-Sign-On (SSO) Token. This token can be used as the authenticated token.- Returns:
- single-sign-on token.
- Throws:
InvalidAuthContextException
-
-