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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations