Search in sources :

Example 11 with ServiceConfigManager

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

the class UpgradeOAuth2AuthModulesStep method perform.

@Override
public void perform() throws UpgradeException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, getAdminToken());
        for (Map.Entry<String, Set<String>> realm : affectedRealms.entrySet()) {
            ServiceConfig realmConfig = scm.getOrganizationConfig(realm.getKey(), null);
            for (String moduleName : realm.getValue()) {
                ServiceConfig moduleConfig = realmConfig.getSubConfig(moduleName);
                Map<String, Set<?>> attributes = getAttributes(moduleConfig);
                if (attributes.get(ACCOUNT_MAPPER_PROPERTY).contains(DEFAULT_ACCOUNT_MAPPER)) {
                    moduleConfig.replaceAttributeValues(ACCOUNT_MAPPER_PROPERTY, asSet(DEFAULT_ACCOUNT_MAPPER), asSet(JSON_MAPPER));
                }
                if (attributes.get(ATTRIBUTE_MAPPER_PROPERTY).contains(DEFAULT_ATTRIBUTE_MAPPER)) {
                    moduleConfig.replaceAttributeValues(ATTRIBUTE_MAPPER_PROPERTY, asSet(DEFAULT_ATTRIBUTE_MAPPER), asSet(JSON_MAPPER));
                }
                moduleCount++;
            }
        }
    } catch (Exception ex) {
        DEBUG.error("An error occurred while trying to update OAuth2 auth modules", ex);
        throw new UpgradeException("Unable to update OAuth2 modules", ex);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

Example 12 with ServiceConfigManager

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

the class UpgradeOAuth2ClientStep method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(IdConstants.AGENT_SERVICE, getAdminToken());
        for (String realm : getRealmNames()) {
            findUpgradableConfigs(realm, scm, AgentType.AGENT);
            findUpgradableConfigs(realm, scm, AgentType.GROUP);
        }
    } catch (Exception ex) {
        DEBUG.error("An error occurred while trying to look for upgradable OAuth2 client profiles", ex);
        throw new UpgradeException("Unable to retrieve modified OAuth2 clients");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 13 with ServiceConfigManager

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

the class DataStore method getIndexCount.

private static int getIndexCount(String realm, boolean referral) {
    int count = 0;
    if (adminToken != null) {
        try {
            ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, adminToken);
            ServiceConfig orgConf = mgr.getOrganizationConfig(realm, null);
            if (orgConf != null) {
                Map<String, Set<String>> map = orgConf.getAttributes();
                Set<String> set = (referral) ? map.get(REFERRAL_INDEX_COUNT) : map.get(INDEX_COUNT);
                if ((set != null) && !set.isEmpty()) {
                    String strCount = (String) set.iterator().next();
                    count = Integer.parseInt(strCount);
                }
            }
        } catch (NumberFormatException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        } catch (SMSException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        } catch (SSOException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        }
    }
    return count;
}
Also used : HashSet(java.util.HashSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 14 with ServiceConfigManager

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

the class DataStore method getOrgConfig.

private ServiceConfig getOrgConfig(SSOToken adminToken, String realm) throws SMSException, SSOException {
    ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, adminToken);
    ServiceConfig orgConf = mgr.getOrganizationConfig(realm, null);
    if (orgConf == null) {
        mgr.createOrganizationConfig(realm, null);
    }
    return orgConf;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 15 with ServiceConfigManager

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

the class EntitlementService method getApplicationConfiguration.

/**
     * Get the service config for registered applications.
     * @param token The admin token for access to the Service Config.
     * @param realm The realm from which to retrieve the service config.
     * @return The application Service Config.
     */
private ServiceConfig getApplicationConfiguration(SSOToken token, String realm) {
    try {
        if (token != null) {
            if (realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX) || realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX2)) {
                realm = "/";
            }
            // TODO. Since applications for the hidden realms have to be
            // the same as root realm mainly for delegation without any
            // referrals, the hack is to use root realm for hidden realm.
            String hackRealm = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
            ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, token);
            ServiceConfig orgConfig = mgr.getOrganizationConfig(hackRealm, null);
            if (orgConfig != null) {
                return orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
            }
        } else {
            PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration, admin token is missing");
        }
    } catch (ClassCastException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    }
    return null;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)163 ServiceConfig (com.sun.identity.sm.ServiceConfig)123 SMSException (com.sun.identity.sm.SMSException)116 SSOException (com.iplanet.sso.SSOException)107 SSOToken (com.iplanet.sso.SSOToken)53 Set (java.util.Set)50 Map (java.util.Map)31 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)28 CLIException (com.sun.identity.cli.CLIException)17 Iterator (java.util.Iterator)16 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)15 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)12 ByteString (org.forgerock.opendj.ldap.ByteString)12 JsonValue (org.forgerock.json.JsonValue)10 IOException (java.io.IOException)9 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)9 IOutput (com.sun.identity.cli.IOutput)8 PolicyException (com.sun.identity.policy.PolicyException)7