use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class ResourceDataBinderImpl method getResourceTO.
@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
ResourceTO resourceTO = new ResourceTO();
// set the resource name
resourceTO.setKey(resource.getKey());
// set the connector instance
ConnInstance connector = resource.getConnector();
resourceTO.setConnector(connector == null ? null : connector.getKey());
resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
// set the provision information
resource.getProvisions().stream().map(provision -> {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setKey(provision.getKey());
provisionTO.setAnyType(provision.getAnyType().getKey());
provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
provisionTO.setSyncToken(provision.getSerializedSyncToken());
if (provision.getMapping() != null) {
MappingTO mappingTO = new MappingTO();
provisionTO.setMapping(mappingTO);
mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
populateItems(provision.getMapping().getItems(), mappingTO);
}
virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
provisionTO.getVirSchemas().add(virSchema.getKey());
MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
ItemTO itemTO = new ItemTO();
itemTO.setKey(linkingMappingItem.getKey());
BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
provisionTO.getMapping().getLinkingItems().add(itemTO);
});
return provisionTO;
}).forEachOrdered(provisionTO -> {
resourceTO.getProvisions().add(provisionTO);
});
if (resource.getOrgUnit() != null) {
OrgUnit orgUnit = resource.getOrgUnit();
OrgUnitTO orgUnitTO = new OrgUnitTO();
orgUnitTO.setKey(orgUnit.getKey());
orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
populateItems(orgUnit.getItems(), orgUnitTO);
resourceTO.setOrgUnit(orgUnitTO);
}
resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
resourceTO.setPropagationPriority(resource.getPropagationPriority());
resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
resourceTO.getConfOverride().addAll(resource.getConfOverride());
Collections.sort(resourceTO.getConfOverride());
resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
return resourceTO;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class RoleDataBinderImpl method getRoleTO.
@Override
public RoleTO getRoleTO(final Role role) {
RoleTO roleTO = new RoleTO();
roleTO.setKey(role.getKey());
roleTO.getEntitlements().addAll(role.getEntitlements());
roleTO.getRealms().addAll(role.getRealms().stream().map(Realm::getFullPath).collect(Collectors.toList()));
roleTO.getDynRealms().addAll(role.getDynRealms().stream().map(Entity::getKey).collect(Collectors.toList()));
if (role.getDynMembership() != null) {
roleTO.setDynMembershipCond(role.getDynMembership().getFIQLCond());
}
roleTO.getPrivileges().addAll(role.getPrivileges().stream().map(Entity::getKey).collect(Collectors.toList()));
return roleTO;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class PolicyDataBinderImpl method getPolicyTO.
@SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> T getPolicyTO(final Policy policy) {
T policyTO = null;
if (policy instanceof PasswordPolicy) {
PasswordPolicy passwordPolicy = PasswordPolicy.class.cast(policy);
PasswordPolicyTO passwordPolicyTO = new PasswordPolicyTO();
policyTO = (T) passwordPolicyTO;
passwordPolicyTO.setAllowNullPassword(passwordPolicy.isAllowNullPassword());
passwordPolicyTO.setHistoryLength(passwordPolicy.getHistoryLength());
passwordPolicyTO.getRules().addAll(passwordPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
} else if (policy instanceof AccountPolicy) {
AccountPolicy accountPolicy = AccountPolicy.class.cast(policy);
AccountPolicyTO accountPolicyTO = new AccountPolicyTO();
policyTO = (T) accountPolicyTO;
accountPolicyTO.setMaxAuthenticationAttempts(accountPolicy.getMaxAuthenticationAttempts());
accountPolicyTO.setPropagateSuspension(accountPolicy.isPropagateSuspension());
accountPolicyTO.getRules().addAll(accountPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
accountPolicyTO.getPassthroughResources().addAll(accountPolicy.getResources().stream().map(Entity::getKey).collect(Collectors.toList()));
} else if (policy instanceof PullPolicy) {
PullPolicy pullPolicy = PullPolicy.class.cast(policy);
PullPolicyTO pullPolicyTO = new PullPolicyTO();
policyTO = (T) pullPolicyTO;
pullPolicyTO.setConflictResolutionAction(((PullPolicy) policy).getConflictResolutionAction());
pullPolicy.getCorrelationRules().forEach(rule -> {
pullPolicyTO.getCorrelationRules().put(rule.getAnyType().getKey(), rule.getImplementation().getKey());
});
}
if (policyTO != null) {
policyTO.setKey(policy.getKey());
policyTO.setDescription(policy.getDescription());
for (ExternalResource resource : resourceDAO.findByPolicy(policy)) {
policyTO.getUsedByResources().add(resource.getKey());
}
for (Realm realm : realmDAO.findByPolicy(policy)) {
policyTO.getUsedByRealms().add(realm.getFullPath());
}
}
return policyTO;
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class ResourceTest method delete.
@Test
public void delete() {
ExternalResource resource = resourceDAO.find("resource-testdb");
assertNotNull(resource);
// -------------------------------------
// Get originally associated connector
// -------------------------------------
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
// -------------------------------------
// -------------------------------------
// Get originally associated users
// -------------------------------------
List<User> users = userDAO.findByResource(resource);
assertNotNull(users);
Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
// -------------------------------------
// Get tasks
List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
assertFalse(propagationTasks.isEmpty());
// delete resource
resourceDAO.delete(resource.getKey());
// close the transaction
resourceDAO.flush();
// resource must be removed
ExternalResource actual = resourceDAO.find("resource-testdb");
assertNull(actual);
// resource must be not referenced any more from users
userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
assertNotNull(actualUser);
return actualUser;
}).forEachOrdered((actualUser) -> {
userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
});
// resource must be not referenced any more from the connector
ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
assertNotNull(actualConnector);
actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
// there must be no tasks
propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
use of org.apache.syncope.core.persistence.api.entity.Entity in project syncope by apache.
the class ElasticsearchUtils method builder.
/**
* Returns the builder specialized with content from the provided any.
*
* @param any user, group or any object to index
* @return builder specialized with content from the provided any
* @throws IOException in case of errors
*/
@Transactional
public XContentBuilder builder(final Any<?> any) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("id", any.getKey()).field("realm", any.getRealm().getFullPath()).field("anyType", any.getType().getKey()).field("creationDate", any.getCreationDate()).field("creator", any.getCreator()).field("lastChangeDate", any.getLastChangeDate()).field("lastModified", any.getLastModifier()).field("status", any.getStatus()).field("resources", any instanceof User ? userDAO.findAllResourceKeys(any.getKey()) : any instanceof AnyObject ? anyObjectDAO.findAllResourceKeys(any.getKey()) : groupDAO.findAllResourceKeys(any.getKey())).field("dynRealms", any instanceof User ? userDAO.findDynRealms(any.getKey()) : any instanceof AnyObject ? anyObjectDAO.findDynRealms(any.getKey()) : groupDAO.findDynRealms(any.getKey()));
if (any instanceof AnyObject) {
AnyObject anyObject = ((AnyObject) any);
builder = builder.field("name", anyObject.getName());
List<Object> memberships = new ArrayList<>(anyObjectDAO.findAllGroupKeys(anyObject));
builder = builder.field("memberships", memberships);
List<Object> relationships = new ArrayList<>();
List<Object> relationshipTypes = new ArrayList<>();
anyObjectDAO.findAllRelationships(anyObject).forEach(relationship -> {
relationships.add(relationship.getRightEnd().getKey());
relationshipTypes.add(relationship.getType().getKey());
});
builder = builder.field("relationships", relationships);
builder = builder.field("relationshipTypes", relationshipTypes);
} else if (any instanceof Group) {
Group group = ((Group) any);
builder = builder.field("name", group.getName());
if (group.getUserOwner() != null) {
builder = builder.field("userOwner", group.getUserOwner().getKey());
}
if (group.getGroupOwner() != null) {
builder = builder.field("groupOwner", group.getGroupOwner().getKey());
}
List<Object> members = groupDAO.findUMemberships(group).stream().map(membership -> membership.getLeftEnd().getKey()).collect(Collectors.toList());
members.add(groupDAO.findUDynMembers(group));
members.addAll(groupDAO.findAMemberships(group).stream().map(membership -> membership.getLeftEnd().getKey()).collect(Collectors.toList()));
members.add(groupDAO.findADynMembers(group));
builder = builder.field("members", members);
} else if (any instanceof User) {
User user = ((User) any);
builder = builder.field("username", user.getUsername()).field("lastLoginDate", user.getLastLoginDate()).field("lastRecertification", user.getLastRecertification()).field("lastRecertificator", user.getLastRecertificator());
List<Object> roles = userDAO.findAllRoles(user).stream().map(r -> r.getKey()).collect(Collectors.toList());
builder = builder.field("roles", roles);
Set<Object> privileges = userDAO.findAllRoles(user).stream().flatMap(role -> role.getPrivileges().stream()).map(Entity::getKey).collect(Collectors.toSet());
builder = builder.field("privileges", privileges);
List<Object> memberships = new ArrayList<>(userDAO.findAllGroupKeys(user));
builder = builder.field("memberships", memberships);
List<Object> relationships = new ArrayList<>();
Set<Object> relationshipTypes = new HashSet<>();
user.getRelationships().stream().map(relationship -> {
relationships.add(relationship.getRightEnd().getKey());
return relationship;
}).forEachOrdered(relationship -> {
relationshipTypes.add(relationship.getType().getKey());
});
builder = builder.field("relationships", relationships);
builder = builder.field("relationshipTypes", relationshipTypes);
}
if (any.getPlainAttrs() != null) {
for (PlainAttr<?> plainAttr : any.getPlainAttrs()) {
List<Object> values = plainAttr.getValues().stream().map(value -> value.getValue()).collect(Collectors.toList());
if (plainAttr.getUniqueValue() != null) {
values.add(plainAttr.getUniqueValue().getValue());
}
builder = builder.field(plainAttr.getSchema().getKey(), values);
}
}
builder = builder.endObject();
return builder;
}
Aggregations