use of com.sun.identity.authentication.server.AuthContextLocal in project OpenAM by OpenRock.
the class CoreServicesWrapper method getAuthContext.
/**
* Will either create or retrieve an existing AuthContextLocal.
*
* {@link AuthUtils#getAuthContext(HttpServletRequest,
* HttpServletResponse, SessionID, boolean, boolean)} (
*
* @param request The HttpServletRequest.
* @param response The HttpServletResponse.
* @param sessionID The Session ID of the AuthContextLocal, empty String if initial request.
* @param isSessionUpgrade Whether the AuthContextLocal should be created for session upgrade.
* @param isBackPost True if back posting.
* @return The AuthContextLocal wrapped as a AuthContextLocalWrapper.
* @throws AuthException If there is a problem creating/retrieving the
* AuthContextLocal.
*/
public AuthContextLocalWrapper getAuthContext(HttpServletRequest request, HttpServletResponse response, SessionID sessionID, boolean isSessionUpgrade, boolean isBackPost) throws AuthException {
AuthContextLocal authContextLocal = AuthUtils.getAuthContext(request, response, sessionID, isSessionUpgrade, isBackPost);
String orgDN = AuthClientUtils.getDomainNameByRequest(request, AuthClientUtils.parseRequestParameters(request));
authContextLocal.setOrgDN(orgDN);
return new AuthContextLocalWrapper(authContextLocal);
}
use of com.sun.identity.authentication.server.AuthContextLocal in project OpenAM by OpenRock.
the class AuthUtils method getAuthContext.
/**
* Returns the authentication context for a request.
*
* @param request HTTP Servlet Request.
* @param response HTTP Servlet Response.
* @param sid SessionID for this request.
* @param isSessionUpgrade <code>true</code> if session upgrade.
* @param isBackPost <code>true</code> if back posting.
* @param isLogout <code>true</code> for logout.
* @return authentication context.
*/
public static AuthContextLocal getAuthContext(HttpServletRequest request, HttpServletResponse response, SessionID sid, boolean isSessionUpgrade, boolean isBackPost, boolean isLogout) throws AuthException {
utilDebug.message("In AuthUtils:getAuthContext");
Hashtable dataHash;
AuthContextLocal authContext = null;
LoginState loginState = null;
// initialize auth service.
AuthD ad = AuthD.getAuth();
try {
dataHash = parseRequestParameters(request);
authContext = retrieveAuthContext(request, sid);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getAuthContext:sid is.. .: " + sid);
utilDebug.message("AuthUtil:getAuthContext:authContext is..: " + authContext);
}
if (!sid.isNull() && authContext == null && !isSessionUpgrade) {
String authCookieValue = getAuthCookieValue(request);
if ((authCookieValue != null) && (!authCookieValue.isEmpty()) && (!authCookieValue.equalsIgnoreCase("LOGOUT"))) {
String cookieURL = null;
try {
SessionID sessionID = new SessionID(authCookieValue);
URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
cookieURL = sessionServerURL.getProtocol() + "://" + sessionServerURL.getHost() + ":" + Integer.toString(sessionServerURL.getPort()) + serviceURI;
} catch (SessionException e) {
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:getAuthContext():" + e.toString());
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:getAuthContext():" + "cookieURL : " + cookieURL);
}
if ((cookieURL != null) && (!cookieURL.isEmpty()) && (isLocalServer(cookieURL, true))) {
utilDebug.error("AuthUtils:getAuthContext(): " + "Invalid Session Timed out");
clearAllCookies(request, response);
throw new AuthException(AMAuthErrorCode.AUTH_TIMEOUT, null);
}
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("isSessionUpgrade :" + isSessionUpgrade);
utilDebug.message("BACK with Request method POST : " + isBackPost);
}
if ((authContext == null) && (isLogout)) {
return null;
}
if ((authContext == null) || (isSessionUpgrade) || (isBackPost)) {
try {
loginState = new LoginState();
InternalSession oldSession = null;
if (sid != null) {
oldSession = AuthD.getSession(sid);
loginState.setOldSession(oldSession);
}
if (isSessionUpgrade) {
loginState.setOldSession(oldSession);
loginState.setSessionUpgrade(isSessionUpgrade);
} else if (isBackPost) {
loginState.setOldSession(oldSession);
}
authContext = loginState.createAuthContext(request, response, sid, dataHash);
loginState.setForceAuth(Boolean.parseBoolean(request.getParameter(FORCE_AUTH)));
authContext.setLoginState(loginState);
String queryOrg = getQueryOrgName(request, getOrgParam(dataHash));
if (utilDebug.messageEnabled()) {
utilDebug.message("query org is .. : " + queryOrg);
}
loginState.setQueryOrg(queryOrg);
} catch (AuthException ae) {
utilDebug.message("Error creating AuthContextLocal : ");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception ", ae);
}
throw new AuthException(ae);
}
} else {
utilDebug.message("getAuthContext: found existing request.");
authContext = processAuthContext(authContext, request, response, dataHash, sid);
loginState = getLoginState(authContext);
loginState.setNewRequest(false);
}
} catch (Exception ee) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Error creating AuthContextLocal : " + ee.getMessage());
}
throw new AuthException(ee);
}
return authContext;
}
use of com.sun.identity.authentication.server.AuthContextLocal in project OpenAM by OpenRock.
the class AuthUtils method getAuthContext.
/* create auth context for org and sid, if sessionupgrade then
* save the previous authcontext and create new authcontext
* orgName - organization name to login too
* sessionId - sessionID of the request - "0" if new request
* isLogout - is this a logout request - if yes then no session
* upgrade - this is the case where session is VALID so need
* to use this flag to determine if session upgrade is needed.
* this is used mainly for Logout/Abort.
* @param orgName OrganizationName in request
* @param sessionID Session ID for this request
* @param isLogout a boolean which is true if it is a Logout request
* @param req HttpServletRequest
* @param indexType Index Type
* @param indexName Index Name
* @param forceAuth force auth flag
* @return AuthContextLocal object
*/
public static AuthContextLocal getAuthContext(String orgName, String sessionID, boolean isLogout, HttpServletRequest req, String indexType, AuthXMLRequest xmlReq, boolean forceAuth) throws AuthException {
AuthContextLocal authContext = null;
SessionID sid = null;
com.iplanet.dpro.session.service.InternalSession sess = null;
LoginState loginState = null;
boolean sessionUpgrade = false;
AuthD ad = AuthD.getAuth();
int sessionState = -1;
SSOToken ssot = null;
String indexName = null;
if (xmlReq != null) {
indexName = xmlReq.getIndexName();
}
if (utilDebug.messageEnabled()) {
utilDebug.message("orgName : " + orgName);
utilDebug.message("sessionID is " + sessionID);
utilDebug.message("sessionID is " + sessionID.length());
utilDebug.message("isLogout : " + isLogout);
}
try {
if ((sessionID != null) && (!sessionID.equals("0"))) {
sid = new SessionID(sessionID);
authContext = retrieveAuthContext(req, sid);
// check if this sesson id is active, if yes then it
// is a session upgrade case.
loginState = getLoginState(authContext);
if (loginState != null) {
sess = loginState.getSession();
} else {
sess = AuthD.getSession(sessionID);
}
if (sess == null) {
sessionUpgrade = false;
} else {
sessionState = sess.getState();
if (utilDebug.messageEnabled()) {
utilDebug.message("sid from sess is : " + sess.getID());
utilDebug.message("sess is : " + sessionState);
}
if (!((sessionState == INVALID) || (isLogout))) {
ssot = AuthUtils.getExistingValidSSOToken(sid);
if ((indexType != null) && (indexName != null)) {
Hashtable indexTable = new Hashtable();
indexTable.put(indexType, indexName);
if (forceAuth) {
sessionUpgrade = true;
} else {
sessionUpgrade = checkSessionUpgrade(ssot, indexTable);
}
} else {
sessionUpgrade = true;
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("session upgrade is : " + sessionUpgrade);
}
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getAuthContext:sid is.. .: " + sid);
utilDebug.message("AuthUtil:getAuthContext:authContext is.. .: " + authContext);
utilDebug.message("AuthUtil:getAuthContext:sessionUpgrade is.. .: " + sessionUpgrade);
utilDebug.message("AuthUtil:getAuthContext:ForceAuth is.. .: " + forceAuth);
}
if ((orgName == null) && (sess == null)) {
utilDebug.error("Cannot create authcontext with null org ");
throw new AuthException(AMAuthErrorCode.AUTH_TIMEOUT, null);
} else if (orgName == null) {
orgName = sess.getClientDomain();
}
if ((ssot != null) && !(sessionUpgrade)) {
xmlReq.setValidSessionNoUpgrade(true);
return null;
}
if (((ssot == null) && (loginState == null)) || (sessionUpgrade)) {
try {
loginState = new LoginState();
InternalSession oldSession = null;
if (sid != null) {
oldSession = AuthD.getSession(sid);
loginState.setOldSession(oldSession);
}
if (sessionUpgrade) {
loginState.setOldSession(oldSession);
loginState.setSessionUpgrade(sessionUpgrade);
}
authContext = loginState.createAuthContext(sid, orgName, req);
authContext.setLoginState(loginState);
String queryOrg = getQueryOrgName(null, orgName);
if (utilDebug.messageEnabled()) {
utilDebug.message("query org is .. : " + queryOrg);
}
loginState.setQueryOrg(queryOrg);
} catch (AuthException ae) {
utilDebug.message("Error creating AuthContextLocal 2: ");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception ", ae);
}
throw new AuthException(ae);
}
} else {
// update loginState
try {
com.iplanet.dpro.session.service.InternalSession requestSess = ad.getSession(sessionID);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil :Session is .. : " + requestSess);
}
loginState = getLoginState(authContext);
if (loginState != null) {
loginState.setSession(requestSess);
loginState.setNewRequest(false);
}
} catch (Exception ae) {
utilDebug.message("Error Retrieving AuthContextLocal");
if (utilDebug.messageEnabled()) {
utilDebug.message("Exception ", ae);
}
throw new AuthException(AMAuthErrorCode.AUTH_ERROR, null);
}
}
if (forceAuth) {
loginState.setForceAuth(forceAuth);
}
} catch (Exception ee) {
if (utilDebug.messageEnabled()) {
utilDebug.message("Creating AuthContextLocal 2: ", ee);
}
throw new AuthException(ee);
}
return authContext;
}
use of com.sun.identity.authentication.server.AuthContextLocal in project OpenAM by OpenRock.
the class AuthUtils method retrieveAuthContext.
// retrieve the AuthContextLocal object from the Session object.
private static AuthContextLocal retrieveAuthContext(SessionID sid) {
com.iplanet.dpro.session.service.InternalSession is = AuthD.getSession(sid);
AuthContextLocal localAC = null;
if (is != null) {
localAC = (AuthContextLocal) is.getObject(ISAuthConstants.AUTH_CONTEXT_OBJ);
}
if (utilDebug.messageEnabled()) {
utilDebug.message("retrieveAuthContext - InternalSession = " + is);
utilDebug.message("retrieveAuthContext - aclocal = " + localAC);
}
return localAC;
}
use of com.sun.identity.authentication.server.AuthContextLocal in project OpenAM by OpenRock.
the class AuthUtils method getOrigAuthContext.
/* retreive the authcontext based on the req */
public static AuthContextLocal getOrigAuthContext(SessionID sid) throws AuthException {
AuthContextLocal authContext = null;
// initialize auth service.
AuthD ad = AuthD.getAuth();
try {
authContext = retrieveAuthContext(sid);
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtil:getOrigAuthContext:sid is.:" + sid);
utilDebug.message("AuthUtil:getOrigAuthContext:authContext is:" + authContext);
}
com.iplanet.dpro.session.service.InternalSession sess = getLoginState(authContext).getSession();
if (utilDebug.messageEnabled()) {
utilDebug.message("Session is : " + sess);
if (sess != null) {
utilDebug.message("Session State is : " + sess.getState());
}
utilDebug.message("Returning Orig AuthContext:" + authContext);
}
if (sess == null) {
return null;
} else {
int status = sess.getState();
if (status == INVALID) {
return null;
}
return authContext;
}
} catch (Exception e) {
return null;
}
}
Aggregations