use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource 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.resource.ExternalResource in project syncope by apache.
the class ConnInstanceTest method deleteCascade.
@Test
public void deleteCascade() {
ConnInstance connInstance = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
assertNotNull(connInstance);
List<? extends ExternalResource> resources = connInstance.getResources();
assertNotNull(resources);
assertFalse(resources.isEmpty());
connInstanceDAO.delete(connInstance.getKey());
connInstanceDAO.flush();
ConnInstance actual = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
assertNull(actual);
for (ExternalResource resource : resources) {
assertNull(resourceDAO.find(resource.getKey()));
}
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class PlainSchemaTest method deleteSurname.
@Test
public void deleteSurname() {
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("surname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mappings = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mappings.add(mapItem);
}
}
}
}
assertFalse(mappings.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("surname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("surname");
assertNull(schema);
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class PlainSchemaTest method deleteFullname.
@Test
public void deleteFullname() {
// fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
// will be raised
resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
if ("fullname".equals(item.getIntAttrName())) {
item.setConnObjectKey(false);
} else if ("surname".equals(item.getIntAttrName())) {
item.setConnObjectKey(true);
}
});
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("fullname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertFalse(mapItems.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("fullname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("fullname");
assertNull(schema);
plainSchemaDAO.clear();
// check for mappings deletion
mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if ("fullname".equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertTrue(mapItems.isEmpty());
assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceTest method emptyMapping.
@Test
public void emptyMapping() {
ExternalResource ldap = resourceDAO.find("resource-ldap");
assertNotNull(ldap);
assertNotNull(ldap.getProvision(anyTypeDAO.findUser()).get().getMapping());
assertNotNull(ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping());
// need to avoid any class not defined in this Maven module
ldap.getPropagationActions().clear();
List<? extends MappingItem> items = ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping().getItems();
assertNotNull(items);
assertFalse(items.isEmpty());
List<String> itemKeys = items.stream().map(Entity::getKey).collect(Collectors.toList());
Provision groupProvision = ldap.getProvision(anyTypeDAO.findGroup()).get();
virSchemaDAO.findByProvision(groupProvision).forEach(schema -> virSchemaDAO.delete(schema.getKey()));
ldap.getProvisions().remove(groupProvision);
resourceDAO.save(ldap);
resourceDAO.flush();
itemKeys.forEach(itemKey -> assertNull(entityManager().find(JPAMappingItem.class, itemKey)));
}
Aggregations