use of com.sun.identity.sm.SMSException 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.SMSException 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.SMSException 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.SMSException 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.SMSException in project OpenAM by OpenRock.
the class SmsRealmProvider method handleDelete.
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context serverContext, DeleteRequest request) {
RealmContext realmContext = serverContext.asContext(RealmContext.class);
String realmPath = realmContext.getResolvedRealm();
try {
OrganizationConfigManager realmManager = new OrganizationConfigManager(getSSOToken(), realmPath);
final ResourceResponse resource = getResource(getJsonValue(realmPath));
realmManager.deleteSubOrganization(null, false);
String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
debug.message("RealmResource.deleteInstance :: DELETE of realm " + realmPath + " performed by " + principalName);
return newResultPromise(resource);
} catch (SMSException smse) {
ResourceException exception = configureErrorMessage(smse);
if (exception instanceof NotFoundException) {
debug.warning("RealmResource.deleteInstance() : Cannot find {}", realmPath, smse);
return exception.asPromise();
} else if (exception instanceof ForbiddenException || exception instanceof PermanentException || exception instanceof ConflictException || exception instanceof BadRequestException) {
debug.warning("RealmResource.deleteInstance() : Cannot DELETE {}", realmPath, smse);
return exception.asPromise();
} else {
return new BadRequestException(exception.getMessage(), exception).asPromise();
}
} catch (Exception e) {
return new BadRequestException(e.getMessage(), e).asPromise();
}
}
Aggregations