use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class JPAExternalResourceDAO method authFind.
@Override
public ExternalResource authFind(final String key) {
ExternalResource resource = find(key);
if (resource == null) {
return null;
}
Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_READ);
if (authRealms == null || authRealms.isEmpty() || !authRealms.stream().anyMatch(realm -> resource.getConnector() != null && resource.getConnector().getAdminRealm().getFullPath().startsWith(realm))) {
throw new DelegatedAdministrationException(resource.getConnector().getAdminRealm().getFullPath(), ExternalResource.class.getSimpleName(), resource.getKey());
}
return resource;
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.
the class JPAUserDAO method getPasswordPolicies.
private List<PasswordPolicy> getPasswordPolicies(final User user) {
List<PasswordPolicy> policies = new ArrayList<>();
PasswordPolicy policy;
// add resource policies
for (ExternalResource resource : findAllResources(user)) {
policy = resource.getPasswordPolicy();
if (policy != null) {
policies.add(policy);
}
}
// add realm policies
for (Realm realm : realmDAO().findAncestors(user.getRealm())) {
policy = realm.getPasswordPolicy();
if (policy != null) {
policies.add(policy);
}
}
return policies;
}
use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource 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.resource.ExternalResource 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.resource.ExternalResource in project syncope by apache.
the class ResourceTest method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
resource.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
try {
resourceDAO.save(resource);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
}
}
Aggregations