Search in sources :

Example 21 with ServiceConfigManager

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

the class EntitlementService method createApplicationCollectionConfig.

private ServiceConfig createApplicationCollectionConfig(String realm) throws SMSException, SSOException {
    ServiceConfig sc = null;
    SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
    ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, token);
    ServiceConfig orgConfig = mgr.getOrganizationConfig(realm, null);
    if (orgConfig != null) {
        sc = orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
    }
    if (sc == null) {
        orgConfig.addSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS, SCHEMA_APPLICATIONS, 0, Collections.EMPTY_MAP);
        sc = orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
    }
    return sc;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 22 with ServiceConfigManager

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

the class AMSetupServlet method updateEmbeddedIdRepo.

/**
      * Update Embedded Idrepo instance with new embedded opends isntance.
      */
private static void updateEmbeddedIdRepo(String orgName, String configName, String entry) throws SMSException, SSOException {
    SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
    ServiceConfigManager scm = new ServiceConfigManager(token, IdConstants.REPO_SERVICE, "1.0");
    ServiceConfig sc = scm.getOrganizationConfig(orgName, null);
    if (sc != null) {
        ServiceConfig subConfig = sc.getSubConfig(configName);
        if (subConfig != null) {
            Map<String, Object> configMap = subConfig.getAttributes();
            Set<String> vals = (Set<String>) configMap.get("sun-idrepo-ldapv3-config-ldap-server");
            vals.add(entry);
            HashMap<String, Set<String>> mp = new HashMap<String, Set<String>>(2);
            mp.put("sun-idrepo-ldapv3-config-ldap-server", vals);
            subConfig.setAttributes(mp);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) LicenseSet(org.forgerock.openam.license.LicenseSet) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) DirUserObject(com.sun.identity.common.configuration.ServerConfigXML.DirUserObject) ServerObject(com.sun.identity.common.configuration.ServerConfigXML.ServerObject) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 23 with ServiceConfigManager

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

the class MailService method sendEmail.

// Mapping to known type
@SuppressWarnings("unchecked")
private JsonValue sendEmail(String realm, JsonValue jsonValue) throws ResourceException {
    String to = jsonValue.get("to").asString();
    if (isBlank(to)) {
        throw new BadRequestException("to field is missing");
    }
    String mimeType = jsonValue.get("type").asString();
    if (isBlank(mimeType)) {
        throw new BadRequestException("mime type needs to be specified");
    }
    String subject = jsonValue.get("subject").asString();
    String body = jsonValue.get("body").asString();
    Map<String, Set<String>> mailConfigAttributes;
    try {
        ServiceConfigManager configManager = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
        ServiceConfig mailConfig = configManager.getOrganizationConfig(realm, null);
        mailConfigAttributes = mailConfig.getAttributes();
    } catch (SMSException | SSOException e) {
        throw new InternalServerErrorException("Cannot create the service " + MailServerImpl.SERVICE_NAME, e);
    }
    if (isEmpty(mailConfigAttributes)) {
        throw new InternalServerErrorException("No service mail config found for realm " + realm);
    }
    MailServer mailServer;
    try {
        String attr = mailConfigAttributes.get(MAIL_SERVER_CLASS).iterator().next();
        mailServer = mailServerLoader.load(attr, realm);
    } catch (IllegalStateException e) {
        throw new InternalServerErrorException("Failed to create mail server", e);
    }
    if (isBlank(subject)) {
        subject = mailConfigAttributes.get(MAIL_SUBJECT).iterator().next();
    }
    if (isBlank(body)) {
        body = mailConfigAttributes.get(MAIL_BODY).iterator().next();
    }
    try {
        mailServer.sendEmail(to, subject, body, mimeType);
    } catch (MessagingException e) {
        throw new InternalServerErrorException("Failed to send email", e);
    }
    return json(object(field("success", "true")));
}
Also used : Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) MessagingException(javax.mail.MessagingException) SSOException(com.iplanet.sso.SSOException) MailServer(org.forgerock.openam.services.email.MailServer) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 24 with ServiceConfigManager

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

the class ScriptEngineConfigurator method registerServiceListener.

/**
     * Registers this configurator with the {@link com.sun.identity.sm.ServiceConfigManager} to receive updates
     * when the script configuration changes.
     *
     * @throws IllegalStateException if the configuration listener cannot be registered.
     */
public void registerServiceListener() {
    if (!initialised) {
        try {
            String listenerId = new ServiceConfigManager(SERVICE_NAME, getAdminToken()).addListener(this);
            if (listenerId == null) {
                throw new SMSException("Unable to register service config listener");
            }
            logger.info("Registered service config listener: {}", listenerId);
            updateConfig(POLICY_CONDITION);
            updateConfig(AUTHENTICATION_SERVER_SIDE);
            updateConfig(OIDC_CLAIMS);
            initialised = true;
        } catch (SSOException | SMSException e) {
            logger.error("Unable to create ServiceConfigManager", e);
            throw new IllegalStateException(e);
        }
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 25 with ServiceConfigManager

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

the class UmaSettingsImpl method addServiceListener.

private void addServiceListener() {
    try {
        final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
        final ServiceConfigManager serviceConfigManager = new ServiceConfigManager(token, SERVICE_NAME, SERVICE_VERSION);
        if (serviceConfigManager.addListener(new UmaProviderSettingsChangeListener()) == null) {
            logger.error("Could not add listener to ServiceConfigManager instance. UMA provider service " + "changes will not be dynamically updated for realm " + realm);
        }
    } catch (Exception e) {
        String message = "Unable to construct ServiceConfigManager: " + e;
        logger.error(message, e);
        throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(null, message);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) SMSException(com.sun.identity.sm.SMSException) OAuthProblemException(org.forgerock.openam.oauth2.OAuthProblemException) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) SSOException(com.iplanet.sso.SSOException)

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