Search in sources :

Example 21 with ServiceConfig

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

the class SmsCollectionProvider method deleteInstance.

/**
     * Deletes a child instance of config. The parent config referenced by the request path is found, and
     * the config is deleted using the resourceId.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, final String resourceId, DeleteRequest request) {
    try {
        ServiceConfigManager scm = getServiceConfigManager(context);
        ServiceConfig config = parentSubConfigFor(context, scm);
        checkedInstanceSubConfig(context, resourceId, config);
        if (isDefaultCreatedAuthModule(context, resourceId)) {
            scm.removeOrganizationConfiguration(realmFor(context), null);
        } else {
            config.removeSubConfig(resourceId);
        }
        return awaitDeletion(context, resourceId).then(new Function<Void, ResourceResponse, ResourceException>() {

            @Override
            public ResourceResponse apply(Void aVoid) {
                return newResourceResponse(resourceId, "0", json(object(field("success", true))));
            }
        });
    } catch (ServiceNotFoundException e) {
        debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on delete", e);
        return new NotFoundException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on delete", e);
        return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on delete", e);
        return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 22 with ServiceConfig

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

the class SmsServerPropertiesResource method readInstance.

@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context serverContext, ReadRequest readRequest) {
    Map<String, String> uriVariables = getUriTemplateVariables(serverContext);
    final String tabName = getTabName(uriVariables);
    if (tabName == null) {
        return new BadRequestException("Tab name not specified.").asPromise();
    }
    final String serverName = getServerName(uriVariables);
    if (serverName == null) {
        return new BadRequestException("Server name not specified.").asPromise();
    }
    try {
        ServiceConfigManager scm = getServiceConfigManager(serverContext);
        ServiceConfig serverConfigs = getServerConfigs(scm);
        Properties defaultAttributes = getAttributes(serverConfigs.getSubConfig(SERVER_DEFAULT_NAME));
        final ServiceConfig serverConfig = serverConfigs.getSubConfig(serverName);
        if (serverConfig == null) {
            return new BadRequestException("Unknown Server " + serverName).asPromise();
        }
        Properties serverSpecificAttributes = getAttributes(serverConfig);
        Map<String, String> defaultSection = new HashMap<>();
        JsonValue result = json(object(field("default", defaultSection)));
        List<String> attributeNamesForTab;
        if (tabName.equalsIgnoreCase(DIRECTORY_CONFIGURATION_TAB_NAME)) {
            InputStream resourceStream = new StringInputStream(getServerConfigXml(serverConfig));
            Document serverXml = dBuilder.parse(resourceStream);
            XPath xPath = XPathFactory.newInstance().newXPath();
            final String baseExpression = "//iPlanetDataAccessLayer/ServerGroup[@name='sms']/";
            String minConnections = (String) xPath.compile(baseExpression + "@" + DSConfigMgr.MIN_CONN_POOL).evaluate(serverXml, XPathConstants.STRING);
            String maxConnections = (String) xPath.compile(baseExpression + "@" + DSConfigMgr.MAX_CONN_POOL).evaluate(serverXml, XPathConstants.STRING);
            String dirDN = (String) xPath.compile(baseExpression + "User/DirDN").evaluate(serverXml, XPathConstants.STRING);
            String directoryPassword = (String) xPath.compile(baseExpression + "User/DirPassword").evaluate(serverXml, XPathConstants.STRING);
            result.put("minConnections", minConnections);
            result.put("maxConnections", maxConnections);
            result.put("dirDN", dirDN);
            result.put("directoryPassword", directoryPassword);
            NodeList serverNames = (NodeList) xPath.compile(baseExpression + "Server/@name").evaluate(serverXml, XPathConstants.NODESET);
            for (int i = 0; i < serverNames.getLength(); i++) {
                final String directoryServerName = serverNames.item(i).getNodeValue();
                final String serverExpression = baseExpression + "Server[@name='" + directoryServerName + "']";
                String hostExpression = serverExpression + "/@host";
                String portExpression = serverExpression + "/@port";
                String typeExpression = serverExpression + "/@type";
                NodeList serverAttributes = (NodeList) xPath.compile(hostExpression + "|" + portExpression + "|" + typeExpression).evaluate(serverXml, XPathConstants.NODESET);
                for (int a = 0; a < serverAttributes.getLength(); a++) {
                    final Node serverAttribute = serverAttributes.item(a);
                    result.addPermissive(new JsonPointer("servers/" + directoryServerName + "/" + serverAttribute.getNodeName()), serverAttribute.getNodeValue());
                }
            }
        } else {
            if (tabName.equalsIgnoreCase(ADVANCED_TAB_NAME)) {
                attributeNamesForTab = getAdvancedTabAttributeNames(serverConfig);
            } else {
                attributeNamesForTab = getDefaultValueNames(tabName);
            }
            for (String attributeName : attributeNamesForTab) {
                final String defaultAttribute = (String) defaultAttributes.get(attributeName);
                if (defaultAttribute != null) {
                    defaultSection.put(attributeName, (String) defaultAttributes.get(attributeName));
                }
                final String serverSpecificAttribute = (String) serverSpecificAttributes.get(attributeName);
                if (serverSpecificAttribute != null) {
                    result.add(attributeName, serverSpecificAttribute);
                }
            }
        }
        return newResultPromise(newResourceResponse(serverName + "/properties/" + tabName, String.valueOf(result.hashCode()), result));
    } catch (SMSException | SSOException | ParserConfigurationException | SAXException | IOException | XPathExpressionException e) {
        logger.error("Error reading property sheet for tab " + tabName, e);
    }
    return new BadRequestException("Error reading properties file for " + tabName).asPromise();
}
Also used : XPath(javax.xml.xpath.XPath) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) StringInputStream(com.sun.xml.bind.StringInputStream) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) JsonPointer(org.forgerock.json.JsonPointer) IOException(java.io.IOException) Properties(java.util.Properties) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringInputStream(com.sun.xml.bind.StringInputStream) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 23 with ServiceConfig

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

the class SmsSingletonProvider method handleRead.

/**
     * Reads config for the singleton instance referenced, and returns the JsonValue representation.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context serverContext, ReadRequest readRequest) {
    String resourceId = resourceId();
    try {
        ServiceConfig config = getServiceConfigNode(serverContext, resourceId);
        String realm = realmFor(serverContext);
        JsonValue result = withExtraAttributes(realm, convertToJson(realm, config));
        return newResultPromise(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException)

Example 24 with ServiceConfig

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

the class SmsSingletonProvider method handleCreate.

/**
     * Creates config for the singleton instance referenced, and returns the JsonValue representation.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> handleCreate(Context serverContext, CreateRequest createRequest) {
    final String realm = realmFor(serverContext);
    try {
        Map<String, Set<String>> attrs = convertFromJson(createRequest.getContent(), realm);
        ServiceConfigManager scm = getServiceConfigManager(serverContext);
        ServiceConfig config;
        if (subSchemaPath.isEmpty()) {
            if (type == SchemaType.GLOBAL) {
                config = scm.createGlobalConfig(attrs);
            } else {
                config = scm.createOrganizationConfig(realm, attrs);
            }
        } else {
            ServiceConfig parent = parentSubConfigFor(serverContext, scm);
            parent.addSubConfig(resourceId(), lastSchemaNodeName(), -1, attrs);
            config = parent.getSubConfig(lastSchemaNodeName());
        }
        JsonValue result = withExtraAttributes(realm, convertToJson(realm, config));
        return newResultPromise(newResourceResponse(resourceId(), String.valueOf(result.hashCode()), result));
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException) ResourceException(org.forgerock.json.resource.ResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 25 with ServiceConfig

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

the class SmsSingletonProvider method handleDelete.

/**
     * Deletes config for the singleton instance referenced.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context serverContext, DeleteRequest deleteRequest) {
    try {
        ServiceConfigManager scm = getServiceConfigManager(serverContext);
        if (subSchemaPath.isEmpty()) {
            if (type == SchemaType.GLOBAL) {
                scm.removeGlobalConfiguration(null);
            } else {
                scm.deleteOrganizationConfig(realmFor(serverContext));
            }
        } else {
            ServiceConfig parent = parentSubConfigFor(serverContext, scm);
            parent.removeSubConfig(resourceId());
        }
        return newResultPromise(newResourceResponse(resourceId(), "0", json(object(field("success", true)))));
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException) 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