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