use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class ConnObjectUtils method getAnyPatch.
/**
* Build {@link AnyPatch} out of connector object attributes and schema mapping.
*
* @param key any object to be updated
* @param obj connector object
* @param original any object to get diff from
* @param pullTask pull task
* @param provision provision information
* @param anyUtils utils
* @param <T> any object
* @return modifications for the any object to be updated
*/
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public <T extends AnyPatch> T getAnyPatch(final String key, final ConnectorObject obj, final AnyTO original, final PullTask pullTask, final Provision provision, final AnyUtils anyUtils) {
AnyTO updated = getAnyTOFromConnObject(obj, pullTask, provision, anyUtils);
updated.setKey(key);
T anyPatch = null;
if (null != anyUtils.getAnyTypeKind()) {
switch(anyUtils.getAnyTypeKind()) {
case USER:
UserTO originalUser = (UserTO) original;
UserTO updatedUser = (UserTO) updated;
if (StringUtils.isBlank(updatedUser.getUsername())) {
updatedUser.setUsername(originalUser.getUsername());
}
// update password if and only if password is really changed
User user = userDAO.authFind(key);
if (StringUtils.isBlank(updatedUser.getPassword()) || ENCRYPTOR.verify(updatedUser.getPassword(), user.getCipherAlgorithm(), user.getPassword())) {
updatedUser.setPassword(null);
}
updatedUser.setSecurityQuestion(updatedUser.getSecurityQuestion());
updatedUser.setMustChangePassword(originalUser.isMustChangePassword());
anyPatch = (T) AnyOperations.diff(updatedUser, originalUser, true);
break;
case GROUP:
GroupTO originalGroup = (GroupTO) original;
GroupTO updatedGroup = (GroupTO) updated;
if (StringUtils.isBlank(updatedGroup.getName())) {
updatedGroup.setName(originalGroup.getName());
}
updatedGroup.setUserOwner(originalGroup.getUserOwner());
updatedGroup.setGroupOwner(originalGroup.getGroupOwner());
updatedGroup.setUDynMembershipCond(originalGroup.getUDynMembershipCond());
updatedGroup.getADynMembershipConds().putAll(originalGroup.getADynMembershipConds());
updatedGroup.getTypeExtensions().addAll(originalGroup.getTypeExtensions());
anyPatch = (T) AnyOperations.diff(updatedGroup, originalGroup, true);
break;
case ANY_OBJECT:
AnyObjectTO originalAnyObject = (AnyObjectTO) original;
AnyObjectTO updatedAnyObject = (AnyObjectTO) updated;
if (StringUtils.isBlank(updatedAnyObject.getName())) {
updatedAnyObject.setName(originalAnyObject.getName());
}
anyPatch = (T) AnyOperations.diff(updatedAnyObject, originalAnyObject, true);
break;
default:
}
}
return anyPatch;
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class ConnObjectUtils method getAnyTO.
/**
* Build a UserTO / GroupTO / AnyObjectTO out of connector object attributes and schema mapping.
*
* @param obj connector object
* @param pullTask pull task
* @param provision provision information
* @param anyUtils utils
* @param <T> any object
* @return UserTO for the user to be created
*/
@Transactional(readOnly = true)
public <T extends AnyTO> T getAnyTO(final ConnectorObject obj, final PullTask pullTask, final Provision provision, final AnyUtils anyUtils) {
T anyTO = getAnyTOFromConnObject(obj, pullTask, provision, anyUtils);
// (for users) if password was not set above, generate if resource is configured for that
if (anyTO instanceof UserTO && StringUtils.isBlank(((UserTO) anyTO).getPassword()) && provision.getResource().isRandomPwdIfNotProvided()) {
UserTO userTO = (UserTO) anyTO;
List<PasswordPolicy> passwordPolicies = new ArrayList<>();
Realm realm = realmDAO.findByFullPath(userTO.getRealm());
if (realm != null) {
realmDAO.findAncestors(realm).stream().filter(ancestor -> ancestor.getPasswordPolicy() != null).forEach(ancestor -> {
passwordPolicies.add(ancestor.getPasswordPolicy());
});
}
userTO.getResources().stream().map(resource -> resourceDAO.find(resource)).filter(resource -> resource != null && resource.getPasswordPolicy() != null).forEach(resource -> {
passwordPolicies.add(resource.getPasswordPolicy());
});
String password;
try {
password = passwordGenerator.generate(passwordPolicies);
} catch (InvalidPasswordRuleConf e) {
LOG.error("Could not generate policy-compliant random password for {}", userTO, e);
password = SecureRandomUtils.generateRandomPassword(16);
}
userTO.setPassword(password);
}
return anyTO;
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class TemplateUtils method check.
public void check(final Map<String, AnyTO> templates, final ClientExceptionType clientExceptionType) {
SyncopeClientException sce = SyncopeClientException.build(clientExceptionType);
templates.values().forEach(value -> {
value.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered(attrTO -> {
sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
});
value.getVirAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered((attrTO) -> {
sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
});
if (value instanceof UserTO) {
UserTO template = (UserTO) value;
if (StringUtils.isNotBlank(template.getUsername()) && !JexlUtils.isExpressionValid(template.getUsername())) {
sce.getElements().add("Invalid JEXL: " + template.getUsername());
}
if (StringUtils.isNotBlank(template.getPassword()) && !JexlUtils.isExpressionValid(template.getPassword())) {
sce.getElements().add("Invalid JEXL: " + template.getPassword());
}
} else if (value instanceof GroupTO) {
GroupTO template = (GroupTO) value;
if (StringUtils.isNotBlank(template.getName()) && !JexlUtils.isExpressionValid(template.getName())) {
sce.getElements().add("Invalid JEXL: " + template.getName());
}
}
});
if (!sce.isEmpty()) {
throw sce;
}
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
// 0. aux classes
any.getAuxClasses().clear();
anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
} else {
any.add(auxClass);
}
});
// 1. attributes
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema != null) {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
attr.setSchema(schema);
}
fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
if (attr.getValuesAsStrings().isEmpty()) {
attr.setOwner(null);
} else {
any.add(attr);
}
}
});
if (!invalidValues.isEmpty()) {
scce.addException(invalidValues);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
// 2. resources
anyTO.getResources().forEach(resourceKey -> {
ExternalResource resource = resourceDAO.find(resourceKey);
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
} else {
any.add(resource);
}
});
requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class Ownership method onEvent.
@Override
public void onEvent(final IEvent<?> event) {
if (event.getPayload() instanceof SearchClausePanel.SearchEvent) {
final AjaxRequestTarget target = SearchClausePanel.SearchEvent.class.cast(event.getPayload()).getTarget();
if (Ownership.this.isGroupOwnership.getObject()) {
final String fiql = SearchUtils.buildFIQL(groupSearchPanel.getModel().getObject(), SyncopeClient.getGroupSearchConditionBuilder());
groupDirectoryPanel.search(fiql, target);
} else {
final String fiql = SearchUtils.buildFIQL(userSearchPanel.getModel().getObject(), SyncopeClient.getUserSearchConditionBuilder());
userDirectoryPanel.search(fiql, target);
}
} else if (event.getPayload() instanceof AnySelectionDirectoryPanel.ItemSelection) {
final AnyTO sel = ((AnySelectionDirectoryPanel.ItemSelection) event.getPayload()).getSelection();
if (sel == null) {
wrapper.getInnerObject().setUserOwner(null);
wrapper.getInnerObject().setGroupOwner(null);
} else if (sel instanceof UserTO) {
wrapper.getInnerObject().setUserOwner(sel.getKey());
wrapper.getInnerObject().setGroupOwner(null);
} else if (sel instanceof GroupTO) {
wrapper.getInnerObject().setGroupOwner(sel.getKey());
wrapper.getInnerObject().setUserOwner(null);
}
((AnySelectionDirectoryPanel.ItemSelection) event.getPayload()).getTarget().add(ownerContainer);
} else {
super.onEvent(event);
}
}
Aggregations