Search in sources :

Example 91 with ServiceConfig

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

the class ResourceManager method getManagedResourceNames.

/**
     * Returns a set of all managed resource names for the given 
     * service type.
     * 
     * @param serviceType the service type for which the resource
     * names should be returned.
     *
     * @return names of the resources.
     *
     * @exception PolicyException if unable to get the policy services,
     * and will contain the exception thrown by SMS.
     */
public Set getManagedResourceNames(String serviceType) throws PolicyException {
    ServiceConfig resources = getResourcesServiceConfig(false);
    if (resources == null) {
        return Collections.EMPTY_SET;
    }
    ServiceConfig leafConfig = null;
    try {
        leafConfig = resources.getSubConfig(serviceType);
    } catch (SMSException e1) {
        throw new PolicyException(e1);
    } catch (SSOException e1) {
        throw (new PolicyException(ResBundleUtils.rbName, "invalid_sso_token", null, null));
    }
    if (leafConfig == null) {
        // no resource node for this service type
        return Collections.EMPTY_SET;
    }
    // else, see if the attribute is there and non-empty
    Map existingAttrs = null;
    existingAttrs = leafConfig.getAttributes();
    if ((existingAttrs == null) || (!existingAttrs.containsKey(RESOURCE_PREFIXES))) {
        return Collections.EMPTY_SET;
    }
    // else, need to look into the attribute
    Set existingRes = (Set) existingAttrs.get(RESOURCE_PREFIXES);
    Set resourcePrefixes = existingRes;
    if ((existingRes != null) && (!existingRes.isEmpty())) {
        String xmlPrefix = (String) (existingRes.iterator().next());
        resourcePrefixes = xmlToResourcePrefixes(xmlPrefix).keySet();
    }
    return resourcePrefixes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 92 with ServiceConfig

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

the class ServerConfiguration method createServerInstance.

/**
     * Creates a server instance.
     *
     * @param ssoToken Single Sign-On Token which is used to access to the
     *        service management datastore.
     * @param instanceName Name of the server instance.
     * @param instanceId Identifier of the server instance.
     * @param values Set of string with this format <code>key=value</code>.
     * @param serverConfigXML Service configuration XML.
     * @throws SMSException if errors access in the service management
     *         datastore.
     * @throws SSOException if the <code>ssoToken</code> is not valid.
     * @throws UnknownPropertyNameException if property names are unknown.
     * @throws ConfigurationException  if the property name and values are not
     *         valid.
     */
public static boolean createServerInstance(SSOToken ssoToken, String instanceName, String instanceId, Set values, String serverConfigXML) throws SMSException, SSOException, ConfigurationException, UnknownPropertyNameException {
    boolean created = false;
    if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
        validateProperty(ssoToken, values);
    }
    ServiceConfig sc = getRootServerConfig(ssoToken);
    if (sc != null) {
        if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
            try {
                new URL(instanceName);
            } catch (MalformedURLException ex) {
                String[] param = { instanceName };
                throw new ConfigurationException("invalid.server.name", param);
            }
        }
        Map serverValues = new HashMap(4);
        Set setServerId = new HashSet(2);
        setServerId.add(instanceId);
        serverValues.put(ATTR_SERVER_ID, setServerId);
        if (values.isEmpty()) {
            values = new HashSet(2);
        }
        values.add(Constants.PROPERTY_NAME_LB_COOKIE_VALUE + "=" + instanceId);
        Set setServerConfigXML = new HashSet(2);
        setServerConfigXML.add(serverConfigXML);
        serverValues.put(ATTR_SERVER_CONFIG_XML, setServerConfigXML);
        serverValues.put(ATTR_SERVER_CONFIG, values);
        if (!instanceName.equals(DEFAULT_SERVER_CONFIG)) {
            setProtocolHostPortURI(serverValues, instanceName);
        }
        sc.addSubConfig(instanceName, SUBSCHEMA_SERVER, 0, serverValues);
        created = true;
    }
    if (created && !instanceName.equals(DEFAULT_SERVER_CONFIG)) {
        updateOrganizationAlias(ssoToken, instanceName, true);
    }
    return created;
}
Also used : MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) HashSet(java.util.HashSet)

Example 93 with ServiceConfig

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

the class MailServerImplTest method setup.

@BeforeMethod
public void setup() {
    ServiceConfigManager serviceConfigManagerMock = PowerMockito.mock(ServiceConfigManager.class);
    ServiceConfig serviceConfigMock = PowerMockito.mock(ServiceConfig.class);
    Debug debugMock = PowerMockito.mock(Debug.class);
    sendMailMock = PowerMockito.mock(AMSendMail.class);
    Map<String, Set<String>> options = createOptionsMap();
    try {
        Mockito.doNothing().when(sendMailMock).postMail(eq(recipients), anyString(), anyString(), anyString());
        Mockito.doNothing().when(sendMailMock).postMail(eq(recipients), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean());
    } catch (MessagingException e) {
        assert (false);
    }
    mailServerMock = new MailServerImpl(serviceConfigManagerMock, serviceConfigMock, debugMock, sendMailMock, options);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) MessagingException(javax.mail.MessagingException) AMSendMail(com.iplanet.am.util.AMSendMail) Matchers.anyString(org.mockito.Matchers.anyString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) Debug(com.sun.identity.shared.debug.Debug) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 94 with ServiceConfig

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

the class ConfigurationBase method getServerConfigurationId.

protected static Set getServerConfigurationId(ServiceConfig svc) throws SMSException, SSOException {
    Set currentIds = new HashSet();
    Set names = svc.getSubConfigNames("*");
    if ((names != null) && !names.isEmpty()) {
        for (Iterator i = names.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            ServiceConfig sc = svc.getSubConfig(name);
            Map map = sc.getAttributes();
            Set set = (Set) map.get(ATTR_SERVER_ID);
            if ((set != null) && !set.isEmpty()) {
                currentIds.add(set.iterator().next());
            }
        }
    }
    return currentIds;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 95 with ServiceConfig

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

the class ConfigurationBase method getSiteConfigurationIds.

protected static Set getSiteConfigurationIds(SSOToken ssoToken, ServiceConfig rootNode, String name, boolean bPrimaryOnly) throws SMSException, SSOException {
    if (rootNode == null) {
        rootNode = getRootSiteConfig(ssoToken);
    }
    ServiceConfig sc = rootNode.getSubConfig(name);
    if (sc == null) {
        return Collections.EMPTY_SET;
    }
    Set currentIds = new LinkedHashSet();
    ServiceConfig accessPoint = sc.getSubConfig(SUBCONFIG_ACCESS_URL);
    Map map = accessPoint.getAttributes();
    Set set = (Set) map.get(ATTR_PRIMARY_SITE_ID);
    currentIds.add(set.iterator().next());
    if (!bPrimaryOnly) {
        Set failovers = accessPoint.getSubConfigNames("*");
        if ((failovers != null) && !failovers.isEmpty()) {
            for (Iterator i = failovers.iterator(); i.hasNext(); ) {
                String foName = (String) i.next();
                ServiceConfig s = accessPoint.getSubConfig(foName);
                Map mapValues = s.getAttributes();
                set = (Set) mapValues.get(ATTR_SEC_ID);
                if ((set != null) && !set.isEmpty()) {
                    currentIds.add(set.iterator().next());
                }
            }
        }
    }
    return currentIds;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) Map(java.util.Map)

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