Search in sources :

Example 31 with ForbiddenException

use of org.forgerock.json.resource.ForbiddenException 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)

Aggregations

ForbiddenException (org.forgerock.json.resource.ForbiddenException)31 SSOException (com.iplanet.sso.SSOException)26 BadRequestException (org.forgerock.json.resource.BadRequestException)22 NotFoundException (org.forgerock.json.resource.NotFoundException)21 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)20 ResourceException (org.forgerock.json.resource.ResourceException)19 IdRepoException (com.sun.identity.idm.IdRepoException)18 SMSException (com.sun.identity.sm.SMSException)18 JsonValue (org.forgerock.json.JsonValue)17 PermanentException (org.forgerock.json.resource.PermanentException)16 SSOToken (com.iplanet.sso.SSOToken)15 ConflictException (org.forgerock.json.resource.ConflictException)15 RealmContext (org.forgerock.openam.rest.RealmContext)14 NotSupportedException (org.forgerock.json.resource.NotSupportedException)11 ResourceResponse (org.forgerock.json.resource.ResourceResponse)11 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)10 ObjectNotFound (com.sun.identity.idsvcs.ObjectNotFound)10 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)9 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8