ModelNode response = dmrResponse.get();
ModelNode overalResult = response.get(RESULT);
SecurityContext context = new SecurityContext(nameToken, resources);
context.setFacet(Facet.valueOf(accessControlReg.getFacet(nameToken).toUpperCase()));
try {
// retrieve access constraints per required resource and update the security context
for(int i=1; i<=steps.size();i++)
{
String step = "step-"+i;
if(overalResult.hasDefined(step))
{
ModelNode modelNode = overalResult.get(step).get(RESULT);
ModelNode stepResult = null;
if(modelNode.getType() == ModelType.LIST)
stepResult = modelNode.asList().get(0);
else
stepResult = modelNode;
ModelNode accessControl = stepResult.hasDefined(RESULT) ?
stepResult.get(RESULT).get("access-control") : stepResult.get("access-control");
List<Property> properties = accessControl.isDefined() ?
accessControl.asPropertyList() : Collections.EMPTY_LIST;
if(!properties.isEmpty())
{
Property acl = properties.get(0);
assert acl.getName().equals("default"); //TODO: overrides ...
ModelNode model = acl.getValue();
Constraints c = new Constraints();
if(model.hasDefined("address")
&& model.get("address").asBoolean()==false)
{
c.setAddress(false);
}
else
{
c.setReadConfig(model.get("read-config").asBoolean());
c.setWriteConfig(model.get("write-config").asBoolean());
c.setReadRuntime(model.get("read-runtime").asBoolean());
c.setWriteRuntime(model.get("write-runtime").asBoolean());
}
// TODO: attribute constraints
context.updateResourceConstraints(step2address.get(step), c);
}
}
}
} catch (Throwable e) {
Log.error("Failed to parse response", e);
callback.onFailure(new RuntimeException("Failed to parse response", e));
}
context.seal(); // makes it immutable
contextMapping.put(nameToken, context);
callback.onSuccess(context);