Search in sources :

Example 56 with ServiceConfig

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

the class VersionBehaviourConfigListener method updateSettings.

private void updateSettings() {
    try {
        ServiceConfig serviceConfig = mgr.getGlobalConfig(null);
        String versionBehaviour = ServiceConfigUtils.getStringAttribute(serviceConfig, VERSION_BEHAVIOUR_ATTRIBUTE);
        defaultVersionBehaviour = DefaultVersionBehaviour.valueOf(versionBehaviour.toUpperCase());
        warningEnabled = ServiceConfigUtils.getBooleanAttribute(serviceConfig, WARNING_BEHAVIOUR_ATTRIBUTE);
        if (debug.messageEnabled()) {
            debug.message("Successfully updated rest version behaviour settings to " + versionBehaviour);
        }
    } catch (Exception e) {
        debug.error("Not able to set version behaviour for rest endpoints", e);
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig)

Example 57 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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 58 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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 59 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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 60 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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)

Aggregations

ServiceConfig (com.sun.identity.sm.ServiceConfig)285 SMSException (com.sun.identity.sm.SMSException)180 Set (java.util.Set)144 SSOException (com.iplanet.sso.SSOException)143 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)124 HashSet (java.util.HashSet)119 Map (java.util.Map)101 HashMap (java.util.HashMap)96 SSOToken (com.iplanet.sso.SSOToken)52 Iterator (java.util.Iterator)41 IdRepoException (com.sun.identity.idm.IdRepoException)27 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)22 EntitlementException (com.sun.identity.entitlement.EntitlementException)19 LinkedHashSet (java.util.LinkedHashSet)18 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)17 CLIException (com.sun.identity.cli.CLIException)16 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)16 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)13 ServiceSchema (com.sun.identity.sm.ServiceSchema)12