Search in sources :

Example 51 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SmsRealmProvider method handleQuery.

@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (!"true".equals(request.getQueryFilter().toString())) {
        return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
    }
    if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
        return new NotSupportedException("Query paging not currently supported").asPromise();
    }
    final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
    try {
        final SessionID sessionID = new SessionID(getUserSsoToken(context).getTokenID().toString());
        final String realmPath = coreWrapper.convertOrgNameToRealmName(sessionCache.getSession(sessionID).getClientDomain());
        final OrganizationConfigManager ocm = new OrganizationConfigManager(getUserSsoToken(context), realmPath);
        //Return realm query is being performed on
        handler.handleResource(getResource(getJsonValue(realmPath)));
        for (final Object subRealmRelativePath : ocm.getSubOrganizationNames("*", true)) {
            String realmName;
            if (realmPath.endsWith("/")) {
                realmName = realmPath + subRealmRelativePath;
            } else {
                realmName = realmPath + "/" + subRealmRelativePath;
            }
            handler.handleResource(getResource(getJsonValue(realmName)));
        }
        debug.message("RealmResource :: QUERY : performed by {}", principalName);
        return newResultPromise(newQueryResponse());
    } catch (SSOException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
        return new ForbiddenException().asPromise();
    } catch (SessionException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
        return new InternalServerErrorException().asPromise();
    } catch (SMSException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed :" + ex);
        switch(ex.getExceptionCode()) {
            case STATUS_NO_PERMISSION:
                // This exception will be thrown if permission to read realms from SMS has not been delegated
                return new ForbiddenException().asPromise();
            default:
                return new InternalServerErrorException().asPromise();
        }
    }
}
Also used : ForbiddenException(org.forgerock.json.resource.ForbiddenException) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) SessionException(com.iplanet.dpro.session.SessionException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) SessionID(com.iplanet.dpro.session.SessionID)

Example 52 with SessionException

use of com.iplanet.dpro.session.SessionException 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 53 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class StatelessOperationsTest method shouldNotBlacklistSessionOnDestroyIfNotAllowed.

@Test(expectedExceptions = SessionException.class, expectedExceptionsMessageRegExp = "test")
public void shouldNotBlacklistSessionOnDestroyIfNotAllowed() throws Exception {
    // Given
    Session requester = mock(Session.class);
    SessionException ex = new SessionException("test");
    willThrow(ex).given(mockSessionService).checkPermissionToDestroySession(requester, sid);
    // When
    try {
        statelessOperations.destroy(requester, mockSession);
    } finally {
        // Then
        verifyZeroInteractions(mockSessionBlacklist);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session) StatelessSession(org.forgerock.openam.sso.providers.stateless.StatelessSession) Test(org.testng.annotations.Test)

Example 54 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class CTSSessionBlacklistTest method shouldPropagateSessionExceptions.

@Test(expectedExceptions = SessionException.class)
public void shouldPropagateSessionExceptions() throws Exception {
    // Given
    given(mockSession.getBlacklistExpiryTime(anyLong())).willThrow(new SessionException("test"));
    // When
    testBlacklist.blacklist(mockSession);
// Then - exception
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) Test(org.testng.annotations.Test)

Example 55 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SessionService method getClusterMonitor.

/**
     * The ClusterMonitor state depends on whether the system is configured for
     * SFO or not. As such, this method is aware of the change in SFO state
     * and triggers a re-initialisation of the ClusterMonitor as required.
     *
     * Note, this method also acts as the lazy initialiser for the ClusterMonitor.
     *
     * Thread Safety: Uses atomic reference to ensure only one thread can modify
     * the reference at any one time.
     *
     * @return A non null instance of the current ClusterMonitor.
     * @throws SessionException If there was an error initialising the ClusterMonitor.
     */
private ClusterMonitor getClusterMonitor() throws SessionException {
    if (!isClusterMonitorValid()) {
        try {
            ClusterMonitor previous = clusterMonitor.getAndSet(resolveClusterMonitor());
            if (previous != null) {
                sessionDebug.message("Previous ClusterMonitor shutdown: {}", previous.getClass().getSimpleName());
                previous.shutdown();
            }
            sessionDebug.message("ClusterMonitor initialised: {}", clusterMonitor.get().getClass().getSimpleName());
        } catch (Exception e) {
            sessionDebug.error("Failed to initialise ClusterMonitor", e);
        }
    }
    ClusterMonitor monitor = clusterMonitor.get();
    if (monitor == null) {
        throw new SessionException("Failed to initialise ClusterMonitor");
    }
    return monitor;
}
Also used : MultiServerClusterMonitor(com.iplanet.dpro.session.service.cluster.MultiServerClusterMonitor) ClusterMonitor(com.iplanet.dpro.session.service.cluster.ClusterMonitor) SingleServerClusterMonitor(com.iplanet.dpro.session.service.cluster.SingleServerClusterMonitor) SessionException(com.iplanet.dpro.session.SessionException) DelegationException(com.sun.identity.delegation.DelegationException) SSOException(com.iplanet.sso.SSOException) InterruptedIOException(java.io.InterruptedIOException) IdRepoException(com.sun.identity.idm.IdRepoException) ConnectException(java.net.ConnectException) SessionException(com.iplanet.dpro.session.SessionException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Aggregations

SessionException (com.iplanet.dpro.session.SessionException)60 SessionID (com.iplanet.dpro.session.SessionID)22 Session (com.iplanet.dpro.session.Session)18 SSOException (com.iplanet.sso.SSOException)15 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)9 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)8 URL (java.net.URL)8 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 InternalSession (com.iplanet.dpro.session.service.InternalSession)6 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)6 DelegationException (com.sun.identity.delegation.DelegationException)5 InterruptedIOException (java.io.InterruptedIOException)5 ConnectException (java.net.ConnectException)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)4 SSOToken (com.iplanet.sso.SSOToken)4