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