use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SMProfileModelImpl method getValidSessions.
private Map<String, Session> getValidSessions(Session session, String pattern) throws AMConsoleException {
Map<String, Session> sessions = Collections.emptyMap();
try {
SearchResults result = session.getValidSessions(serverName, pattern);
Map<String, Session> validSessions = result.getResultAttributes();
if ((validSessions != null) && !validSessions.isEmpty()) {
sessions = new HashMap<String, Session>(validSessions.size());
for (Session s : validSessions.values()) {
if (s != null) {
sessions.put(s.getID().toString(), s);
}
}
}
} catch (SessionException se) {
throw new AMConsoleException(getErrorString(se));
}
return sessions;
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SMProfileModelImpl method invalidateSessions.
public List<String> invalidateSessions(List<String> list, String pattern) throws AMConsoleException {
List<String> failList = Collections.emptyList();
if ((list != null) && !list.isEmpty()) {
Session session = getCurrentSession();
Map<String, Session> validSessions = getValidSessions(session, pattern);
list.retainAll(validSessions.keySet());
if (!list.isEmpty()) {
String currentSessionHandler = null;
try {
currentSessionHandler = session.getProperty(SESSION_HANDLE_PROP);
} catch (SessionException se) {
throw new AMConsoleException(getErrorString(se));
}
String[] params = new String[2];
params[0] = serverName;
String curSessionId = null;
failList = new ArrayList<String>(list.size());
for (String sessionId : list) {
Session s = validSessions.get(sessionId);
params[1] = sessionId;
boolean isCurrentSession = false;
try {
isCurrentSession = currentSessionHandler.equals(s.getProperty(SESSION_HANDLE_PROP));
} catch (SessionException se) {
logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", params);
throw new AMConsoleException(getErrorString(se));
}
if (isCurrentSession) {
curSessionId = sessionId;
validSession = false;
} else {
try {
logEvent("ATTEMPT_INVALIDATE_SESSIONS", params);
session.destroySession(s);
logEvent("SUCCEED_INVALIDATE_SESSIONS", params);
} catch (SessionException se) {
String[] paramsEx = { serverName, sessionId, getErrorString(se) };
logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", paramsEx);
try {
failList.add(s.getProperty(USER_ID));
} catch (SessionException e) {
debug.error("SMProfileModelImpl.invalidateSessions", e);
}
debug.error("SMProfileModelImpl.invalidateSessions", se);
}
}
}
if (!validSession) {
params[1] = curSessionId;
logEvent("ATTEMPT_INVALIDATE_SESSIONS", params);
try {
session.destroySession(session);
logEvent("SUCCEED_INVALIDATE_SESSIONS", params);
} catch (SessionException se) {
String[] paramsEx = { serverName, curSessionId, getErrorString(se) };
logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", paramsEx);
}
}
}
}
return failList;
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SSOProviderImpl method createSSOToken.
/**
* Creates a single sign on token.
*
* @param tokenId single sign on token ID.
* @param invokedByAuth boolean flag indicating that this method has been invoked by the AuthContext.getSSOToken()
* API.
* @param possiblyResetIdleTime If true, the idle time of the token/session may be reset to zero. If false, the
* idle time will never be reset.
* @return single sign on token.
* @throws SSOException if the single sign on token cannot be created for any reason.
* @throws java.lang.UnsupportedOperationException only here to satisfy the interface, this is never thrown.
*/
public SSOToken createSSOToken(String tokenId, boolean invokedByAuth, boolean possiblyResetIdleTime) throws SSOException, UnsupportedOperationException {
try {
SessionID sessionId = new SessionID(tokenId);
sessionId.setComingFromAuth(invokedByAuth);
Session session = sessionCache.getSession(sessionId, false, possiblyResetIdleTime);
SSOToken ssoToken = new SSOTokenImpl(session);
return ssoToken;
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message("SSOProviderImpl.createSSOToken(tokenId, " + invokedByAuth + ", " + possiblyResetIdleTime + ") could not create SSOToken for token ID \"" + tokenId + "\" (" + e.getMessage() + ")");
}
throw new SSOException(e);
}
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SSOProviderImpl method logout.
@Override
public void logout(final SSOToken token) throws SSOException {
try {
Session session = sessionCache.getSession(new SessionID(token.getTokenID().toString()));
session.logout();
} catch (SessionException e) {
if (debug.messageEnabled()) {
debug.message("Logout: ", e);
}
throw new SSOException(e);
}
}
use of com.iplanet.dpro.session.Session in project OpenAM by OpenRock.
the class SSOProviderImpl method createSSOToken.
/**
* Creates a single sign on token.
*
* @param tokenId single sign on token ID.
* @param clientIP client IP address
* @return single sign on token.
* @throws SSOException if the single sign on token cannot be created.
* @throws UnsupportedOperationException Thrown to indicate that the
* requested operation is not supported.
* @deprecated Use #createSSOToken(String, String)
*/
public SSOToken createSSOToken(String tokenId, String clientIP) throws SSOException, UnsupportedOperationException {
try {
SessionID sessionId = new SessionID(tokenId);
Session session = sessionCache.getSession(sessionId);
if (checkIP && !isIPValid(session, clientIP)) {
throw new Exception(SSOProviderBundle.getString("invalidIP"));
}
SSOToken ssoToken = new SSOTokenImpl(session);
return ssoToken;
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message("could not create SSOToken for token ID \"" + tokenId + "\" (" + e.getMessage() + ")");
}
throw new SSOException(e);
}
}
Aggregations