return role;
}
public PropagationByResource update(final SyncopeRole role, final RoleMod roleMod) {
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
Set<String> currentResources = role.getResourceNames();
// name
SyncopeClientException invalidRoles = new SyncopeClientException(SyncopeClientExceptionType.InvalidRoles);
if (roleMod.getName() != null) {
SyncopeRole otherRole = roleDAO.find(roleMod.getName(),
role.getParent() == null ? null : role.getParent().getId());
if (otherRole == null || role.equals(otherRole)) {
if (!roleMod.getName().equals(role.getName())) {
propByRes.addAll(ResourceOperation.UPDATE, currentResources);
for (String resource : currentResources) {
propByRes.addOldAccountId(resource, role.getName());
}
role.setName(roleMod.getName());
}
} else {
LOG.error("Another role exists with the same name and the same parent role: " + otherRole);
invalidRoles.addElement(roleMod.getName());
scce.addException(invalidRoles);
}
}
if (roleMod.getInheritOwner() != null) {
role.setInheritOwner(roleMod.getInheritOwner());
}
if (roleMod.getInheritAttributes() != null) {
role.setInheritAttributes(roleMod.getInheritAttributes());
}
if (roleMod.getInheritDerivedAttributes() != null) {
role.setInheritDerivedAttributes(roleMod.getInheritDerivedAttributes());
}
if (roleMod.getInheritVirtualAttributes() != null) {
role.setInheritVirtualAttributes(roleMod.getInheritVirtualAttributes());
}
if (roleMod.getInheritPasswordPolicy() != null) {
role.setInheritPasswordPolicy(roleMod.getInheritPasswordPolicy());
}
if (roleMod.getInheritAccountPolicy() != null) {
role.setInheritAccountPolicy(roleMod.getInheritAccountPolicy());
}
// entitlements
if (roleMod.getEntitlements() != null) {
role.getEntitlements().clear();
for (String entitlementName : roleMod.getEntitlements()) {
Entitlement entitlement = entitlementDAO.find(entitlementName);
if (entitlement == null) {
LOG.warn("Ignoring invalid entitlement {}", entitlementName);
} else {
role.addEntitlement(entitlement);
}
}
}
// policies
if (roleMod.getPasswordPolicy() != null) {
role.setPasswordPolicy(roleMod.getPasswordPolicy().getId() == null
? null
: (PasswordPolicy) policyDAO.find(roleMod.getPasswordPolicy().getId()));
}
if (roleMod.getAccountPolicy() != null) {
role.setAccountPolicy(roleMod.getAccountPolicy().getId() == null
? null
: (AccountPolicy) policyDAO.find(roleMod.getAccountPolicy().getId()));
}
// owner
if (roleMod.getUserOwner() != null) {
role.setUserOwner(roleMod.getUserOwner().getId() == null
? null
: userDAO.find(roleMod.getUserOwner().getId()));
}
if (roleMod.getRoleOwner() != null) {
role.setRoleOwner(roleMod.getRoleOwner().getId() == null
? null
: roleDAO.find(roleMod.getRoleOwner().getId()));
}
// attributes, derived attributes, virtual attributes and resources
propByRes.merge(fill(role, roleMod, AttributableUtil.getInstance(AttributableType.ROLE), scce));
return propByRes;
}