Search in sources :

Example 46 with ExternalResource

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;
}
Also used : DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) JPAExternalResource(org.apache.syncope.core.persistence.jpa.entity.resource.JPAExternalResource) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Example 47 with ExternalResource

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;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 48 with ExternalResource

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);
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) Transactional(org.springframework.transaction.annotation.Transactional) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 49 with ExternalResource

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());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 50 with ExternalResource

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));
    }
}
Also used : ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)59 Test (org.junit.jupiter.api.Test)30 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)28 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)23 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)21 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)15 List (java.util.List)14 Collectors (java.util.stream.Collectors)14 HashSet (java.util.HashSet)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Set (java.util.Set)12 Transactional (org.springframework.transaction.annotation.Transactional)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)10 Collections (java.util.Collections)9 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)9 Realm (org.apache.syncope.core.persistence.api.entity.Realm)9 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)9 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8