Search in sources :

Example 81 with ServiceConfigManager

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

the class ISResourceBundle method getResourceBundleFromDirectory.

private static ResourceBundle getResourceBundleFromDirectory(SSOToken token, String rbName, String locale) throws SSOException {
    // in the local file system, we look it up in the directory.
    if (debug.messageEnabled()) {
        debug.message("ISResourceBundle.get-> Unable to find RB in" + " local path. looking in the directory: " + rbName);
    }
    String language = null;
    try {
        ServiceConfigManager scm = new ServiceConfigManager(token, LOCALE_SERVICE, VERSION);
        ServiceConfig globalConfig = scm.getGlobalConfig(null);
        if (globalConfig == null) {
            // throw MissingResourceException
            throw new MissingResourceException("Unable to find " + "LocaleService", "com.sun.identity.common.ISResourceBundle", "all");
        }
        // Check to see if rb subconfig exists
        ServiceConfig rbConfig = globalConfig.getSubConfig(rbName);
        if (rbConfig == null) {
            throw new MissingResourceException("Unable to find " + "ResourceBundle: " + rbName, "com.sun.identity.common.ISResourceBundle", "all");
        }
        if (locale == null) {
            // Get the default set of key-values
            Map attrs = rbConfig.getAttributes();
            return new ISResourceBundle(attrs);
        } else {
            StringTokenizer tzer = new StringTokenizer(locale, "_");
            language = tzer.nextToken();
        }
        ServiceConfig localeConfig = rbConfig.getSubConfig(locale);
        if (localeConfig == null) {
            // look for language specific RB
            localeConfig = rbConfig.getSubConfig(language);
        }
        if (localeConfig == null) {
            // look for generic RB
            Map attrs = rbConfig.getAttributes();
            return new ISResourceBundle(attrs);
        } else {
            Map attrs = localeConfig.getAttributes();
            return new ISResourceBundle(attrs);
        }
    } catch (SMSException se) {
        // log a debug exceptipn
        throw new MissingResourceException(_bundle.getString("isResourceBundleMsg0") + rbName, _bundle.getString("isResourceBundleMsg2"), _bundle.getString("isResourceBundleMsg3"));
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) MissingResourceException(java.util.MissingResourceException) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 82 with ServiceConfigManager

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

the class ISResourceBundle method deleteResourceBundle.

/**
     * Deletes the specified ResourceBundle from the directory.
     * 
     * @param token
     *            Single sign-on token of user
     * @param rbName
     *            Name of ResourceBundle
     * @param locale
     *            String defining the locale. If null, then all the locales of
     *            this ResourceBundle, including the default one, are deleted.
     * @throws SMSException
     *             If there is an error trying to modify the datastore
     * @throws SSOException
     *             If this user's token has expired.
     */
public static void deleteResourceBundle(SSOToken token, String rbName, String locale) throws SMSException, SSOException {
    if (rbName == null) {
        return;
    }
    ServiceConfigManager scm = new ServiceConfigManager(token, LOCALE_SERVICE, VERSION);
    ServiceConfig globalConfig = scm.getGlobalConfig(null);
    if (locale == null) {
        // Delete the entire ResourceBundle tree
        try {
            globalConfig.removeSubConfig(rbName);
        } catch (SMSException se) {
            throw new MissingResourceException(_bundle.getString("isResourceBundleMsg1") + rbName + ". " + se.getMessage(), _bundle.getString("isResourceBundleMsg2"), _bundle.getString("isResourceBundleMsg3"));
        }
    } else {
        ServiceConfig rbConfig = globalConfig.getSubConfig(rbName);
        if (rbConfig == null) {
            // the resource bundle provided.
            throw new MissingResourceException(_bundle.getString("isResourceBundleMsg0") + rbName + ". ", _bundle.getString("isResourceBundleMsg2"), _bundle.getString("isResourceBundleMsg3"));
        } else {
            rbConfig.removeSubConfig(locale);
        }
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) MissingResourceException(java.util.MissingResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 83 with ServiceConfigManager

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

the class AdminInterfaceUtils method initialize.

/**
     * Initializes the default containers using SMS
     */
private static void initialize() {
    if (!initialized) {
        try {
            // Generate a SSOToken to initialize ServiceSchemaManager
            String adminDN = (String) AccessController.doPrivileged(new AdminDNAction());
            String adminPassword = (String) AccessController.doPrivileged(new AdminPasswordAction());
            SSOTokenManager mgr = SSOTokenManager.getInstance();
            ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, mgr.createSSOToken(new AuthPrincipal(adminDN), adminPassword));
            if (!addedListener) {
                addedListener = true;
                scm.addListener(new AdminInterfaceUtils());
            }
            ServiceConfig globalConfig = scm.getGlobalConfig(null);
            ServiceConfig templatesConfig = globalConfig.getSubConfig(TEMPLATES);
            ServiceConfig structTemplateSubConfig = templatesConfig.getSubConfig(STRUCTURE_TEMPLATES);
            ServiceConfig groupContConfig = structTemplateSubConfig.getSubConfig(GCCREATE_ATTR_NAME);
            ServiceConfig peopleContConfig = structTemplateSubConfig.getSubConfig(PCCREATE_ATTR_NAME);
            ServiceConfig orgAdminConfig = structTemplateSubConfig.getSubConfig(ORG_ADMIN_ATTR_NAME);
            ServiceConfig helpDeskAdminConfig = structTemplateSubConfig.getSubConfig(HELP_DESK_ADMIN_ATTR_NAME);
            ServiceConfig policyAdminConfig = structTemplateSubConfig.getSubConfig(POLICY_ADMIN_ATTR_NAME);
            defaultGCCreateDuringOrgConfig = getConfigAttributeValue(groupContConfig, defaultGCCreateDuringOrgConfig);
            defaultPCCreateDuringOrgConfig = getConfigAttributeValue(peopleContConfig, defaultPCCreateDuringOrgConfig);
            defaultORGADMIN = getConfigAttributeValue(orgAdminConfig, defaultORGADMIN);
            defaultHELP_DESK_ADMIN = getConfigAttributeValue(helpDeskAdminConfig, defaultHELP_DESK_ADMIN);
            defaultPOLICY_ADMIN = getConfigAttributeValue(policyAdminConfig, defaultPOLICY_ADMIN);
            ServiceSchemaManager sm = new ServiceSchemaManager(CONSOLE_SERVICE_NAME, mgr.createSSOToken(new AuthPrincipal(adminDN), adminPassword));
            if (!addedListener) {
                addedListener = true;
                sm.addListener(new AdminInterfaceUtils());
            }
            ServiceSchema schema = sm.getGlobalSchema();
            defaultAC = getAttributeValue(schema, AC_ATTR_NAME, defaultAC);
            defaultGC = getAttributeValue(schema, GC_ATTR_NAME, defaultGC);
            defaultPC = getAttributeValue(schema, PC_ATTR_NAME, defaultPC);
        } catch (Exception e) {
            // Use the default values, and write out debug warning msg
            debug.warning("AdminInterfaceUtils: Unable to get " + "default People, Groups, Org Admin Role, " + "Help Desk Admin Role, Policy Admin Role and " + "Agents containers from SM", e);
        }
        if (debug.messageEnabled()) {
            debug.message("AdminInterfaceUtils: Defaults container: " + defaultPC + ", " + defaultGC + ", " + defaultAC + ", " + defaultPCCreateDuringOrgConfig + ", " + defaultGCCreateDuringOrgConfig + ", " + defaultORGADMIN + ", " + defaultHELP_DESK_ADMIN + ", " + defaultPOLICY_ADMIN);
        }
        initialized = true;
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) ServiceSchema(com.sun.identity.sm.ServiceSchema) AdminDNAction(com.sun.identity.security.AdminDNAction) AdminPasswordAction(com.sun.identity.security.AdminPasswordAction) ServiceConfig(com.sun.identity.sm.ServiceConfig) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) SMSException(com.sun.identity.sm.SMSException) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException)

Example 84 with ServiceConfigManager

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

the class ISResourceBundle method storeResourceBundle.

/**
     * Stores or creates the ResourceBundle in the directory.
     * 
     * @param token
     *            Single sign-on token of user
     * @param rbName
     *            Name of ResourceBundle
     * @param locale
     *            Locale of ResourceBundle. If null, the default ResourceBundle
     *            is updated.
     * @param attributes
     *            Map of key-value pairs defining the ResourceBundle.
     * @throws SMSException
     *             If there is an error trying to modify the datastore
     * @throws SSOException
     *             If this user's token has expired.
     */
public static void storeResourceBundle(SSOToken token, String rbName, String locale, Map attributes) throws SMSException, SSOException {
    if (rbName == null) {
        return;
    }
    ServiceConfigManager scm = new ServiceConfigManager(token, LOCALE_SERVICE, VERSION);
    ServiceConfig globalConfig = scm.getGlobalConfig(null);
    ServiceConfig rbConfig = globalConfig.getSubConfig(rbName);
    if (rbConfig == null) {
        // create a sub config
        globalConfig.addSubConfig(rbName, RB_CONFIG_ID, 0, new HashMap());
        rbConfig = globalConfig.getSubConfig(rbName);
    }
    if (locale == null) {
        // store these as defaults
        rbConfig.setAttributes(attributes);
    } else {
        // get/create locale subconfig and set these attributes
        ServiceConfig localeConfig = rbConfig.getSubConfig(locale);
        if (localeConfig == null) {
            rbConfig.addSubConfig(locale, LOCALE_CONFIG_ID, 0, attributes);
            localeConfig = rbConfig.getSubConfig(locale);
        } else {
            localeConfig.setAttributes(attributes);
        }
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 85 with ServiceConfigManager

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

the class DelegationUtils method getPrivilegeConfig.

/**
     * Returns service config information for a delegation privilege
     * @param orgName name of the organization whose organization config
     *        is searched.
     * @param name name of the delegation privilege whose information is
              sought.
     * @param global <code>boolean</code> indicating if global config
     *        of the delegation service is expected.
     *
     * @return <code>ServiceConfig</code> information for a delegation privilege
     */
static ServiceConfig getPrivilegeConfig(String orgName, String name, boolean global) throws SSOException, DelegationException {
    ServiceConfig orgConfig = null;
    ServiceConfig privsConfig = null;
    ServiceConfig priv = null;
    try {
        // get the service configuration manager of the
        // delegation service
        ServiceConfigManager scm = new ServiceConfigManager(DelegationManager.DELEGATION_SERVICE, DelegationManager.getAdminToken());
        // get the organization configuration of this realm
        if (global) {
            orgConfig = scm.getGlobalConfig(null);
        } else {
            orgConfig = scm.getOrganizationConfig(orgName, null);
        }
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_org_config_failed", null, se);
    }
    if (orgConfig == null) {
        throw new DelegationException(ResBundleUtils.rbName, "get_privs_config_failed", null, null);
    }
    try {
        // get the sub configuration "Privileges"
        privsConfig = orgConfig.getSubConfig(DelegationManager.PRIVILEGES);
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_privs_config_failed", null, se);
    }
    try {
        // get the sub configuration for the defined privilege
        priv = privsConfig.getSubConfig(name);
    } catch (SMSException se) {
        throw new DelegationException(ResBundleUtils.rbName, "get_privilege_config_failed", null, se);
    }
    return (priv);
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) 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