use of com.sun.identity.common.SearchResults 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.sun.identity.common.SearchResults in project OpenAM by OpenRock.
the class SessionCommand method getSessionList.
private List getSessionList(String name, String pattern) throws CLIException {
IOutput output = getOutputWriter();
List list = new ArrayList();
try {
String currentSessionHandler = curSession.getProperty(SESSION_HANDLE_PROP);
SearchResults result = curSession.getValidSessions(name, null);
String warning = getSearchResultWarningMessage(result);
if (warning.length() > 0) {
output.printlnMessage(warning);
}
Map<String, Session> sessions = (Map<String, Session>) result.getResultAttributes();
boolean isCurrentSession = false;
int i = 0;
for (Iterator iter = (Iterator) sessions.values().iterator(); iter.hasNext(); ) {
boolean isCurr = false;
Session sess = (Session) iter.next();
// need to check current session only if we have not found it.
if (!isCurrentSession) {
try {
isCurr = sess.getProperty(SESSION_HANDLE_PROP).equals(currentSessionHandler);
} catch (SessionException se) {
throw new CLIException(se, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
isCurrentSession = isCurr;
}
String userId = sess.getProperty(USER_ID);
if (userId != null) {
userId = dnToName(userId);
if (DisplayUtils.wildcardMatch(userId, pattern)) {
// -1 indicates that it is current session.
int idx = (isCurr) ? -1 : i++;
SessionData sData = createSessionData(idx, userId, sess);
if (idx == -1) {
list.add(0, sData);
} else {
list.add(sData);
}
}
}
}
} catch (SessionException se) {
throw new CLIException(se, ExitCodes.INVALID_OPTION_VALUE);
}
return list;
}
use of com.sun.identity.common.SearchResults 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.sun.identity.common.SearchResults in project OpenAM by OpenRock.
the class Session method getValidSessions.
/**
* Returns all the valid sessions for a particular Session Service URL. If a
* user is not allowed to access the Sessions of the input Session Server,
* it will return null.
*
* @param svcurl Session Service URL.
* @exception SessionException
*/
private SearchResults getValidSessions(URL svcurl, String pattern) throws SessionException {
try {
int[] status = { 0 };
List<SessionInfo> infos = null;
boolean isLocal = false;
if (sessionService != null && sessionService.isLocalSessionService(svcurl)) {
infos = sessionService.getValidSessions(this, pattern, status);
isLocal = true;
} else {
SessionRequest sreq = new SessionRequest(SessionRequest.GetValidSessions, sessionID.toString(), false);
if (pattern != null) {
sreq.setPattern(pattern);
}
SessionResponse sres = requests.getSessionResponseWithRetry(svcurl, sreq, this);
infos = sres.getSessionInfo();
status[0] = sres.getStatus();
}
Map<String, Session> sessions = new HashMap<String, Session>();
Session session = null;
for (SessionInfo info : infos) {
SessionID sid = new SessionID(info.getSessionID());
session = new Session(sid, isLocal);
session.sessionServiceURL = svcurl;
session.update(info);
sessions.put(info.getSessionID(), session);
}
return new SearchResults(sessions.size(), sessions.keySet(), status[0], sessions);
} catch (Exception ex) {
sessionDebug.error("Session:getValidSession : ", ex);
throw new SessionException(SessionBundle.rbName, "getValidSessionsError", null);
}
}
Aggregations