Search in sources :

Example 1 with SearchResults

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);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) SessionID(com.iplanet.dpro.session.SessionID) HashMap(java.util.HashMap) Map(java.util.Map) Session(com.iplanet.dpro.session.Session)

Example 2 with SearchResults

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;
}
Also used : ArrayList(java.util.ArrayList) SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Session(com.iplanet.dpro.session.Session)

Example 3 with SearchResults

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;
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Session(com.iplanet.dpro.session.Session)

Example 4 with SearchResults

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);
    }
}
Also used : HashMap(java.util.HashMap) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) SearchResults(com.sun.identity.common.SearchResults) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) SSOException(com.iplanet.sso.SSOException) SessionResponse(com.iplanet.dpro.session.share.SessionResponse)

Aggregations

SearchResults (com.sun.identity.common.SearchResults)4 Session (com.iplanet.dpro.session.Session)3 SessionException (com.iplanet.dpro.session.SessionException)3 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 SessionID (com.iplanet.dpro.session.SessionID)1 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)1 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)1 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)1 SSOException (com.iplanet.sso.SSOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1