use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AbstractAnyLogic method beforeCreate.
protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
Realm realm = realmDAO.findByFullPath(input.getRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add(input.getRealm());
throw sce;
}
AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
if (anyType == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
sce.getElements().add(input.getType());
throw sce;
}
TO any = input;
templateUtils.apply(any, realm.getTemplate(anyType));
List<LogicActions> actions = getActions(realm);
for (LogicActions action : actions) {
any = action.beforeCreate(any);
}
LOG.debug("Input: {}\nOutput: {}\n", input, any);
return ImmutablePair.of(any, actions);
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class NotificationManagerImpl method createTasks.
@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
Any<?> any = null;
if (before instanceof UserTO) {
any = userDAO.find(((UserTO) before).getKey());
} else if (output instanceof UserTO) {
any = userDAO.find(((UserTO) output).getKey());
} else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
} else if (output instanceof AnyObjectTO) {
any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
} else if (before instanceof GroupTO) {
any = groupDAO.find(((GroupTO) before).getKey());
} else if (output instanceof GroupTO) {
any = groupDAO.find(((GroupTO) output).getKey());
} else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
}
AnyType anyType = any == null ? null : any.getType();
LOG.debug("Search notification for [{}]{}", anyType, any);
List<NotificationTask> notifications = new ArrayList<>();
for (Notification notification : notificationDAO.findAll()) {
if (LOG.isDebugEnabled()) {
notification.getAbouts().forEach(about -> {
LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
});
}
if (notification.isActive()) {
String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
if (!notification.getEvents().contains(currentEvent)) {
LOG.debug("No events found about {}", any);
} else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
final Map<String, Object> model = new HashMap<>();
model.put("type", type);
model.put("category", category);
model.put("subcategory", subcategory);
model.put("event", event);
model.put("condition", condition);
model.put("before", before);
model.put("output", output);
model.put("input", input);
if (any instanceof User) {
model.put("user", userDataBinder.getUserTO((User) any, true));
} else if (any instanceof Group) {
model.put("group", groupDataBinder.getGroupTO((Group) any, true));
} else if (any instanceof AnyObject) {
model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
}
NotificationTask notificationTask = getNotificationTask(notification, any, model);
notificationTask = taskDAO.save(notificationTask);
notifications.add(notificationTask);
}
} else {
LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
}
}
return notifications;
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- VIRTUAL -----------------
private VirSchema fill(final VirSchema schema, final VirSchemaTO schemaTO) {
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
if (schemaTO.getAnyTypeClass() != null && (schema.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(schema.getAnyTypeClass().getKey()))) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
if (anyTypeClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
} else {
anyTypeClass.add(schema);
schema.setAnyTypeClass(anyTypeClass);
}
} else if (schemaTO.getAnyTypeClass() == null && schema.getAnyTypeClass() != null) {
schema.getAnyTypeClass().getVirSchemas().remove(schema);
schema.setAnyTypeClass(null);
}
ExternalResource resource = resourceDAO.find(schemaTO.getResource());
if (resource == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("Resource " + schemaTO.getResource() + " not found");
throw sce;
}
AnyType anyType = anyTypeDAO.find(schemaTO.getAnyType());
if (anyType == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("AnyType " + schemaTO.getAnyType() + " not found");
throw sce;
}
Provision provision = resource.getProvision(anyType).orElse(null);
if (provision == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
sce.getElements().add("Provision for AnyType" + schemaTO.getAnyType() + " not found in " + schemaTO.getResource());
throw sce;
}
schema.setProvision(provision);
return virSchemaDAO.save(schema);
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyObjectDataBinderImpl method create.
@Override
public void create(final AnyObject anyObject, final AnyObjectTO anyObjectTO) {
AnyType type = anyTypeDAO.find(anyObjectTO.getType());
if (type == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
sce.getElements().add(anyObjectTO.getType());
throw sce;
}
anyObject.setType(type);
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
// name
SyncopeClientException invalidGroups = SyncopeClientException.build(ClientExceptionType.InvalidGroup);
if (anyObjectTO.getName() == null) {
LOG.error("No name specified for this anyObject");
invalidGroups.getElements().add("No name specified for this anyObject");
} else {
anyObject.setName(anyObjectTO.getName());
}
// realm
Realm realm = realmDAO.findByFullPath(anyObjectTO.getRealm());
if (realm == null) {
SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
noRealm.getElements().add("Invalid or null realm specified: " + anyObjectTO.getRealm());
scce.addException(noRealm);
}
anyObject.setRealm(realm);
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT);
if (anyObject.getRealm() != null) {
// relationships
anyObjectTO.getRelationships().forEach(relationshipTO -> {
if (StringUtils.isBlank(relationshipTO.getOtherEndType()) || AnyTypeKind.USER.name().equals(relationshipTO.getOtherEndType()) || AnyTypeKind.GROUP.name().equals(relationshipTO.getOtherEndType())) {
SyncopeClientException invalidAnyType = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
invalidAnyType.getElements().add(AnyType.class.getSimpleName() + " not allowed for relationship: " + relationshipTO.getOtherEndType());
scce.addException(invalidAnyType);
} else {
AnyObject otherEnd = anyObjectDAO.find(relationshipTO.getOtherEndKey());
if (otherEnd == null) {
LOG.debug("Ignoring invalid anyObject " + relationshipTO.getOtherEndKey());
} else if (anyObject.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) {
RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTO.getType());
if (relationshipType == null) {
LOG.debug("Ignoring invalid relationship type {}", relationshipTO.getType());
} else {
ARelationship relationship = entityFactory.newEntity(ARelationship.class);
relationship.setType(relationshipType);
relationship.setRightEnd(otherEnd);
relationship.setLeftEnd(anyObject);
anyObject.add(relationship);
}
} else {
LOG.error("{} cannot be assigned to {}", otherEnd, anyObject);
SyncopeClientException unassignabled = SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
unassignabled.getElements().add("Cannot be assigned: " + otherEnd);
scce.addException(unassignabled);
}
}
});
// memberships
anyObjectTO.getMemberships().forEach(membershipTO -> {
Group group = membershipTO.getGroupKey() == null ? groupDAO.findByName(membershipTO.getGroupName()) : groupDAO.find(membershipTO.getGroupKey());
if (group == null) {
LOG.debug("Ignoring invalid group " + membershipTO.getGroupKey() + " / " + membershipTO.getGroupName());
} else if (anyObject.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) {
AMembership membership = entityFactory.newEntity(AMembership.class);
membership.setRightEnd(group);
membership.setLeftEnd(anyObject);
anyObject.add(membership);
// membership attributes
fill(anyObject, membership, membershipTO, anyUtils, scce);
} else {
LOG.error("{} cannot be assigned to {}", group, anyObject);
SyncopeClientException unassignable = SyncopeClientException.build(ClientExceptionType.InvalidMembership);
unassignable.getElements().add("Cannot be assigned: " + group);
scce.addException(unassignable);
}
});
}
// attributes and resources
fill(anyObject, anyObjectTO, anyUtils, scce);
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class GroupDataBinderImpl method create.
@Override
public void create(final Group group, final GroupTO groupTO) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
// name
SyncopeClientException invalidGroups = SyncopeClientException.build(ClientExceptionType.InvalidGroup);
if (groupTO.getName() == null) {
LOG.error("No name specified for this group");
invalidGroups.getElements().add("No name specified for this group");
} else {
group.setName(groupTO.getName());
}
// realm
Realm realm = realmDAO.findByFullPath(groupTO.getRealm());
if (realm == null) {
SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
noRealm.getElements().add("Invalid or null realm specified: " + groupTO.getRealm());
scce.addException(noRealm);
}
group.setRealm(realm);
// attributes and resources
fill(group, groupTO, anyUtilsFactory.getInstance(AnyTypeKind.GROUP), scce);
// owner
if (groupTO.getUserOwner() != null) {
User owner = userDAO.find(groupTO.getUserOwner());
if (owner == null) {
LOG.warn("Ignoring invalid user specified as owner: {}", groupTO.getUserOwner());
} else {
group.setUserOwner(owner);
}
}
if (groupTO.getGroupOwner() != null) {
Group owner = groupDAO.find(groupTO.getGroupOwner());
if (owner == null) {
LOG.warn("Ignoring invalid group specified as owner: {}", groupTO.getGroupOwner());
} else {
group.setGroupOwner(owner);
}
}
// dynamic membership
if (groupTO.getUDynMembershipCond() != null) {
setDynMembership(group, anyTypeDAO.findUser(), groupTO.getUDynMembershipCond());
}
groupTO.getADynMembershipConds().forEach((type, fiql) -> {
AnyType anyType = anyTypeDAO.find(type);
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), type);
} else {
setDynMembership(group, anyType, fiql);
}
});
// type extensions
groupTO.getTypeExtensions().forEach(typeExtTO -> {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
typeExtTO.getAuxClasses().forEach(name -> {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
});
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
});
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
}
Aggregations