in core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java [87:273]
protected <T extends Policy> T getPolicy(final T policy, final PolicyTO policyTO) {
T result = policy;
if (policyTO instanceof PasswordPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(PasswordPolicy.class);
}
PasswordPolicy passwordPolicy = PasswordPolicy.class.cast(result);
PasswordPolicyTO passwordPolicyTO = PasswordPolicyTO.class.cast(policyTO);
passwordPolicy.setAllowNullPassword(passwordPolicyTO.isAllowNullPassword());
passwordPolicy.setHistoryLength(passwordPolicyTO.getHistoryLength());
passwordPolicyTO.getRules().forEach(ruleKey -> {
Implementation rule = implementationDAO.find(ruleKey);
if (rule == null) {
LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", ruleKey);
} else {
passwordPolicy.add(rule);
}
});
// remove all implementations not contained in the TO
passwordPolicy.getRules().
removeIf(implementation -> !passwordPolicyTO.getRules().contains(implementation.getKey()));
} else if (policyTO instanceof AccountPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(AccountPolicy.class);
}
AccountPolicy accountPolicy = AccountPolicy.class.cast(result);
AccountPolicyTO accountPolicyTO = AccountPolicyTO.class.cast(policyTO);
accountPolicy.setMaxAuthenticationAttempts(accountPolicyTO.getMaxAuthenticationAttempts());
accountPolicy.setPropagateSuspension(accountPolicyTO.isPropagateSuspension());
accountPolicyTO.getRules().forEach(ruleKey -> {
Implementation rule = implementationDAO.find(ruleKey);
if (rule == null) {
LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", ruleKey);
} else {
accountPolicy.add(rule);
}
});
// remove all implementations not contained in the TO
accountPolicy.getRules().
removeIf(implementation -> !accountPolicyTO.getRules().contains(implementation.getKey()));
accountPolicy.getResources().clear();
accountPolicyTO.getPassthroughResources().forEach(resourceName -> {
ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
LOG.debug("Ignoring invalid resource {} ", resourceName);
} else {
accountPolicy.add(resource);
}
});
} else if (policyTO instanceof PropagationPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(PropagationPolicy.class);
}
PropagationPolicy propagationPolicy = PropagationPolicy.class.cast(result);
PropagationPolicyTO propagationPolicyTO = PropagationPolicyTO.class.cast(policyTO);
propagationPolicy.setFetchAroundProvisioning(propagationPolicyTO.isFetchAroundProvisioning());
propagationPolicy.setUpdateDelta(propagationPolicyTO.isUpdateDelta());
propagationPolicy.setBackOffStrategy(propagationPolicyTO.getBackOffStrategy());
propagationPolicy.setBackOffParams(propagationPolicyTO.getBackOffParams());
propagationPolicy.setMaxAttempts(propagationPolicyTO.getMaxAttempts());
} else if (policyTO instanceof PullPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(PullPolicy.class);
}
PullPolicy pullPolicy = PullPolicy.class.cast(result);
PullPolicyTO pullPolicyTO = PullPolicyTO.class.cast(policyTO);
pullPolicy.setConflictResolutionAction(pullPolicyTO.getConflictResolutionAction());
pullPolicyTO.getCorrelationRules().forEach((type, impl) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.debug("Invalid AnyType {} specified, ignoring...", type);
} else {
PullCorrelationRuleEntity correlationRule = pullPolicy.
getCorrelationRule(anyType.getKey()).orElse(null);
if (correlationRule == null) {
correlationRule = entityFactory.newEntity(PullCorrelationRuleEntity.class);
correlationRule.setAnyType(anyType);
correlationRule.setPullPolicy(pullPolicy);
pullPolicy.add(correlationRule);
}
Implementation rule = implementationDAO.find(impl);
if (rule == null) {
throw new NotFoundException("Implementation " + type + ' ' + impl);
}
correlationRule.setImplementation(rule);
}
});
// remove all rules not contained in the TO
pullPolicy.getCorrelationRules().removeIf(anyFilter -> !pullPolicyTO.getCorrelationRules().
containsKey(anyFilter.getAnyType().getKey()));
} else if (policyTO instanceof PushPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(PushPolicy.class);
}
PushPolicy pushPolicy = PushPolicy.class.cast(result);
PushPolicyTO pushPolicyTO = PushPolicyTO.class.cast(policyTO);
pushPolicy.setConflictResolutionAction(pushPolicyTO.getConflictResolutionAction());
pushPolicyTO.getCorrelationRules().forEach((type, impl) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.debug("Invalid AnyType {} specified, ignoring...", type);
} else {
PushCorrelationRuleEntity correlationRule = pushPolicy.
getCorrelationRule(anyType.getKey()).orElse(null);
if (correlationRule == null) {
correlationRule = entityFactory.newEntity(PushCorrelationRuleEntity.class);
correlationRule.setAnyType(anyType);
correlationRule.setPushPolicy(pushPolicy);
pushPolicy.add(correlationRule);
}
Implementation rule = implementationDAO.find(impl);
if (rule == null) {
throw new NotFoundException("Implementation " + type + ' ' + impl);
}
correlationRule.setImplementation(rule);
}
});
// remove all rules not contained in the TO
pushPolicy.getCorrelationRules().removeIf(anyFilter
-> !pushPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
} else if (policyTO instanceof AuthPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(AuthPolicy.class);
}
AuthPolicy authPolicy = AuthPolicy.class.cast(result);
AuthPolicyTO authPolicyTO = AuthPolicyTO.class.cast(policyTO);
authPolicy.setName(authPolicyTO.getKey());
authPolicy.setConf(authPolicyTO.getConf());
} else if (policyTO instanceof AccessPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(AccessPolicy.class);
}
AccessPolicy accessPolicy = AccessPolicy.class.cast(result);
AccessPolicyTO accessPolicyTO = AccessPolicyTO.class.cast(policyTO);
accessPolicy.setName(accessPolicyTO.getKey());
accessPolicy.setConf(accessPolicyTO.getConf());
} else if (policyTO instanceof AttrReleasePolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(AttrReleasePolicy.class);
}
AttrReleasePolicy attrReleasePolicy = AttrReleasePolicy.class.cast(result);
AttrReleasePolicyTO attrReleasePolicyTO = AttrReleasePolicyTO.class.cast(policyTO);
attrReleasePolicy.setName(attrReleasePolicyTO.getKey());
attrReleasePolicy.setOrder(attrReleasePolicyTO.getOrder());
attrReleasePolicy.setStatus(attrReleasePolicyTO.getStatus());
attrReleasePolicy.setConf(attrReleasePolicyTO.getConf());
} else if (policyTO instanceof TicketExpirationPolicyTO) {
if (result == null) {
result = (T) entityFactory.newEntity(TicketExpirationPolicy.class);
}
TicketExpirationPolicy ticketExpirationPolicy = TicketExpirationPolicy.class.cast(result);
TicketExpirationPolicyTO ticketExpirationPolicyTO = TicketExpirationPolicyTO.class.cast(policyTO);
ticketExpirationPolicy.setConf(ticketExpirationPolicyTO.getConf());
}
if (result != null) {
result.setName(policyTO.getName());
}
return result;
}