use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class SessionCommand method displaySessions.
private List displaySessions(SSOToken ssoToken) throws CLIException {
String origHost = getStringOptionValue(ARGUMENT_HOST_NAME);
String host = trimTrailingSlash(origHost);
StringTokenizer st = new StringTokenizer(host, ":");
if (st.countTokens() != 3) {
Object[] params = { origHost };
throw new CLIException(MessageFormat.format(getResourceString("session-invalid-host-name"), params), ExitCodes.INVALID_OPTION_VALUE);
}
curSessionID = new SessionID(ssoToken.getTokenID().toString());
String filter = getStringOptionValue(IArgument.FILTER);
if ((filter == null) || (filter.trim().length() == 0)) {
filter = "*";
}
try {
curSession = sessionCache.getSession(curSessionID);
return getSessionList(host, filter);
} catch (SessionException se) {
throw new CLIException(se, ExitCodes.SESSION_BASED_LOGIN_FAILED);
}
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class SMProfileModelImpl method initSessionsList.
/**
* Initializes sessions list.
*
* @param pattern user id pattern to search for.
* @throws AMConsoleException if unable to initialized the session list.
*/
private void initSessionsList(String pattern) throws AMConsoleException {
pattern = pattern.toLowerCase();
String[] params = { serverName, pattern };
logEvent("ATTEMPT_GET_CURRENT_SESSIONS", params);
try {
Session session = sessionCache.getSession(new SessionID(getUserSSOToken().getTokenID().toString()));
SearchResults result = session.getValidSessions(serverName, pattern);
Map<String, Session> sessions = (Map<String, Session>) result.getResultAttributes();
String errorMessage = AMAdminUtils.getSearchResultWarningMessage(result, this);
smSessionCache = new SMSessionCache(sessions.values(), errorMessage, this);
logEvent("SUCCEED_GET_CURRENT_SESSIONS", params);
} catch (SessionException se) {
String strError = getErrorString(se);
String[] paramsEx = { serverName, pattern, strError };
logEvent("SESSION_EXCEPTION_GET_CURRENT_SESSIONS", paramsEx);
throw new AMConsoleException(strError);
}
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class AuthContext method login.
private void login(IndexType indexType, String indexName, String[] params, Map envMap, String locale, HttpServletRequest request, HttpServletResponse response) throws AuthLoginException {
if (ssoToken != null) {
try {
organizationName = ssoToken.getProperty(ISAuthConstants.ORGANIZATION);
ssoTokenID = ssoToken.getTokenID().toString();
authURL = sessionCache.getSession(new SessionID(ssoTokenID)).getSessionServiceURL();
} catch (Exception e) {
throw new AuthLoginException(e);
}
}
if (authURL != null) {
authServiceURL = getAuthServiceURL(authURL.getProtocol(), authURL.getHost(), Integer.toString(authURL.getPort()), authURL.getPath());
}
AuthLoginException authException = null;
try {
if (authServiceURL == null) {
authServiceURL = getAuthServiceURL(server_proto, server_host, server_port, server_uri);
}
if (authServiceURL != null) {
if (authDebug.messageEnabled()) {
authDebug.message("AuthContext.login : runLogin against " + authServiceURL);
}
runLogin(indexType, indexName, params, envMap, locale, request, response);
return;
}
} catch (AuthLoginException e) {
authException = e;
authDebug.error("Failed to login to " + authServiceURL);
} catch (Exception e) {
authDebug.error("Failed to login to " + authServiceURL + ": " + e.getMessage(), e);
}
if (authURL == null) {
// failover when authURL is not specified
Vector serviceURLs = null;
try {
serviceURLs = WebtopNaming.getServiceAllURLs(AuthXMLTags.AUTH_SERVICE);
} catch (Exception e) {
throw new AuthLoginException(amAuthContext, "loginError", new Object[] { e.getMessage() });
}
if (authDebug.messageEnabled()) {
authDebug.message("Org Name : " + organizationName);
authDebug.message("ssoTokenID: " + ssoTokenID);
authDebug.message("serviceURLs: " + serviceURLs);
}
if (serviceURLs != null) {
serviceURLs.remove(authServiceURL);
for (Enumeration e = serviceURLs.elements(); e.hasMoreElements(); ) {
authServiceURL = (URL) e.nextElement();
try {
runLogin(indexType, indexName, params, envMap, locale, request, response);
return;
} catch (AuthLoginException ex) {
authException = ex;
authDebug.error("Failed to login in failover with " + authServiceURL + ": " + ex.getMessage());
}
}
}
}
authDebug.error("Authentication failed.");
if (authException != null) {
throw authException;
} else {
throw new AuthLoginException(amAuthContext, "loginError", null);
}
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class AuthClientUtils method getCookieURLForSessionUpgrade.
public static String getCookieURLForSessionUpgrade(HttpServletRequest request) {
String cookieURL = null;
try {
SSOTokenManager tokenManager = SSOTokenManager.getInstance();
SSOToken token = tokenManager.createSSOToken(request);
Hashtable reqDataHash = parseRequestParameters(request);
if (tokenManager.isValidToken(token)) {
cookieURL = getCookieURL(new SessionID(token.getTokenID().toString()));
if (cookieURL != null && !isLocalServer(cookieURL, true) && (forceAuthFlagExists(reqDataHash) || checkSessionUpgrade(token, reqDataHash))) {
return cookieURL;
}
}
} catch (SSOException ssoe) {
if (utilDebug.messageEnabled()) {
utilDebug.message("SSOException occurred while checking session upgrade case", ssoe);
}
}
return null;
}
use of com.iplanet.dpro.session.SessionID in project OpenAM by OpenRock.
the class AuthClientUtils method getSessionIDFromRequest.
/**
* Returns the Session ID for this request. If Authetnication Cookie and
* Valid AM Cookie are there and request method is GET then use Valid
* AM Cookie else use Auth Cookie. The cookie in the request for invalid
* sessions is in auth cookie, <code>com.iplanet.am.auth.cookie</code>,
* and for active/inactive sessions in <code>com.iplanet.am.cookie</code>.
*
* @param request HTTP Servlet Request.
* @return Session ID for this request.
*/
public static SessionID getSessionIDFromRequest(HttpServletRequest request) {
boolean isGetRequest = (request != null && request.getMethod().equalsIgnoreCase("GET"));
SessionID amCookieSid = new SessionID(request);
SessionID authCookieSid = getSidFromCookie(request);
SessionID sessionID;
if (authCookieSid == null) {
sessionID = amCookieSid;
} else {
if (isGetRequest) {
sessionID = amCookieSid;
} else {
sessionID = authCookieSid;
}
}
if (utilDebug.messageEnabled()) {
utilDebug.message("AuthUtils:returning sessionID:" + sessionID);
}
return sessionID;
}
Aggregations