Search in sources :

Example 81 with OrganizationConfigManager

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

the class RealmTest method setRealmAttributeValues.

@Parameters({ "realm" })
@Test(groups = { "cli-realm", "set-realm-attrs" }, dependsOnMethods = { "removeRealmAttribute" })
public void setRealmAttributeValues(String realm) throws CLIException, SMSException, SSOException {
    String[] param = { realm };
    entering("setRealmAttributeValues", param);
    String[] args = { "set-realm-attrs", CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.REALM_NAME, realm, CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.SERVICE_NAME, "sunIdentityRepositoryService", CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.ATTRIBUTE_VALUES, "sunOrganizationStatus=Active" };
    CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
    cmdManager.addToRequestQueue(req);
    cmdManager.serviceRequestQueue();
    OrganizationConfigManager ocm = new OrganizationConfigManager(getAdminSSOToken(), realm);
    Map values = ocm.getAttributes("sunIdentityRepositoryService");
    Set attrValues = (Set) values.get("sunOrganizationStatus");
    assert attrValues.contains("Active");
    exiting("setRealmAttributeValues");
}
Also used : Set(java.util.Set) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIRequest(com.sun.identity.cli.CLIRequest) HashMap(java.util.HashMap) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 82 with OrganizationConfigManager

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

the class RealmTest method removeRealmAttribute.

@Parameters({ "realm" })
@Test(groups = { "cli-realm", "delete-realm-attr" })
public void removeRealmAttribute(String realm) throws CLIException, SMSException, SSOException {
    String[] param = { realm };
    entering("removeRealmAttribute", param);
    String[] args = { "delete-realm-attr", CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.REALM_NAME, realm, CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.SERVICE_NAME, "sunIdentityRepositoryService", CLIConstants.PREFIX_ARGUMENT_LONG + IArgument.ATTRIBUTE_NAME, "sunOrganizationStatus" };
    CLIRequest req = new CLIRequest(null, args, getAdminSSOToken());
    cmdManager.addToRequestQueue(req);
    cmdManager.serviceRequestQueue();
    OrganizationConfigManager ocm = new OrganizationConfigManager(getAdminSSOToken(), realm);
    Map values = ocm.getAttributes("sunIdentityRepositoryService");
    Set attrValues = (Set) values.get("sunOrganizationStatus");
    assert (attrValues == null);
    exiting("removeRealmAttribute");
}
Also used : Set(java.util.Set) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) CLIRequest(com.sun.identity.cli.CLIRequest) HashMap(java.util.HashMap) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 83 with OrganizationConfigManager

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

the class UpgradeIdRepoSubConfigs method perform.

@Override
public void perform() throws UpgradeException {
    for (Map.Entry<String, Set<String>> entry : repos.entrySet()) {
        try {
            String realm = entry.getKey();
            OrganizationConfigManager ocm = new OrganizationConfigManager(getAdminToken(), realm);
            for (String subConfig : entry.getValue()) {
                UpgradeProgress.reportStart("upgrade.data.store.start", subConfig);
                Map<String, Set<String>> newValues = new HashMap<String, Set<String>>(2);
                ServiceConfig sc = ocm.getServiceConfig(IdConstants.REPO_SERVICE);
                ServiceConfig repoConfig = sc.getSubConfig(subConfig);
                Map<String, Set<String>> attributes = repoConfig.getAttributes();
                String className = CollectionHelper.getMapAttr(attributes, IdConstants.ID_REPO);
                if (OLD_IDREPO_CLASS.equals(className)) {
                    newValues.put(IdConstants.ID_REPO, asSet(NEW_IDREPO_CLASS));
                }
                String newFilter = getModifiedFilter(attributes);
                if (newFilter != null) {
                    if (DEBUG.messageEnabled()) {
                        DEBUG.message("Upgrading psearch filter for datastore: " + subConfig + " to: " + newFilter);
                    }
                    newValues.put(PSEARCH_FILTER, asSet(newFilter));
                }
                Map<String, String> sslModes = oldConnectionModeRepos.get(realm);
                String sslMode = (sslModes == null) ? null : sslModes.get(subConfig);
                if (sslMode != null) {
                    if (DEBUG.messageEnabled()) {
                        DEBUG.message("Upgrading connection mode for datastore: " + subConfig + " to: " + sslMode);
                    }
                    newValues.put(NEW_CONNECTION_MODE, asSet(sslMode));
                }
                //There is no need to remove the obsolete attributes here, because once we set an attribute, the SMS
                //framework will automagically remove those that do not adhere to the schema.
                repoConfig.setAttributes(newValues);
                UpgradeProgress.reportEnd("upgrade.success");
            }
        } catch (Exception ex) {
            UpgradeProgress.reportEnd("upgrade.failed");
            DEBUG.error("An error occurred while upgrading service config ", ex);
            throw new UpgradeException("Unable to upgrade IdRepo configuration");
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ServiceConfig(com.sun.identity.sm.ServiceConfig) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) HashMap(java.util.HashMap) Map(java.util.Map) UpgradeException(org.forgerock.openam.upgrade.UpgradeException)

Example 84 with OrganizationConfigManager

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

the class ConfigFedMonitoring method getRealmsList.

/*
     *  get the list of realms, starting from "startRealm", usu. "/".
     *  return List with realms, with leading "/".
     */
private List getRealmsList(String startRealm) {
    String classMethod = "ConfigFedMonitoring.getRealmsList: ";
    try {
        // for startRealm
        int rlmCnt = 1;
        OrganizationConfigManager orgMgr = new OrganizationConfigManager(ssoToken, startRealm);
        Set orgs = orgMgr.getSubOrganizationNames("*", true);
        rlmCnt += orgs.size();
        realmList = new ArrayList(rlmCnt);
        realmList.add(startRealm);
        for (Iterator it = orgs.iterator(); it.hasNext(); ) {
            String ss = "/" + (String) it.next();
            realmList.add(ss);
        }
        return (realmList);
    } catch (SMSException e) {
        debug.error(classMethod + "SMSException getting OrgConfigMgr: " + e.getMessage());
    }
    return (new ArrayList());
}
Also used : Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 85 with OrganizationConfigManager

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

the class ConfigureSocialAuthN method createOrModifySocialService.

/**
     * Create a social service given the attributes specified.
     * @param realm The realm/organisation
     * @param chainName
     * @param providerName
     * @param icon
     * @throws WorkflowException if there are problems modifying or assigning the service.
     */
private void createOrModifySocialService(String realm, String chainName, String providerName, String icon) throws WorkflowException {
    try {
        SSOToken token = getAdminToken();
        OrganizationConfigManager ocm = new OrganizationConfigManager(token, realm);
        Map<String, Set<String>> attrs = new HashMap<String, Set<String>>(4);
        String prefix = "[" + providerName + "]=";
        attrs.put(SERVICE_DISPLAY_NAME, asSet(prefix + providerName));
        attrs.put(SERVICE_CHAIN_NAME, asSet(prefix + chainName));
        attrs.put(SERVICE_ICON, asSet(prefix + icon));
        attrs.put(SERVICE_ENABLED, asSet(providerName));
        if (ocm.getAssignedServices().contains(SERVICE_NAME)) {
            ServiceConfig serviceConfig = ocm.getServiceConfig(SERVICE_NAME);
            serviceConfig.setAttributes(mergeAttributes(serviceConfig.getAttributesWithoutDefaults(), attrs));
        } else {
            ocm.assignService(SERVICE_NAME, attrs);
        }
    } catch (SMSException smse) {
        DEBUG.error("An error occurred while creating/modifying social authentication service", smse);
        throw new WorkflowException("social-service-error", null);
    } catch (SSOException ssoe) {
        DEBUG.warning("A session error occurred while creating/modifying social authentication service", ssoe);
        throw new WorkflowException("social-service-error", null);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) Set(java.util.Set) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) SSOException(com.iplanet.sso.SSOException)

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