Search in sources :

Example 51 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class SelectRealmModelImpl method getRealmNames.

/**
     * Returns realms that have names matching with a filter.
     *
     * @param base Base realm name for this search. null indicates root
     *        suffix.
     * @param filter Filter string.
     * @return realms that have names matching with a filter.
     * @throws AMConsoleException if search fails.
     */
public Set getRealmNames(String base, String filter) throws AMConsoleException {
    if ((base == null) || (base.length() == 0)) {
        base = getStartDN();
    }
    String[] param = { base };
    logEvent("ATTEMPT_GET_REALM_NAMES", param);
    try {
        OrganizationConfigManager orgMgr = new OrganizationConfigManager(getUserSSOToken(), base);
        logEvent("SUCCEED_GET_REALM_NAMES", param);
        return PolicyModelImpl.appendBaseDN(base, orgMgr.getSubOrganizationNames(filter, true), filter, this);
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { base, strError };
        logEvent("SMS_EXCEPTION_GET_REALM_NAMES", paramsEx);
        throw new AMConsoleException(strError);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 52 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class SmsRealmProvider method handleDelete.

@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context serverContext, DeleteRequest request) {
    RealmContext realmContext = serverContext.asContext(RealmContext.class);
    String realmPath = realmContext.getResolvedRealm();
    try {
        OrganizationConfigManager realmManager = new OrganizationConfigManager(getSSOToken(), realmPath);
        final ResourceResponse resource = getResource(getJsonValue(realmPath));
        realmManager.deleteSubOrganization(null, false);
        String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
        debug.message("RealmResource.deleteInstance :: DELETE of realm " + realmPath + " performed by " + principalName);
        return newResultPromise(resource);
    } catch (SMSException smse) {
        ResourceException exception = configureErrorMessage(smse);
        if (exception instanceof NotFoundException) {
            debug.warning("RealmResource.deleteInstance() : Cannot find {}", realmPath, smse);
            return exception.asPromise();
        } else if (exception instanceof ForbiddenException || exception instanceof PermanentException || exception instanceof ConflictException || exception instanceof BadRequestException) {
            debug.warning("RealmResource.deleteInstance() : Cannot DELETE {}", realmPath, smse);
            return exception.asPromise();
        } else {
            return new BadRequestException(exception.getMessage(), exception).asPromise();
        }
    } catch (Exception e) {
        return new BadRequestException(e.getMessage(), e).asPromise();
    }
}
Also used : ForbiddenException(org.forgerock.json.resource.ForbiddenException) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SMSException(com.sun.identity.sm.SMSException) ConflictException(org.forgerock.json.resource.ConflictException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) PermanentException(org.forgerock.json.resource.PermanentException) NotFoundException(org.forgerock.json.resource.NotFoundException) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) ConflictException(org.forgerock.json.resource.ConflictException) PermanentException(org.forgerock.json.resource.PermanentException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ForbiddenException(org.forgerock.json.resource.ForbiddenException) SSOException(com.iplanet.sso.SSOException) NotFoundException(org.forgerock.json.resource.NotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) BadRequestException(org.forgerock.json.resource.BadRequestException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) ResourceException(org.forgerock.json.resource.ResourceException) SessionException(com.iplanet.dpro.session.SessionException)

Example 53 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class SearchIdentities method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String type = getStringOptionValue(ARGUMENT_ID_TYPE);
    String filter = getStringOptionValue(IArgument.FILTER);
    String[] params = { realm, type, filter };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SEARCH_IDENTITIES", params);
    // test if realm exists
    try {
        new OrganizationConfigManager(adminSSOToken, realm);
    } catch (SMSException e) {
        String[] args = { realm, type, filter, e.getMessage() };
        debugError("SearchIdentities.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
        Object[] msgArg = { realm };
        throw new CLIException(MessageFormat.format(getResourceString("realm-does-not-exist"), msgArg), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    try {
        AMIdentityRepository amir = new AMIdentityRepository(adminSSOToken, realm);
        IdType idType = convert2IdType(type);
        IdSearchResults isr = amir.searchIdentities(idType, filter, new IdSearchControl());
        Set results = isr.getSearchResults();
        if ((results != null) && !results.isEmpty()) {
            if (idType.equals(IdType.USER)) {
                IdSearchResults specialUsersResults = amir.getSpecialIdentities(IdType.USER);
                results.removeAll(specialUsersResults.getSearchResults());
            }
            for (Iterator i = results.iterator(); i.hasNext(); ) {
                AMIdentity amid = (AMIdentity) i.next();
                String[] args = { amid.getName(), amid.getUniversalId() };
                outputWriter.printlnMessage(MessageFormat.format(getResourceString("format-search-identities-results"), (Object[]) args));
            }
        } else {
            outputWriter.printlnMessage(getResourceString("search-identities-no-entries"));
        }
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("search-identities-succeed"), (Object[]) params));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SEARCH_IDENTITIES", params);
    } catch (IdRepoException e) {
        String[] args = { realm, type, filter, e.getMessage() };
        debugError("SearchIdentities.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { realm, type, filter, e.getMessage() };
        debugError("SearchIdentities.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_IDENTITIES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IdSearchResults(com.sun.identity.idm.IdSearchResults) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IdType(com.sun.identity.idm.IdType) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 54 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class DeleteRealm method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    boolean recursive = isOptionSet(IArgument.RECURSIVE);
    String strRecursive = (recursive) ? "recursive" : "non recursive";
    String[] params = { realm, strRecursive };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        ocm.deleteSubOrganization(null, recursive);
        getOutputWriter().printlnMessage(getResourceString("delete-realm-succeed"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_REALM", params);
    } catch (SMSException e) {
        String[] args = { realm, strRecursive, e.getMessage() };
        debugError("DeleteRealm.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIException(com.sun.identity.cli.CLIException)

Example 55 with OrganizationConfigManager

use of com.sun.identity.sm.OrganizationConfigManager in project OpenAM by OpenRock.

the class AllowedModulesChoiceValues method getChoiceValues.

/**
     * Returns choice values from  environment parameters
     * @param envParams map of environment parameters
     * @return choice values from  environment parameters
     */
public Map getChoiceValues(Map envParams) {
    // Get default choice values
    getChoiceValues();
    Set serviceNames = null;
    String orgDN = null;
    Map registeredServices = new HashMap();
    if (envParams != null) {
        orgDN = (String) envParams.get(Constants.ORGANIZATION_NAME);
    }
    if (orgDN == null || orgDN.length() == 0) {
        orgDN = SMSEntry.getRootSuffix();
    }
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        OrganizationConfigManager orgConfig = getOrgConfigManager(orgDN, adminToken);
        serviceNames = orgConfig.getAssignedServices();
    } catch (Exception e) {
    // this Exception should have been (or will be) caught by the
    // caller of of this plugin(console). it does not worth to
    // duplicate log/debug here.
    }
    if (serviceNames != null) {
        for (Iterator ite = choiceValues.keySet().iterator(); ite.hasNext(); ) {
            String value = (String) ite.next();
            if (serviceRegistered(value, serviceNames)) {
                registeredServices.put(value, value);
            } else {
                String serviceName = AuthUtils.getModuleServiceName(value);
                try {
                    new ServiceConfigManager(serviceName, adminToken);
                } catch (SMSException e) {
                    // services don't have template.
                    registeredServices.put(value, value);
                } catch (Exception e) {
                // SSO, do nothing
                }
            }
        }
    }
    return registeredServices;
}
Also used : Set(java.util.Set) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) SMSException(com.sun.identity.sm.SMSException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)144 SMSException (com.sun.identity.sm.SMSException)87 Set (java.util.Set)79 HashSet (java.util.HashSet)54 SSOException (com.iplanet.sso.SSOException)50 Map (java.util.Map)48 HashMap (java.util.HashMap)40 SSOToken (com.iplanet.sso.SSOToken)33 IdRepoException (com.sun.identity.idm.IdRepoException)32 Iterator (java.util.Iterator)28 AMIdentity (com.sun.identity.idm.AMIdentity)23 CLIException (com.sun.identity.cli.CLIException)21 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)20 ServiceConfig (com.sun.identity.sm.ServiceConfig)17 IOutput (com.sun.identity.cli.IOutput)15 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)15 List (java.util.List)10 ForbiddenException (org.forgerock.json.resource.ForbiddenException)9 BadRequestException (org.forgerock.json.resource.BadRequestException)8 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)8