use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class JPAConnInstanceDAO method authFind.
@Override
public ConnInstance authFind(final String key) {
ConnInstance connInstance = find(key);
if (connInstance == null) {
return null;
}
Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_READ);
if (authRealms == null || authRealms.isEmpty() || !authRealms.stream().anyMatch(realm -> connInstance.getAdminRealm().getFullPath().startsWith(realm))) {
throw new DelegatedAdministrationException(connInstance.getAdminRealm().getFullPath(), ConnInstance.class.getSimpleName(), connInstance.getKey());
}
return connInstance;
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class JPAConnInstanceDAO method delete.
@Override
public void delete(final String key) {
ConnInstance connInstance = find(key);
if (connInstance == null) {
return;
}
connInstance.getResources().stream().map(Entity::getKey).collect(Collectors.toList()).forEach(resource -> resourceDAO.delete(resource));
connInstanceHistoryConfDAO.deleteByEntity(connInstance);
entityManager().remove(connInstance);
connRegistry.unregisterConnector(key);
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ResourceTest method findById.
@Test
public void findById() {
ExternalResource resource = resourceDAO.find("ws-target-resource-1");
assertNotNull(resource);
ConnInstance connector = resource.getConnector();
assertNotNull(connector);
assertEquals("net.tirasa.connid.bundles.soap.WebServiceConnector", connector.getConnectorName());
assertEquals("net.tirasa.connid.bundles.soap", connector.getBundleName());
Mapping mapping = resource.getProvision(anyTypeDAO.findUser()).get().getMapping();
assertFalse(mapping.getItems().isEmpty());
assertTrue(mapping.getItems().stream().anyMatch(item -> "7f55b09c-b573-41dc-a9eb-ccd80bd3ea7a".equals(item.getKey())));
try {
resourceDAO.authFind("ws-target-resource-1");
fail("This should not happen");
} catch (DelegatedAdministrationException e) {
assertNotNull(e);
}
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance 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-basic-save");
resource.setPropagationPriority(2);
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);
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setExtAttrName("username");
connObjectKey.setIntAttrName("fullname");
connObjectKey.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(connObjectKey);
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
// save the resource
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
assertNotNull(actual.getConnector());
assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
assertFalse(actual.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().isEmpty());
assertEquals(Integer.valueOf(2), actual.getPropagationPriority());
}
use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.
the class ResourceTest method saveInvalidMappingIntAttr.
@Test
public void saveInvalidMappingIntAttr() {
assertThrows(InvalidEntityException.class, () -> {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("ws-target-resource-basic-save-invalid");
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
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);
MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
connObjectKey.setConnObjectKey(true);
mapping.add(connObjectKey);
// save the resource
resourceDAO.save(resource);
});
}
Aggregations