Search in sources :

Example 11 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance 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);
    });
}
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 12 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.

the class ConnInstanceHistoryConfTest method createDelete.

@Test
public void createDelete() {
    ConnInstance ldapConnector = connInstanceDAO.find("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
    assertNotNull(ldapConnector);
    ConnInstanceHistoryConf ldapHistory = entityFactory.newEntity(ConnInstanceHistoryConf.class);
    ldapHistory.setCreation(new Date());
    ldapHistory.setCreator("me");
    ldapHistory.setEntity(ldapConnector);
    ldapHistory.setConf(new ConnInstanceTO());
    ldapHistory = connInstanceHistoryConfDAO.save(ldapHistory);
    assertNotNull(ldapHistory.getKey());
    connInstanceHistoryConfDAO.flush();
    List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(ldapConnector);
    assertEquals(1, history.size());
    assertEquals(ldapHistory, history.get(0));
    connInstanceHistoryConfDAO.delete(ldapHistory.getKey());
    connInstanceHistoryConfDAO.flush();
    assertNull(connInstanceHistoryConfDAO.find(ldapHistory.getKey()));
    assertTrue(connInstanceHistoryConfDAO.findByEntity(ldapConnector).isEmpty());
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 13 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.

the class ConnInstanceTest method save.

@Test
public void save() throws ClassNotFoundException {
    ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
    connInstance.setLocation(new File(System.getProperty("java.io.tmpdir")).toURI().toString());
    // set connector version
    connInstance.setVersion("1.0");
    // set connector name
    connInstance.setConnectorName("WebService");
    // set bundle name
    connInstance.setBundleName("org.apache.syncope.core.persistence.test.util");
    connInstance.setDisplayName("New");
    connInstance.setConnRequestTimeout(60);
    // set the connector configuration using PropertyTO
    Set<ConnConfProperty> conf = new HashSet<>();
    ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
    endpointSchema.setName("endpoint");
    endpointSchema.setType(String.class.getName());
    endpointSchema.setRequired(true);
    ConnConfProperty endpoint = new ConnConfProperty();
    endpoint.setSchema(endpointSchema);
    endpoint.getValues().add("http://host.domain");
    ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
    servicenameSchema.setName("servicename");
    servicenameSchema.setType(String.class.getName());
    servicenameSchema.setRequired(true);
    ConnConfProperty servicename = new ConnConfProperty();
    servicename.setSchema(servicenameSchema);
    endpoint.getValues().add("Provisioning");
    conf.add(endpoint);
    conf.add(servicename);
    // set connector configuration
    connInstance.setConf(conf);
    assertFalse(connInstance.getConf().isEmpty());
    // perform save operation
    ConnInstance actual = connInstanceDAO.save(connInstance);
    assertNotNull("save did not work", actual.getKey());
    assertEquals("WebService", actual.getConnectorName());
    assertEquals("org.apache.syncope.core.persistence.test.util", actual.getBundleName());
    assertEquals("1.0", connInstance.getVersion());
    assertEquals("New", actual.getDisplayName());
    assertEquals(60, actual.getConnRequestTimeout().intValue());
    conf = connInstance.getConf();
    assertFalse(conf.isEmpty());
    assertNotNull(conf);
    assertTrue(conf.size() == 2);
}
Also used : ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) File(java.io.File) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 14 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.

the class ConnInstanceTest method findById.

@Test
public void findById() {
    ConnInstance connInstance = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connInstance);
    assertEquals("net.tirasa.connid.bundles.soap.WebServiceConnector", connInstance.getConnectorName());
    assertEquals("net.tirasa.connid.bundles.soap", connInstance.getBundleName());
    try {
        connInstanceDAO.authFind("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
        fail("This should not happen");
    } catch (DelegatedAdministrationException e) {
        assertNotNull(e);
    }
}
Also used : DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 15 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance in project syncope by apache.

the class ConnInstanceTest method findAll.

@Test
public void findAll() {
    List<GrantedAuthority> authorities = StandardEntitlement.values().stream().map(entitlement -> new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM)).collect(Collectors.toList());
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(new org.springframework.security.core.userdetails.User("admin", "FAKE_PASSWORD", authorities), "FAKE_PASSWORD", authorities);
    auth.setDetails(new SyncopeAuthenticationDetails("Master"));
    SecurityContextHolder.getContext().setAuthentication(auth);
    try {
        List<ConnInstance> connectors = connInstanceDAO.findAll();
        assertNotNull(connectors);
        assertFalse(connectors.isEmpty());
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : 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) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) HashSet(java.util.HashSet) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) 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) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) Set(java.util.Set) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) Collectors(java.util.stream.Collectors) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) File(java.io.File) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Transactional(org.springframework.transaction.annotation.Transactional) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)34 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)17 Test (org.junit.jupiter.api.Test)17 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)13 Mapping (org.apache.syncope.core.persistence.api.entity.resource.Mapping)11 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)11 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)10 Transactional (org.springframework.transaction.annotation.Transactional)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 HashSet (java.util.HashSet)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)5 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Date (java.util.Date)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Set (java.util.Set)3