use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceLogic method readConnObject.
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_GET_CONNOBJECT + "')")
@Transactional(readOnly = true)
public ConnObjectTO readConnObject(final String key, final String anyTypeKey, final String anyKey) {
Triple<ExternalResource, AnyType, Provision> init = connObjectInit(key, anyTypeKey);
// 1. find any
Any<?> any = init.getMiddle().getKind() == AnyTypeKind.USER ? userDAO.find(anyKey) : init.getMiddle().getKind() == AnyTypeKind.ANY_OBJECT ? anyObjectDAO.find(anyKey) : groupDAO.find(anyKey);
if (any == null) {
throw new NotFoundException(init.getMiddle() + " " + anyKey);
}
// 2. build connObjectKeyItem
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(init.getRight());
if (!connObjectKeyItem.isPresent()) {
throw new NotFoundException("ConnObjectKey mapping for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'");
}
Optional<String> connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, init.getRight());
// 3. determine attributes to query
Set<MappingItem> linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream().map(virSchema -> virSchema.asLinkingMappingItem()).collect(Collectors.toSet());
Iterator<MappingItem> mapItems = new IteratorChain<>(init.getRight().getMapping().getItems().iterator(), linkinMappingItems.iterator());
// 4. read from the underlying connector
Connector connector = connFactory.getConnector(init.getLeft());
ConnectorObject connectorObject = connector.getObject(init.getRight().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue.get()), MappingUtils.buildOperationOptions(mapItems));
if (connectorObject == null) {
throw new NotFoundException("Object " + connObjectKeyValue.get() + " with class " + init.getRight().getObjectClass() + " not found on resource " + key);
}
// 5. build result
Set<Attribute> attributes = connectorObject.getAttributes();
if (AttributeUtil.find(Uid.NAME, attributes) == null) {
attributes.add(connectorObject.getUid());
}
if (AttributeUtil.find(Name.NAME, attributes) == null) {
attributes.add(connectorObject.getName());
}
return ConnObjectUtils.getConnObjectTO(connectorObject);
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceTest method updateRemoveOrgUnit.
@Test
public void updateRemoveOrgUnit() {
ExternalResource resource = resourceDAO.find("resource-ldap-orgunit");
assertNotNull(resource);
assertNotNull(resource.getOrgUnit());
String orgUnitKey = resource.getOrgUnit().getKey();
assertNotNull(entityManager().find(JPAOrgUnit.class, orgUnitKey));
resource.getOrgUnit().setResource(null);
resource.setOrgUnit(null);
resourceDAO.save(resource);
resourceDAO.flush();
resource = resourceDAO.find("resource-ldap-orgunit");
assertNull(resource.getOrgUnit());
assertNull(entityManager().find(JPAOrgUnit.class, orgUnitKey));
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceTest method createWithPasswordPolicy.
@Test
public void createWithPasswordPolicy() {
final String resourceName = "resourceWithPasswordPolicy";
PasswordPolicy policy = policyDAO.find("986d1236-3ac5-4a19-810c-5ab21d79cba1");
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey(resourceName);
resource.setPasswordPolicy(policy);
ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
assertNotNull(connector);
resource.setConnector(connector);
ExternalResource actual = resourceDAO.save(resource);
assertNotNull(actual);
actual = resourceDAO.find(actual.getKey());
assertNotNull(actual);
assertNotNull(actual.getPasswordPolicy());
resourceDAO.delete(resourceName);
assertNull(resourceDAO.find(resourceName));
assertNotNull(policyDAO.find("986d1236-3ac5-4a19-810c-5ab21d79cba1"));
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceTest method getConnObjectKey.
@Test
public void getConnObjectKey() {
ExternalResource resource = resourceDAO.find("ws-target-resource-2");
assertNotNull(resource);
assertEquals("fullname", resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getConnObjectKeyItem().get().getIntAttrName());
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class ResourceTest method saveInvalidProvision.
@Test
public void saveInvalidProvision() {
assertThrows(InvalidEntityException.class, () -> {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("invalidProvision");
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);
provision = entityFactory.newEntity(Provision.class);
provision.setAnyType(anyTypeDAO.findGroup());
provision.setObjectClass(ObjectClass.ACCOUNT);
provision.setResource(resource);
resource.add(provision);
ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
resource.setConnector(connector);
// save the resource
resourceDAO.save(resource);
});
}
Aggregations