Search in sources :

Example 26 with ServiceConfigManager

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

the class UmaEmailService method getMailServer.

private MailServer getMailServer(String realm) throws MessagingException {
    try {
        ServiceConfigManager mailmgr = new ServiceConfigManager(AccessController.doPrivileged(AdminTokenAction.getInstance()), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
        ServiceConfig mailscm = mailmgr.getOrganizationConfig(realm, null);
        if (!mailscm.exists()) {
            throw new MessagingException("EmailService is not configured for realm, " + realm);
        }
        Map<String, Set<String>> mailattrs = mailscm.getAttributes();
        String mailServerClass = mailattrs.get("forgerockMailServerImplClassName").iterator().next();
        return Class.forName(mailServerClass).asSubclass(MailServer.class).getDeclaredConstructor(String.class).newInstance(realm);
    } catch (IllegalAccessException | SSOException | InstantiationException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException | SMSException e) {
        throw new MessagingException("Failed to load mail server", e);
    }
}
Also used : Set(java.util.Set) MessagingException(javax.mail.MessagingException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 27 with ServiceConfigManager

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

the class AMAuthConfigUtils method removeNamedConfig.

/**
     * Removes an authentication configuration defined in 
     * <code>iPlanetAMAuthConfiguration</code> service. This method will be
     * used by console to manage configurations for different services.
     *
     * @param configName Name of the authentication configuration.
     * @param orgName Organization DN.
     * @param token Single Sign On token.
     * @throws SMSException if failed to delete the configuration because
     *         of SM Exception.
     * @throws SSOException if single sign on token is not valid.
     * @throws AMConfigurationException if <code>configName</code> is null
     *         or not defined .
     */
public static void removeNamedConfig(String configName, String orgName, SSOToken token) throws SMSException, SSOException, AMConfigurationException {
    if (debug.messageEnabled()) {
        debug.message("removeNamedConfig name=" + configName + ",org=" + orgName);
    }
    // Check if name is valid
    if (configName == null) {
        throw new AMConfigurationException(bundleName, "null-name");
    }
    // Get service config for named config node
    ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, token);
    ServiceConfig oConfig = scm.getOrganizationConfig(orgName, null);
    if (oConfig == null) {
        // service not registered
        throw new AMConfigurationException(bundleName, "service-not-registered");
    }
    ServiceConfig namedConfig = oConfig.getSubConfig(NAMED_CONFIGURATION);
    if (namedConfig == null) {
        // named configuration not exists
        throw new AMConfigurationException(bundleName, "named-config-not-defined");
    }
    // get the  config 
    ServiceConfig pConfig = namedConfig.getSubConfig(configName);
    if (pConfig == null) {
        // configuration does not exist
        throw new AMConfigurationException(bundleName, "config-not-exists");
    }
    // do the removal of config 
    namedConfig.removeSubConfig(configName);
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 28 with ServiceConfigManager

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

the class AMAuthConfigUtils method getAllNamedConfig.

/**
     * Returns all the authentication configurations defined in
     * <code>iPlanetAMAuthConfiguration</code> service. This method will be
     * used by console to manage configurations for different services.
     *
     * @param orgName Organization DN.
     * @param token Single Sign On token.
     * @return Set which contains all the configuration names 
     * @throws SMSException if failed to get configurations because
     *         of SM Exception.
     * @throws SSOException if single sign on token is not valid.
     */
public static Set getAllNamedConfig(String orgName, SSOToken token) throws SMSException, SSOException {
    if ((orgName != null) && (orgName.length() != 0)) {
        orgName = orgName.toLowerCase();
    }
    if (debug.messageEnabled()) {
        debug.message("getAllNamedConfig org=" + orgName);
    }
    // Get the named config node
    ServiceConfigManager scm = new ServiceConfigManager(token, SERVICE_NAME, SERVICE_VERSION);
    ServiceConfig oConfig = scm.getOrganizationConfig(orgName, null);
    if (oConfig == null) {
        // service not registered
        return Collections.EMPTY_SET;
    }
    ServiceConfig namedConfig = oConfig.getSubConfig(NAMED_CONFIGURATION);
    if (namedConfig == null) {
        // named configuration not exists 
        return Collections.EMPTY_SET;
    }
    // get all sub config names
    return namedConfig.getSubConfigNames("*");
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 29 with ServiceConfigManager

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

the class EntitiesModelImpl method repoExists.

public boolean repoExists(String realmName) {
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, getUserSSOToken());
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realmName, null);
        if (cfg == null) {
            return false;
        }
        Set names = cfg.getSubConfigNames();
        if (names == null || names.isEmpty()) {
            return false;
        }
        return true;
    } catch (SMSException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realmName, strError };
        logEvent("SMS_EXCEPTION_GET_ID_REPO_NAMES", paramsEx);
        return false;
    } catch (SSOException e) {
        String strError = getErrorString(e);
        String[] paramsEx = { realmName, strError };
        logEvent("SSO_EXCEPTION_GET_ID_REPO_NAMES", paramsEx);
        return false;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 30 with ServiceConfigManager

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

the class AMServiceUtils method getOrgConfig.

/**
     * Get organization config for the service
     * 
     * @param token
     *            SSOToken
     * @param orgDN
     *            DN of the org or org unit
     * @param serviceName
     *            Service Name
     * @return ServiceConfig of the organization for the service
     */
public static ServiceConfig getOrgConfig(SSOToken token, String orgDN, String serviceName) throws SSOException, AMException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, token);
        ServiceConfig sc = scm.getOrganizationConfig(orgDN, null);
        DN theOrgDN = DN.valueOf(orgDN);
        if (theOrgDN.equals(DN.valueOf(SMSEntry.getAMSdkBaseDN())) && sc != null) {
            Map avPair = sc.getAttributes();
            Set subConfigs = sc.getSubConfigNames();
            if (avPair.isEmpty() && (subConfigs == null || subConfigs.isEmpty())) {
                return null;
            }
        }
        return sc;
    } catch (ServiceNotFoundException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("481", args, locale), "481", args);
    } catch (ServiceAlreadyExistsException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("479", args, locale), "479", args);
    } catch (SMSException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("482", args, locale), "482", args);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) DN(org.forgerock.opendj.ldap.DN) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

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