Search in sources :

Example 31 with ServiceConfigManager

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

the class CoreTokenConfigService method initServiceConfig.

private synchronized void initServiceConfig() {
    try {
        SSOToken dsameUserToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        ServiceConfigManager mgr = new ServiceConfigManager(CoreTokenConstants.CORE_TOKEN_CONFIG_SERVICE_NAME, dsameUserToken);
        ServiceConfig globalConf = mgr.getGlobalConfig(null);
        if (globalConf != null) {
            Map<String, Set<String>> map = globalConf.getAttributes();
            if (map != null) {
                Set<String> set = map.get(IMPL_CLASS_ATTR);
                if ((set != null) && !set.isEmpty()) {
                    implClassName = set.iterator().next();
                }
                set = map.get(SEARCHABLE_ATTR);
                Set<String> tmpSet = new HashSet<String>();
                if ((set != null) && !set.isEmpty()) {
                    Iterator<String> it = set.iterator();
                    while (it.hasNext()) {
                        tmpSet.add(it.next().toLowerCase());
                    }
                }
                searchableAttrs = tmpSet;
                set = map.get(CLEANUP_INTERVAL);
                if ((set != null) && !set.isEmpty()) {
                    String tmp = set.iterator().next();
                    try {
                        cleanupInt = Integer.parseInt(tmp) * 1000;
                    } catch (NumberFormatException ne) {
                        CoreTokenUtils.debug.error("CoreTokenConfigService" + ".init. invalid interval : " + tmp, ne);
                        cleanupInt = DEFAULT_CLEANUP_INTERVAL;
                    }
                }
                set = map.get(TYPES_WITHOUT_ETAG_ENFORCE);
                tmpSet = new HashSet<String>();
                if ((set != null) && !set.isEmpty()) {
                    Iterator<String> it = set.iterator();
                    while (it.hasNext()) {
                        tmpSet.add(it.next().toLowerCase());
                    }
                }
                noETagEnfTypes = tmpSet;
            }
        }
        if (CoreTokenUtils.debug.messageEnabled()) {
            CoreTokenUtils.debug.message("CoreTokenConfigServcie.init: " + "searchable Attrs=" + searchableAttrs + "; token store impl class=" + implClassName + "; cleanup interval=" + cleanupInt + "; token types without ETag enforcement=" + noETagEnfTypes);
        }
    } catch (SMSException ex) {
        CoreTokenUtils.debug.error("CoreTokenConfigService.init", ex);
    } catch (SSOException ex) {
        CoreTokenUtils.debug.error("CoreTokenConfigService.init", ex);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) HashSet(java.util.HashSet)

Example 32 with ServiceConfigManager

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

the class IdRepoUtils method loadIdRepoSchema.

/**
     * Loads schema to specified IdRepo.
     * 
     * @param ssoToken single sign on token of authenticated user identity
     * @param idRepoName IdRepo name
     * @param realm the realm
     * @param servletCtx the servlet context
     *
     * @throws IdRepoException If schema can't be loaded or there are
     *     repository related error conditions.
     */
public static void loadIdRepoSchema(SSOToken ssoToken, String idRepoName, String realm, ServletContext servletCtx) throws IdRepoException {
    if (servletCtx == null) {
        return;
    }
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, ssoToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        ServiceConfig ss = cfg.getSubConfig(idRepoName);
        if (ss == null) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdRepoUtils.loadIdRepoSchema: data store " + idRepoName + " for realm " + realm + " doesn't exist.");
            }
            Object[] args = { idRepoName, realm };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_DOESNT_EXIST_FOR_REALM, args);
        }
        String idRepoType = ss.getSchemaID();
        Map attrValues = ss.getAttributes();
        String schemaFiles = getSchemaFiles(idRepoType);
        if ((schemaFiles == null) || (schemaFiles.trim().length() == 0)) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdRepoUtils.loadIdRepoSchema: data store " + idRepoName + " for realm " + realm + " doesn't have " + "schema files.");
            }
            return;
        }
        StringTokenizer st = new StringTokenizer(schemaFiles);
        while (st.hasMoreTokens()) {
            String schemaFile = st.nextToken();
            tagSwapAndImportSchema(schemaFile, attrValues, servletCtx, idRepoType);
        }
    } catch (SMSException smsex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", smsex);
        }
        Object[] args = { idRepoName, realm };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_READ_PLUGIN_FOR_REALM, args);
    } catch (SSOException ssoex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", ssoex);
        }
        Object[] args = { idRepoName, realm };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_READ_PLUGING_FOR_REALM_SSOTOKEN_NOT_VALID, args);
    } catch (Exception ex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", ex);
        }
        Object[] args = { idRepoName, realm, ex.getMessage() };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_LOAD_SCHEMA_FOR_PLUGIN_FOR_REALM, args);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 33 with ServiceConfigManager

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

the class IdRepoPluginsCache method initializeListeners.

protected void initializeListeners() {
    synchronized (debug) {
        if (!initializedListeners) {
            // Add listeners to Service Schema and Config Managers
            if (debug.messageEnabled()) {
                debug.message("IdRepoPluginsCache.initializeListeners: " + "setting up ServiceListener");
            }
            SSOToken token = getAdminToken();
            try {
                // Initialize configuration objects
                idRepoServiceConfigManager = new ServiceConfigManager(token, IdConstants.REPO_SERVICE, "1.0");
                idRepoServiceConfigManager.addListener(this);
                // Initialize schema objects
                ServiceSchemaManager idRepoServiceSchemaManager = new ServiceSchemaManager(token, IdConstants.REPO_SERVICE, "1.0");
                idRepoServiceSchemaManager.addListener(this);
                // Get the version number
                svcRevisionNumber = idRepoServiceSchemaManager.getRevisionNumber();
                // Initialize listener for JAXRPCObject
                IdRepoListener.addRemoteListener(new JAXRPCObjectImplEventListener());
                initializedListeners = true;
            } catch (SMSException smse) {
                // Exceptions will be throws during install and config
                // when these services will not be loaded
                String installTime = SystemProperties.get(Constants.SYS_PROPERTY_INSTALL_TIME, "false");
                if (!installTime.equals("true")) {
                    debug.error("IdRepoPluginsCache.initializeListeners: " + "Unable to set up a service listener for IdRepo", smse);
                }
            } catch (SSOException ssoe) {
                debug.error("IdRepoPluginsCache.initializeListeners: " + "Unable to set up a service listener for IdRepo.", ssoe);
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 34 with ServiceConfigManager

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

the class AgentIdentityImpl method getAgentServiceConfig.

private ServiceConfig getAgentServiceConfig(SSOToken token) {
    AMIdentity identity;
    try {
        identity = IdUtils.getIdentity(token);
    } catch (IdRepoException | SSOException e) {
        debug.error("Exception while obtaining identity corresponding to SSOToken: {}", e, e);
        return null;
    }
    // before instantiating a ServiceConfigManager.
    if (!IdType.AGENT.equals(identity.getType())) {
        debug.message("Not an agent");
        return null;
    }
    ServiceConfig agentService;
    try {
        agentService = new ServiceConfigManager(AGENT_SERVICE_NAME, getAdminToken()).getOrganizationConfig(identity.getRealm(), null);
    } catch (Exception e) {
        debug.error("Exception while obtaining base AgentService ServiceConfig instance: {}", e, e);
        return null;
    }
    try {
        return agentService.getSubConfig(identity.getName());
    } catch (SSOException | SMSException e) {
        // Should only enter this block if the return from getAdminToken is an invalid token
        // or if an error occurs accessing LDAP.
        debug.error("Exception while obtaining AgentService SubConfig {}: {}", identity.getName(), e, e);
        return null;
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 35 with ServiceConfigManager

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

the class UpgradeUtils method createOrganizationConfiguration.

/**
     * Creates <code>OrganizationConfiguration</code> in a service.
     *
     * @param serviceName name of the service
     * @param orgName name of the organization
     * @param attrValues map of attribute names and their values. The
     *        key is the attribute name a string and the values is a Set
     *        of values.
     */
public static void createOrganizationConfiguration(String serviceName, String orgName, Map attrValues) {
    String classMethod = "UpgradeUtils:createOrganizationConfiguration: ";
    try {
        ServiceConfigManager sm = getServiceConfigManager(serviceName);
        sm.createOrganizationConfig(orgName, attrValues);
    } catch (Exception e) {
        debug.error(classMethod + "Error creating organization " + "configuration for " + serviceName, e);
    }
}
Also used : ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

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