Search in sources :

Example 26 with SSOException

use of com.iplanet.sso.SSOException in project OpenAM by OpenRock.

the class OathDevicesResource method actionCollection.

/**
     * {@inheritDoc}
     */
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    try {
        //could be admin
        final AMIdentity identity = getUserIdFromUri(context);
        final AuthenticatorOathService realmOathService = oathServiceFactory.create(getRealm(context));
        switch(request.getAction()) {
            case SKIP:
                try {
                    final boolean setValue = request.getContent().get(VALUE).asBoolean();
                    realmOathService.setUserSkipOath(identity, setValue ? AuthenticatorOathService.SKIPPABLE : AuthenticatorOathService.NOT_SKIPPABLE);
                    return newResultPromise(newActionResponse(JsonValueBuilder.jsonValue().build()));
                } catch (SSOException | IdRepoException e) {
                    debug.error("OathDevicesResource :: SKIP action - Unable to set value in user store.", e);
                    return new InternalServerErrorException().asPromise();
                }
            case CHECK:
                try {
                    final Set resultSet = identity.getAttribute(realmOathService.getSkippableAttributeName());
                    boolean result = false;
                    if (CollectionUtils.isNotEmpty(resultSet)) {
                        String tmp = (String) resultSet.iterator().next();
                        int resultInt = Integer.valueOf(tmp);
                        if (resultInt == AuthenticatorOathService.SKIPPABLE) {
                            result = true;
                        }
                    }
                    return newResultPromise(newActionResponse(JsonValueBuilder.jsonValue().put(RESULT, result).build()));
                } catch (SSOException | IdRepoException e) {
                    debug.error("OathDevicesResource :: CHECK action - Unable to read value from user store.", e);
                    return new InternalServerErrorException().asPromise();
                }
            case //sets their 'skippable' selection to default (NOT_SET) and deletes their profiles attribute
            RESET:
                try {
                    realmOathService.setUserSkipOath(identity, AuthenticatorOathService.NOT_SET);
                    realmOathService.removeAllUserDevices(identity);
                    return newResultPromise(newActionResponse(JsonValueBuilder.jsonValue().put(RESULT, true).build()));
                } catch (SSOException | IdRepoException e) {
                    debug.error("OathDevicesResource :: Action - Unable to reset identity attributes", e);
                    return new InternalServerErrorException().asPromise();
                }
            default:
                return new NotSupportedException().asPromise();
        }
    } catch (SMSException e) {
        debug.error("OathDevicesResource :: Action - Unable to communicate with the SMS.", e);
        return new InternalServerErrorException().asPromise();
    } catch (SSOException | InternalServerErrorException e) {
        debug.error("OathDevicesResource :: Action - Unable to retrieve identity data from request context", e);
        return new InternalServerErrorException().asPromise();
    }
}
Also used : Set(java.util.Set) AuthenticatorOathService(org.forgerock.openam.core.rest.devices.services.AuthenticatorOathService) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMIdentity(com.sun.identity.idm.AMIdentity) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 27 with SSOException

use of com.iplanet.sso.SSOException in project OpenAM by OpenRock.

the class AMOrganizationalUnitImpl method getOrgTypeAttributes.

/**
     * Protected method to be used to obtain organization attribute values for a
     * given serviceName and attribute name. Returns a null value if a template
     * value or default value for the attribute does not exist.
     */
protected Set getOrgTypeAttributes(String serviceName, String attrName) throws SSOException {
    Set attrValues = null;
    try {
        AMTemplate amTemplate = getTemplate(serviceName, AMTemplate.ORGANIZATION_TEMPLATE);
        attrValues = amTemplate.getAttribute(attrName);
        if (debug.messageEnabled()) {
            debug.message("AMOrganizationImpl." + "getOrgTypeAttributes(): " + "obtained from org template " + serviceName + " : " + attrName + "\n" + super.entryDN + " : " + attrValues);
        }
    } catch (AMException ame) {
        // Get default Service attribues
        try {
            Map defaultValues = AMServiceUtils.getServiceConfig(token, ADMINISTRATION_SERVICE, SchemaType.ORGANIZATION);
            attrValues = (Set) defaultValues.get(attrName);
            if (debug.messageEnabled()) {
                debug.message("AMOrganizationImpl." + "getOrgTypeAttributes(): " + "obtained from org defaults " + serviceName + " : " + attrName + "\n" + super.entryDN + " : " + attrValues);
            }
        } catch (Exception se) {
            debug.warning("AMOrganizationImpl." + "getOrgTypeAttributes(): " + "Error encountered in retrieving " + "default org attrs for", se);
        }
    }
    return attrValues;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Map(java.util.Map) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 28 with SSOException

use of com.iplanet.sso.SSOException in project OpenAM by OpenRock.

the class SessionService method isSuperUser.

/**
     * Returns true if the user is super user
     *
     * @param uuid the uuid of the login user
     */
public boolean isSuperUser(String uuid) {
    boolean isSuperUser = false;
    try {
        // Get the AMIdentity Object for super user 
        AMIdentity adminUserId = null;
        String adminUser = SystemProperties.get(Constants.AUTHENTICATION_SUPER_USER);
        if (adminUser != null) {
            adminUserId = new AMIdentity(dsameAdminTokenProvider.getAdminToken(), adminUser, IdType.USER, "/", null);
        }
        //Get the AMIdentity Object for login user
        AMIdentity user = IdUtils.getIdentity(dsameAdminTokenProvider.getAdminToken(), uuid);
        //Check for the equality
        isSuperUser = adminUserId.equals(user);
    } catch (SSOException ssoe) {
        sessionDebug.error("SessionService.isSuperUser: Cannot get the admin token for this operation.");
    } catch (IdRepoException idme) {
        sessionDebug.error("SessionService.isSuperUser: Cannot get the user identity.");
    }
    if (sessionDebug.messageEnabled()) {
        sessionDebug.message("SessionService.isSuperUser: " + isSuperUser);
    }
    return isSuperUser;
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 29 with SSOException

use of com.iplanet.sso.SSOException in project OpenAM by OpenRock.

the class AuthUtils method getGlobalAttributes.

/**
      * Returns <code>Map</code> attributes
      *
      * @param serviceName Service Name
      * @return <code>Map</code> of global attributes.
      */
public static Map getGlobalAttributes(String serviceName) {
    Map attrs = null;
    try {
        SSOToken dUserToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        ServiceSchemaManager scm = new ServiceSchemaManager(serviceName, dUserToken);
        ServiceSchema schema = scm.getGlobalSchema();
        if (schema != null) {
            attrs = schema.getAttributeDefaults();
        }
    } catch (SMSException smsExp) {
        utilDebug.error("AuthUtils.getGlobalAttributes: SMS Error", smsExp);
    } catch (SSOException ssoExp) {
        utilDebug.error("AuthUtils.getGlobalAttributes: SSO Error", ssoExp);
    }
    if (utilDebug.messageEnabled()) {
        utilDebug.message("AuthUtils.getGlobalAttributes: attrs=" + attrs);
    }
    return attrs;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashMap(java.util.HashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 30 with SSOException

use of com.iplanet.sso.SSOException in project OpenAM by OpenRock.

the class DeleteDataStores method handleRequest.

/**
     * Handles request.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List names = (List) rc.getOption(DatastoreOptions.DATASTORE_NAMES);
    validateRealm(realm);
    String[] params = { realm, names.toString() };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_DATASTORES", params);
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminSSOToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        if (cfg != null) {
            for (Iterator i = names.iterator(); i.hasNext(); ) {
                cfg.removeSubConfig((String) i.next());
            }
            if (names.size() > 1) {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastores-succeeded"));
            } else {
                getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-succeeded"));
            }
        } else {
            getOutputWriter().printlnMessage(getResourceString("datastore-delete-datastore-not-found"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_DATASTORES", params);
    } catch (SMSException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        debugError("DeleteDataStores.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_DATASTORES", params);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

SSOException (com.iplanet.sso.SSOException)1002 SMSException (com.sun.identity.sm.SMSException)553 Set (java.util.Set)374 SSOToken (com.iplanet.sso.SSOToken)336 IdRepoException (com.sun.identity.idm.IdRepoException)291 HashSet (java.util.HashSet)289 Map (java.util.Map)223 HashMap (java.util.HashMap)205 AMIdentity (com.sun.identity.idm.AMIdentity)193 Iterator (java.util.Iterator)189 CLIException (com.sun.identity.cli.CLIException)170 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)126 ServiceConfig (com.sun.identity.sm.ServiceConfig)126 IOutput (com.sun.identity.cli.IOutput)121 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)104 ServiceSchema (com.sun.identity.sm.ServiceSchema)101 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)93 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)88 IOException (java.io.IOException)65 PolicyException (com.sun.identity.policy.PolicyException)62