use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class DBPasswordPropagationActions method before.
@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
if (AnyTypeKind.USER == task.getAnyTypeKind()) {
User user = userDAO.find(task.getEntityKey());
if (user != null && user.getPassword() != null) {
Attribute missing = AttributeUtil.find(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, task.getAttributes());
ConnInstance connInstance = task.getResource().getConnector();
if (missing != null && missing.getValue() != null && missing.getValue().size() == 1 && missing.getValue().get(0).equals(OperationalAttributes.PASSWORD_NAME) && cipherAlgorithmMatches(getCipherAlgorithm(connInstance), user.getCipherAlgorithm())) {
Attribute passwordAttribute = AttributeBuilder.buildPassword(new GuardedString(user.getPassword().toCharArray()));
Set<Attribute> attributes = new HashSet<>(task.getAttributes());
attributes.add(passwordAttribute);
attributes.remove(missing);
Attribute hashedPasswordAttribute = AttributeBuilder.build(AttributeUtil.createSpecialName("HASHED_PASSWORD"), Boolean.TRUE);
attributes.add(hashedPasswordAttribute);
task.setAttributes(attributes);
}
}
}
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class LDAPMembershipPropagationActions method before.
@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
Optional<? extends Provision> provision = task.getResource().getProvision(anyTypeDAO.findGroup());
if (AnyTypeKind.USER == task.getAnyTypeKind() && provision.isPresent() && provision.get().getMapping() != null && StringUtils.isNotBlank(provision.get().getMapping().getConnObjectLink())) {
User user = userDAO.find(task.getEntityKey());
if (user != null) {
List<String> groupConnObjectLinks = new ArrayList<>();
userDAO.findAllGroupKeys(user).forEach(groupKey -> {
Group group = groupDAO.find(groupKey);
if (group != null && groupDAO.findAllResourceKeys(groupKey).contains(task.getResource().getKey())) {
LOG.debug("Evaluating connObjectLink for {}", group);
JexlContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(group, jexlContext);
JexlUtils.addPlainAttrsToContext(group.getPlainAttrs(), jexlContext);
JexlUtils.addDerAttrsToContext(group, jexlContext);
String groupConnObjectLinkLink = JexlUtils.evaluate(provision.get().getMapping().getConnObjectLink(), jexlContext);
LOG.debug("ConnObjectLink for {} is '{}'", group, groupConnObjectLinkLink);
if (StringUtils.isNotBlank(groupConnObjectLinkLink)) {
groupConnObjectLinks.add(groupConnObjectLinkLink);
}
}
});
LOG.debug("Group connObjectLinks to propagate for membership: {}", groupConnObjectLinks);
Set<Attribute> attributes = new HashSet<>(task.getAttributes());
Set<String> groups = new HashSet<>(groupConnObjectLinks);
Attribute ldapGroups = AttributeUtil.find(getGroupMembershipAttrName(), attributes);
if (ldapGroups != null) {
ldapGroups.getValue().forEach(obj -> {
groups.add(obj.toString());
});
attributes.remove(ldapGroups);
}
attributes.add(AttributeBuilder.build(getGroupMembershipAttrName(), groups));
task.setAttributes(attributes);
}
} else {
LOG.debug("Not about user, or group mapping missing for resource: not doing anything");
}
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class GroupTest method saveWithTwoOwners.
@Test
public void saveWithTwoOwners() {
assertThrows(InvalidEntityException.class, () -> {
Group root = groupDAO.findByName("root");
assertNotNull(root);
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
Group group = entityFactory.newEntity(Group.class);
group.setRealm(realmDAO.getRoot());
group.setName("error");
group.setUserOwner(user);
group.setGroupOwner(root);
groupDAO.save(group);
});
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class ResourceTest method save.
@Test
public void save() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-save");
// specify the connector
ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
resource.setConnector(connector);
Provision provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findUser());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
Mapping mapping = entityFactory.newEntity(Mapping.class);
mapping.setProvision(provision);
provision.setMapping(mapping);
// specify mappings
for (int i = 0; i < 3; i++) {
MappingItem item = entityFactory.newEntity(MappingItem.class);
item.setExtAttrName("test" + i);
item.setIntAttrName("nonexistent" + i);
item.setMandatoryCondition("false");
item.setPurpose(MappingPurpose.PULL);
mapping.add(item);
item.setMapping(mapping);
}
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("username");
connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(connObjectKey);
connObjectKey.setMapping(mapping);
// map a derived attribute
MappingItem derived = entityFactory.newEntity(MappingItem.class);
derived.setConnObjectKey(false);
derived.setExtAttrName("fullname");
derived.setIntAttrName("cn");
derived.setPurpose(MappingPurpose.PROPAGATION);
mapping.add(derived);
derived.setMapping(mapping);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
resourceDAO.flush();
resourceDAO.detach(actual);
connInstanceDAO.detach(connector);
// assign the new resource to an user
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
user.add(actual);
resourceDAO.flush();
// retrieve resource
resource = resourceDAO.find(actual.getKey());
assertNotNull(resource);
resourceDAO.refresh(resource);
// check connector
connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
assertNotNull(connector.getResources());
assertNotNull(resource.getConnector());
assertTrue(resource.getConnector().equals(connector));
// check mappings
List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
assertNotNull(items);
assertEquals(5, items.size());
// check user
user = userDAO.findByUsername("rossini");
assertNotNull(user);
assertNotNull(user.getResources());
assertTrue(user.getResources().contains(actual));
}
use of org.apache.syncope.core.persistence.api.entity.user.User 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())));
}
Aggregations