Search in sources :

Example 56 with ServiceConfigManager

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

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

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

Example 59 with ServiceConfigManager

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

the class SmsRequestHandler method registerServiceListener.

private void registerServiceListener() throws SSOException, SMSException {
    final SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
    ServiceConfigManager serviceConfigManager = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, token);
    if (serviceConfigManager.addListener(this) == null) {
        debug.error("Could not add listener to ServiceConfigManager instance. Auth Module " + "changes will not be dynamically updated");
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 60 with ServiceConfigManager

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

the class AuthIdHelperTest method mockGetSigningKey.

private void mockGetSigningKey(String orgName, boolean nullKeyAlias) throws SMSException, SSOException {
    SSOToken adminToken = mock(SSOToken.class);
    ServiceConfigManager serviceConfigManager = mock(ServiceConfigManager.class);
    ServiceConfig serviceConfig = mock(ServiceConfig.class);
    Map<String, Set<String>> orgConfigAttributes = new HashMap<String, Set<String>>();
    Set<String> orgConfigSet = new HashSet<String>();
    if (!nullKeyAlias) {
        orgConfigSet.add(SIGNING_KEY);
    }
    orgConfigAttributes.put("iplanet-am-auth-hmac-signing-shared-secret", orgConfigSet);
    given(coreServicesWrapper.getAdminToken()).willReturn(adminToken);
    given(coreServicesWrapper.getServiceConfigManager("iPlanetAMAuthService", adminToken)).willReturn(serviceConfigManager);
    given(serviceConfigManager.getOrganizationConfig(orgName, null)).willReturn(serviceConfig);
    given(serviceConfig.getAttributes()).willReturn(orgConfigAttributes);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) JwtClaimsSet(org.forgerock.json.jose.jwt.JwtClaimsSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) HashSet(java.util.HashSet)

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