Search in sources :

Example 1 with ItemTO

use of org.apache.syncope.common.lib.to.ItemTO in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE453.

@Test
public void issueSYNCOPE453() {
    String resourceName = "issueSYNCOPE453Res" + getUUIDString();
    String groupKey = null;
    String groupName = "issueSYNCOPE453Group" + getUUIDString();
    try {
        // -------------------------------------------
        // Create a VirAttrITCase ad-hoc
        // -------------------------------------------
        VirSchemaTO rvirtualdata;
        try {
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, "rvirtualdata");
        } catch (SyncopeClientException e) {
            LOG.warn("rvirtualdata not found, re-creating", e);
            rvirtualdata = new VirSchemaTO();
            rvirtualdata.setKey("rvirtualdata");
            rvirtualdata.setExtAttrName("businessCategory");
            rvirtualdata.setResource(RESOURCE_NAME_LDAP);
            rvirtualdata.setAnyType(AnyTypeKind.GROUP.name());
            rvirtualdata = createSchema(SchemaType.VIRTUAL, rvirtualdata);
        }
        assertNotNull(rvirtualdata);
        if (!"minimal group".equals(rvirtualdata.getAnyTypeClass())) {
            LOG.warn("rvirtualdata not in minimal group, restoring");
            AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
            minimalGroup.getVirSchemas().add(rvirtualdata.getKey());
            anyTypeClassService.update(minimalGroup);
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, rvirtualdata.getKey());
            assertEquals("minimal group", rvirtualdata.getAnyTypeClass());
        }
        // -------------------------------------------
        // Create a resource ad-hoc
        // -------------------------------------------
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector("be24b061-019d-4e3e-baf0-0a6d0a45cb9c");
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resourceTO.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("fullname");
        item.setExtAttrName("ID");
        item.setPurpose(MappingPurpose.PROPAGATION);
        item.setConnObjectKey(true);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("USERNAME");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        item = new ItemTO();
        item.setIntAttrName("groups[" + groupName + "].rvirtualdata");
        item.setExtAttrName("EMAIL");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        assertNotNull(getObject(resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
        // -------------------------------------------
        GroupTO groupTO = new GroupTO();
        groupTO.setName(groupName);
        groupTO.setRealm("/");
        groupTO.getVirAttrs().add(attrTO(rvirtualdata.getKey(), "ml@group.it"));
        groupTO.getResources().add(RESOURCE_NAME_LDAP);
        groupTO = createGroup(groupTO).getEntity();
        groupKey = groupTO.getKey();
        assertEquals(1, groupTO.getVirAttrs().size());
        assertEquals("ml@group.it", groupTO.getVirAttrs().iterator().next().getValues().get(0));
        // -------------------------------------------
        // -------------------------------------------
        // Create new user
        // -------------------------------------------
        UserTO userTO = UserITCase.getUniqueSampleTO("syn453@syncope.apache.org");
        userTO.getPlainAttrs().add(attrTO("fullname", "123"));
        userTO.getResources().clear();
        userTO.getResources().add(resourceName);
        userTO.getVirAttrs().clear();
        userTO.getMemberships().clear();
        userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
        ProvisioningResult<UserTO> result = createUser(userTO);
        assertEquals(2, result.getPropagationStatuses().size());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(1).getStatus());
        userTO = result.getEntity();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        Map<String, Object> actuals = jdbcTemplate.queryForMap("SELECT id, surname, email FROM testpull WHERE id=?", new Object[] { userTO.getPlainAttr("fullname").get().getValues().get(0) });
        assertEquals(userTO.getPlainAttr("fullname").get().getValues().get(0), actuals.get("id").toString());
        assertEquals("ml@group.it", actuals.get("email"));
    // -------------------------------------------
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
    } finally {
        // -------------------------------------------
        // Delete resource and group ad-hoc
        // -------------------------------------------
        resourceService.delete(resourceName);
        if (groupKey != null) {
            groupService.delete(groupKey);
        }
    // -------------------------------------------
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 2 with ItemTO

use of org.apache.syncope.common.lib.to.ItemTO in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE691.

@Test
public void issueSYNCOPE691() {
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    try {
        ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).orElse(null);
        assertNotNull(provision);
        List<ItemTO> mail = provision.getMapping().getItems().stream().filter(item -> "mail".equals(item.getExtAttrName())).collect(Collectors.toList());
        provision.getMapping().getItems().removeAll(mail);
        provision.getVirSchemas().clear();
        ldap.getProvisions().clear();
        ldap.getProvisions().add(provision);
        ldap.setKey(RESOURCE_NAME_LDAP + "691" + getUUIDString());
        resourceService.create(ldap);
        ldap = resourceService.read(ldap.getKey());
        provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
        assertNotNull(provision);
        // create new virtual schema for the resource below
        VirSchemaTO virSchema = new VirSchemaTO();
        virSchema.setKey("syncope691" + getUUIDString());
        virSchema.setExtAttrName("mail");
        virSchema.setResource(ldap.getKey());
        virSchema.setAnyType(provision.getAnyType());
        virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
        assertNotNull(virSchema);
        AnyTypeClassTO newClass = new AnyTypeClassTO();
        newClass.setKey("syncope691" + getUUIDString());
        newClass.getVirSchemas().add(virSchema.getKey());
        Response response = anyTypeClassService.create(newClass);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
        newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
        // create a new user
        UserTO userTO = UserITCase.getUniqueSampleTO("syncope691@syncope.apache.org");
        userTO.getAuxClasses().add(newClass.getKey());
        userTO.getResources().clear();
        userTO.getMemberships().clear();
        userTO.getVirAttrs().clear();
        AttrTO emailTO = new AttrTO();
        emailTO.setSchema(virSchema.getKey());
        emailTO.getValues().add("test@issue691.dom1.org");
        emailTO.getValues().add("test@issue691.dom2.org");
        userTO.getVirAttrs().add(emailTO);
        // assign resource-ldap691 to user
        userTO.getResources().add(ldap.getKey());
        // save user
        userTO = createUser(userTO).getEntity();
        // make std controls about user
        assertNotNull(userTO);
        assertTrue(ldap.getKey().equals(userTO.getResources().iterator().next()));
        assertEquals(2, userTO.getVirAttrs().iterator().next().getValues().size());
        assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom1.org"));
        assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom2.org"));
        // update user
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        // modify virtual attribute
        userPatch.getVirAttrs().add(new AttrTO.Builder().schema(virSchema.getKey()).value("test@issue691.dom3.org").value("test@issue691.dom4.org").build());
        UserTO updated = updateUser(userPatch).getEntity();
        assertNotNull(updated);
        assertEquals(2, updated.getVirAttrs().iterator().next().getValues().size());
        assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom3.org"));
        assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom4.org"));
    } finally {
        try {
            resourceService.delete(ldap.getKey());
        } catch (Exception ignore) {
        // ignore
        }
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 3 with ItemTO

use of org.apache.syncope.common.lib.to.ItemTO in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE397.

@Test
public void issueSYNCOPE397() {
    ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
    // change mapping of resource-csv
    MappingTO origMapping = SerializationUtils.clone(csv.getProvisions().get(0).getMapping());
    try {
        // remove this mapping
        Optional<ItemTO> email = csv.getProvisions().get(0).getMapping().getItems().stream().filter(item -> "email".equals(item.getIntAttrName())).findFirst();
        if (email.isPresent()) {
            csv.getProvisions().get(0).getMapping().getItems().remove(email.get());
        }
        resourceService.update(csv);
        csv = resourceService.read(RESOURCE_NAME_CSV);
        assertNotNull(csv.getProvisions().get(0).getMapping());
        // create new virtual schema for the resource below
        ProvisionTO provision = csv.getProvision(AnyTypeKind.USER.name()).get();
        assertNotNull(provision);
        VirSchemaTO virSchema = new VirSchemaTO();
        virSchema.setKey("syncope397" + getUUIDString());
        virSchema.setExtAttrName("email");
        virSchema.setResource(RESOURCE_NAME_CSV);
        virSchema.setAnyType(provision.getAnyType());
        virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
        assertNotNull(virSchema);
        AnyTypeClassTO newClass = new AnyTypeClassTO();
        newClass.setKey("syncope397" + getUUIDString());
        newClass.getVirSchemas().add(virSchema.getKey());
        Response response = anyTypeClassService.create(newClass);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
        newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
        // create a new user
        UserTO userTO = UserITCase.getUniqueSampleTO("397@syncope.apache.org");
        userTO.getAuxClasses().add("csv");
        userTO.getAuxClasses().add(newClass.getKey());
        userTO.getResources().clear();
        userTO.getMemberships().clear();
        userTO.getVirAttrs().clear();
        userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testone.org"));
        // assign resource-csv to user
        userTO.getResources().add(RESOURCE_NAME_CSV);
        // save user
        userTO = createUser(userTO).getEntity();
        // make std controls about user
        assertNotNull(userTO);
        assertTrue(RESOURCE_NAME_CSV.equals(userTO.getResources().iterator().next()));
        assertEquals("test@testone.org", userTO.getVirAttrs().iterator().next().getValues().get(0));
        // update user
        UserTO toBeUpdated = userService.read(userTO.getKey());
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(toBeUpdated.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
        // assign new resource to user
        userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
        // modify virtual attribute
        userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testoneone.com"));
        // check Syncope change password
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").onSyncope(true).resource(RESOURCE_NAME_WS2).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        toBeUpdated = result.getEntity();
        assertTrue(toBeUpdated.getVirAttrs().iterator().next().getValues().contains("test@testoneone.com"));
        // check if propagates correctly with assertEquals on size of tasks list
        assertEquals(2, result.getPropagationStatuses().size());
    } finally {
        // restore mapping of resource-csv
        csv.getProvisions().get(0).setMapping(origMapping);
        resourceService.update(csv);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 4 with ItemTO

use of org.apache.syncope.common.lib.to.ItemTO in project syncope by apache.

the class SAML2ITCase method setIdPMapping.

@Test
public void setIdPMapping() {
    assumeTrue(SAML2SPDetector.isSAML2SPAvailable());
    Optional<SAML2IdPTO> ssoCircleOpt = saml2IdPService.list().stream().filter(o -> "https://idp.ssocircle.com".equals(o.getEntityID())).findFirst();
    assertTrue(ssoCircleOpt.isPresent());
    SAML2IdPTO ssoCircle = ssoCircleOpt.get();
    assertNotNull(ssoCircle);
    assertFalse(ssoCircle.isCreateUnmatching());
    assertNull(ssoCircle.getUserTemplate());
    assertFalse(ssoCircle.getItems().isEmpty());
    assertNotNull(ssoCircle.getConnObjectKeyItem());
    assertNotEquals("email", ssoCircle.getConnObjectKeyItem().getIntAttrName());
    assertNotEquals("EmailAddress", ssoCircle.getConnObjectKeyItem().getExtAttrName());
    ssoCircle.setCreateUnmatching(true);
    UserTO userTemplate = new UserTO();
    userTemplate.setRealm("'/'");
    ssoCircle.setUserTemplate(userTemplate);
    ssoCircle.getItems().clear();
    ItemTO keyMapping = new ItemTO();
    keyMapping.setIntAttrName("email");
    keyMapping.setExtAttrName("EmailAddress");
    ssoCircle.setConnObjectKeyItem(keyMapping);
    saml2IdPService.update(ssoCircle);
    ssoCircle = saml2IdPService.read(ssoCircle.getKey());
    assertTrue(ssoCircle.isCreateUnmatching());
    assertEquals(userTemplate, ssoCircle.getUserTemplate());
    assertEquals("email", ssoCircle.getConnObjectKeyItem().getIntAttrName());
    assertEquals("EmailAddress", ssoCircle.getConnObjectKeyItem().getExtAttrName());
}
Also used : X509Certificate(java.security.cert.X509Certificate) Merlin(org.apache.wss4j.common.crypto.Merlin) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) JwsJwtCompactConsumer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Date(java.util.Date) DOMUtils(org.apache.cxf.helpers.DOMUtils) DOM2Writer(org.apache.wss4j.common.util.DOM2Writer) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) SAML2SPService(org.apache.syncope.common.rest.api.service.SAML2SPService) SecureRandom(java.security.SecureRandom) AfterAll(org.junit.jupiter.api.AfterAll) Status(org.opensaml.saml.saml2.core.Status) MediaType(javax.ws.rs.core.MediaType) X500Name(org.bouncycastle.asn1.x500.X500Name) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SAML2ReceivedResponseTO(org.apache.syncope.common.lib.to.SAML2ReceivedResponseTO) XMLSignature(org.apache.xml.security.signature.XMLSignature) BeforeAll(org.junit.jupiter.api.BeforeAll) Document(org.w3c.dom.Document) SignatureConstants(org.opensaml.xmlsec.signature.support.SignatureConstants) BigInteger(java.math.BigInteger) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) Path(java.nio.file.Path) KeyPairGenerator(java.security.KeyPairGenerator) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) KeyStore(java.security.KeyStore) WSSConfig(org.apache.wss4j.dom.engine.WSSConfig) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) Certificate(java.security.cert.Certificate) Response(javax.ws.rs.core.Response) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AudienceRestrictionBean(org.apache.wss4j.common.saml.bean.AudienceRestrictionBean) Optional(java.util.Optional) SAMLProtocolResponseValidator(org.apache.cxf.rs.security.saml.sso.SAMLProtocolResponseValidator) Pattern(java.util.regex.Pattern) QName(javax.xml.namespace.QName) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) ContentSigner(org.bouncycastle.operator.ContentSigner) SAML2RequestTO(org.apache.syncope.common.lib.to.SAML2RequestTO) JcaX509CertificateConverter(org.bouncycastle.cert.jcajce.JcaX509CertificateConverter) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) SyncopeClientFactoryBean(org.apache.syncope.client.lib.SyncopeClientFactoryBean) WSConstants(org.apache.wss4j.dom.WSConstants) SAML2IdPTO(org.apache.syncope.common.lib.to.SAML2IdPTO) SubjectConfirmationDataBean(org.apache.wss4j.common.saml.bean.SubjectConfirmationDataBean) ConditionsBean(org.apache.wss4j.common.saml.bean.ConditionsBean) SAMLUtil(org.apache.wss4j.common.saml.SAMLUtil) RFC4519Style(org.bouncycastle.asn1.x500.style.RFC4519Style) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SAML2LoginResponseTO(org.apache.syncope.common.lib.to.SAML2LoginResponseTO) SAML2Constants(org.apache.wss4j.common.saml.builder.SAML2Constants) OpenSAMLUtil(org.apache.wss4j.common.saml.OpenSAMLUtil) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) OutputStream(java.io.OutputStream) Crypto(org.apache.wss4j.common.crypto.Crypto) Files(java.nio.file.Files) WebClient(org.apache.cxf.jaxrs.client.WebClient) DateTime(org.joda.time.DateTime) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Element(org.w3c.dom.Element) SAML2SPDetector(org.apache.syncope.fit.SAML2SPDetector) Loader(org.apache.wss4j.common.util.Loader) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Collections(java.util.Collections) StaxUtils(org.apache.cxf.staxutils.StaxUtils) FileSystems(java.nio.file.FileSystems) X509v3CertificateBuilder(org.bouncycastle.cert.X509v3CertificateBuilder) InputStream(java.io.InputStream) SAML2IdPTO(org.apache.syncope.common.lib.to.SAML2IdPTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 5 with ItemTO

use of org.apache.syncope.common.lib.to.ItemTO in project syncope by apache.

the class PropagationTaskITCase method privileges.

@Test
public void privileges() {
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    ldap.setKey("ldapWithPrivileges");
    ItemTO item = new ItemTO();
    item.setIntAttrName("privileges[mightyApp]");
    item.setExtAttrName("businessCategory");
    item.setPurpose(MappingPurpose.PROPAGATION);
    ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
    provision.getVirSchemas().clear();
    provision.getMapping().add(item);
    ldap = createResource(ldap);
    try {
        UserTO user = UserITCase.getUniqueSampleTO("privilege@syncope.apache.org");
        user.getResources().add(ldap.getKey());
        user.getRoles().add("Other");
        ProvisioningResult<UserTO> result = createUser(user);
        assertEquals(1, result.getPropagationStatuses().size());
        assertNotNull(result.getPropagationStatuses().get(0).getAfterObj());
        AttrTO businessCategory = result.getPropagationStatuses().get(0).getAfterObj().getAttr("businessCategory").orElse(null);
        assertNotNull(businessCategory);
        assertEquals(1, businessCategory.getValues().size());
        assertEquals("postMighty", businessCategory.getValues().get(0));
    } finally {
        resourceService.delete(ldap.getKey());
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Aggregations

ItemTO (org.apache.syncope.common.lib.to.ItemTO)35 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)30 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)25 Test (org.junit.jupiter.api.Test)25 MappingTO (org.apache.syncope.common.lib.to.MappingTO)22 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)17 Response (javax.ws.rs.core.Response)13 UserTO (org.apache.syncope.common.lib.to.UserTO)9 List (java.util.List)7 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)7 GroupTO (org.apache.syncope.common.lib.to.GroupTO)7 MappingPurpose (org.apache.syncope.common.lib.types.MappingPurpose)7 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)7 HashSet (java.util.HashSet)6 Date (java.util.Date)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)5 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)5 Optional (java.util.Optional)4