report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
return report;
}
ReadChildrenNames op = new ReadChildrenNames(address, pathProperty.getStringValue());
Result res = connection.execute(op);
if (res.isSuccess()) {
List<String> entries = (List<String>) res.getResult();
if (!entries.isEmpty()) {
report.setErrorMessage("Resource is a singleton, but there are already children " + entries
+ " please remove them and retry");
report.setStatus(CreateResourceStatus.FAILURE);
return report;
}
}
}
//determine type then attribute
ResourceType resourceType = report.getResourceType();
String attribute = attributeMap.get(resourceType.getName());
//determine new child name from attribute
String newChild = newChildTypeMap.get(attribute);
//get resourceConfig
Configuration configuration = report.getResourceConfiguration();
if(attribute!=null){//create executed from SecurityDomain level
//retrieve the values passed in via config
Value loaded = loadCodeFlagType(configuration, attribute, null);
//populate the ModuleOptionType from the Configuration
List<Value> newAttributeState = new ArrayList<Value>();
newAttributeState.add(loaded);
//build the operation
//update the address to point to the new child being created
Address newChildLocation = new Address(path + "," + newChild);
Operation op = createAddModuleOptionTypeOperation(newChildLocation, attribute, newAttributeState);
Result result = connection.execute(op);
if (result.isSuccess()) {
report.setStatus(CreateResourceStatus.SUCCESS);
report.setResourceKey(newChildLocation.getPath());
report.setResourceName(report.getResourceType().getName());
} else {
report.setStatus(CreateResourceStatus.FAILURE);
report.setErrorMessage(result.getFailureDescription());
}
}else{//Create executed from the 'Login Modules/Provider Modules/etc. level.
//retrieve the parent type to lookup attribute to write to
ResourceType parentType = (ResourceType) resourceType.getParentResourceTypes().toArray()[0];
attribute = attributeMap.get(parentType.getName());
//retrieve existing attribute definition
//get the current attribute value
ReadAttribute op = new ReadAttribute(address, attribute);
Result result = getASConnection().execute(op);
if (result.isSuccess()) {
//populate attribute values
List<Value> currentAttributeState = new ArrayList<Value>();
currentAttributeState = ModuleOptionsComponent.populateSecurityDomainModuleOptions(result,
ModuleOptionsComponent.loadModuleOptionType(attribute));
//populate new Module type data
//retrieve the values passed in via config
Value loaded = loadCodeFlagType(configuration, attribute, null);
//append new type information
currentAttributeState.add(loaded);
//write values back out.
Operation write = new WriteAttribute(address);
write.addAdditionalProperty("name", attribute);//attribute to execute on
//now complete the write operation by updating the value
write.addAdditionalProperty("value", (Object) currentAttributeState);
result = connection.execute(write);
if (result.isSuccess()) {
report.setStatus(CreateResourceStatus.SUCCESS);
//Ex. subsystem=security,security-domain=createOne,authentication=classic,login-modules:0
report.setResourceKey(path + "," + attribute + ":" + (currentAttributeState.size() - 1));
//Ex. Login Modules 0
report.setResourceName(ModuleOptionType.readableNameMap.get(attribute) + " "
+ (currentAttributeState.size() - 1));
} else {
report.setStatus(CreateResourceStatus.FAILURE);
report.setErrorMessage(result.getFailureDescription());
}
}
}
return report;
}