use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceITCase method createWithPasswordPolicy.
@Test
public void createWithPasswordPolicy() {
String resourceKey = "res-with-password-policy";
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
resourceTO.setPasswordPolicy("986d1236-3ac5-4a19-810c-5ab21d79cba1");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setExtAttrName("userId");
item.setIntAttrName("userId");
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
Response response = resourceService.create(resourceTO);
ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(actual);
// check the existence
actual = resourceService.read(resourceKey);
assertNotNull(actual);
assertNotNull(actual.getPasswordPolicy());
assertEquals("986d1236-3ac5-4a19-810c-5ab21d79cba1", actual.getPasswordPolicy());
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceITCase method createWithoutExtAttr.
@Test
public void createWithoutExtAttr() {
assertThrows(SyncopeClientException.class, () -> {
String resourceKey = RESOURCE_NAME_CREATE_WRONG;
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("userId");
item.setConnObjectKey(true);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setIntAttrName("usernane");
// missing extAttrName ...
mapping.add(item);
createResource(resourceTO);
});
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceITCase method history.
@Test
public void history() {
List<ResourceHistoryConfTO> history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
assertNotNull(history);
int pre = history.size();
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
TraceLevel originalTraceLevel = SerializationUtils.clone(ldap.getUpdateTraceLevel());
assertEquals(TraceLevel.ALL, originalTraceLevel);
ProvisionTO originalProvision = SerializationUtils.clone(ldap.getProvision(AnyTypeKind.USER.name()).get());
assertEquals(ObjectClass.ACCOUNT_NAME, originalProvision.getObjectClass());
boolean originalFlag = ldap.isRandomPwdIfNotProvided();
assertTrue(originalFlag);
ldap.setUpdateTraceLevel(TraceLevel.FAILURES);
ldap.getProvision(AnyTypeKind.USER.name()).get().setObjectClass("ANOTHER");
ldap.setRandomPwdIfNotProvided(false);
resourceService.update(ldap);
ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertNotEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
assertNotEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
assertNotEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
assertEquals(pre + 1, history.size());
resourceHistoryService.restore(history.get(0).getKey());
ldap = resourceService.read(RESOURCE_NAME_LDAP);
assertEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
assertEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
assertEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceITCase method createWithSingleMappingItem.
@Test
public void createWithSingleMappingItem() {
String resourceKey = RESOURCE_NAME_CREATE_SINGLE;
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("userId");
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(item);
provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.GROUP.name());
provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
resourceTO.getProvisions().add(provisionTO);
mapping = new MappingTO();
provisionTO.setMapping(mapping);
item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("groupId");
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.PULL);
mapping.setConnObjectKeyItem(item);
Response response = resourceService.create(resourceTO);
ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(actual);
assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping());
assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems());
assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems());
assertEquals(MappingPurpose.PULL, actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
assertEquals(MappingPurpose.PROPAGATION, actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
}
use of org.apache.syncope.common.lib.to.ProvisionTO in project syncope by apache.
the class ResourceDataBinderTest method issue42.
@Test
public void issue42() {
PlainSchema userId = plainSchemaDAO.find("userId");
Set<MappingItem> beforeUserIdMappings = new HashSet<>();
for (ExternalResource res : resourceDAO.findAll()) {
if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (userId.getKey().equals(mapItem.getIntAttrName())) {
beforeUserIdMappings.add(mapItem);
}
}
}
}
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey("resource-issue42");
resourceTO.setConnector("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
resourceTO.setEnforceMandatoryCondition(true);
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("userId");
item.setExtAttrName("campo1");
item.setConnObjectKey(true);
item.setMandatoryCondition("false");
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
ExternalResource resource = resourceDataBinder.create(resourceTO);
resource = resourceDAO.save(resource);
assertNotNull(resource);
assertNotNull(resource.getProvision(anyTypeDAO.findUser()).get().getMapping());
assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
resourceDAO.flush();
ExternalResource actual = resourceDAO.find("resource-issue42");
assertNotNull(actual);
assertEquals(resource, actual);
userId = plainSchemaDAO.find("userId");
Set<MappingItem> afterUserIdMappings = new HashSet<>();
for (ExternalResource res : resourceDAO.findAll()) {
if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (userId.getKey().equals(mapItem.getIntAttrName())) {
afterUserIdMappings.add(mapItem);
}
}
}
}
assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
}
Aggregations