use of org.apache.syncope.common.lib.to.ResourceTO 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.ResourceTO 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.ResourceTO in project syncope by apache.
the class ConnectorITCase method issueSYNCOPE10.
@Test
public void issueSYNCOPE10() {
// ----------------------------------
// Copy resource and connector in order to create new objects.
// ----------------------------------
// Retrieve a connector instance template.
ConnInstanceTO connInstanceTO = connectorService.read("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b", Locale.ENGLISH.getLanguage());
assertNotNull(connInstanceTO);
// check for resource
List<ResourceTO> resources = resourceService.list().stream().filter(resource -> "fcf9f2b0-f7d6-42c9-84a6-61b28255a42b".equals(resource.getConnector())).collect(Collectors.toList());
assertEquals(4, resources.size());
// Retrieve a resource TO template.
ResourceTO resourceTO = resources.get(0);
// Make it new.
resourceTO.setKey("newAbout103" + getUUIDString());
// Make it new.
connInstanceTO.setKey(null);
connInstanceTO.setDisplayName("newDisplayName" + getUUIDString());
// ----------------------------------
// ----------------------------------
// Create a new connector instance.
// ----------------------------------
Response response = connectorService.create(connInstanceTO);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
connInstanceTO = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
assertNotNull(connInstanceTO);
assertFalse(connInstanceTO.getCapabilities().contains(ConnectorCapability.AUTHENTICATE));
final String connKey = connInstanceTO.getKey();
// Link resourceTO to the new connector instance.
resourceTO.setConnector(connKey);
// ----------------------------------
// ----------------------------------
// Check for connector instance update after resource creation.
// ----------------------------------
response = resourceService.create(resourceTO);
resourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(resourceTO);
resources = resourceService.list().stream().filter(resource -> connKey.equals(resource.getConnector())).collect(Collectors.toList());
assertEquals(1, resources.size());
// ----------------------------------
// ----------------------------------
// Check for spring bean.
// ----------------------------------
ConnInstanceTO connInstanceBean = connectorService.readByResource(resourceTO.getKey(), Locale.ENGLISH.getLanguage());
assertNotNull(connInstanceBean);
assertFalse(connInstanceBean.getCapabilities().contains(ConnectorCapability.AUTHENTICATE));
// ----------------------------------
// ----------------------------------
// Check for spring bean update after connector instance update.
// ----------------------------------
connInstanceTO.getCapabilities().add(ConnectorCapability.AUTHENTICATE);
connectorService.update(connInstanceTO);
ConnInstanceTO actual = connectorService.read(connInstanceTO.getKey(), Locale.ENGLISH.getLanguage());
assertNotNull(actual);
assertTrue(connInstanceTO.getCapabilities().contains(ConnectorCapability.AUTHENTICATE));
// check for spring bean update
connInstanceBean = connectorService.readByResource(resourceTO.getKey(), Locale.ENGLISH.getLanguage());
assertTrue(connInstanceBean.getCapabilities().contains(ConnectorCapability.AUTHENTICATE));
// ----------------------------------
}
use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.
the class ResourceWizardBuilder method buildModelSteps.
@Override
protected WizardModel buildModelSteps(final Serializable modelObject, final WizardModel wizardModel) {
ResourceTO resourceTO = ResourceTO.class.cast(modelObject);
wizardModel.add(new ResourceDetailsPanel(resourceTO, createFlag));
wizardModel.add(new ResourceConnConfPanel(resourceTO, createFlag) {
private static final long serialVersionUID = -1128269449868933504L;
@Override
protected Pair<Boolean, String> check(final AjaxRequestTarget target) {
return resourceRestClient.check(modelObject);
}
@Override
protected void onComponentTag(final ComponentTag tag) {
tag.append("class", "scrollable-tab-content", " ");
}
});
wizardModel.add(new ResourceConnCapabilitiesPanel(resourceTO, connectorRestClient.read(resourceTO.getConnector()).getCapabilities()));
wizardModel.add(new ResourceSecurityPanel(resourceTO));
return wizardModel;
}
use of org.apache.syncope.common.lib.to.ResourceTO 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