Search in sources :

Example 51 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class PlainSchemaITCase method testBinaryValidation.

@Test
public void testBinaryValidation() throws IOException {
    // pdf - with validator
    PlainSchemaTO schemaTOpdf = new PlainSchemaTO();
    schemaTOpdf.setKey("BinaryPDF");
    schemaTOpdf.setType(AttrSchemaType.Binary);
    schemaTOpdf.setMimeType("application/pdf");
    schemaTOpdf.setValidator("BinaryValidator");
    schemaTOpdf.setAnyTypeClass("minimal user");
    createSchema(SchemaType.PLAIN, schemaTOpdf);
    // json - with validator
    PlainSchemaTO schemaTOjson = new PlainSchemaTO();
    schemaTOjson.setKey("BinaryJSON");
    schemaTOjson.setType(AttrSchemaType.Binary);
    schemaTOjson.setMimeType("application/json");
    schemaTOjson.setValidator("BinaryValidator");
    schemaTOjson.setAnyTypeClass("minimal user");
    createSchema(SchemaType.PLAIN, schemaTOjson);
    // json - no validator
    PlainSchemaTO schemaTOjson2 = new PlainSchemaTO();
    schemaTOjson2.setKey("BinaryJSON2");
    schemaTOjson2.setType(AttrSchemaType.Binary);
    schemaTOjson2.setMimeType("application/json");
    schemaTOjson2.setAnyTypeClass("minimal user");
    createSchema(SchemaType.PLAIN, schemaTOjson2);
    UserTO userTO = UserITCase.getUniqueSampleTO("test@syncope.apache.org");
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // validation OK - application/pdf -> application/pdf
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryPDF", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.pdf"))))).build());
    updateUser(userPatch);
    assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryPDF"));
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // validation KO - text/html -> application/pdf
    try {
        userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryPDF", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.html"))))).build());
        updateUser(userPatch);
        fail("This should not be reacheable");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidValues, e.getType());
    }
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // validation ok - application/json -> application/json
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryJSON", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.json"))))).build());
    updateUser(userPatch);
    assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryJSON"));
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // no validation - application/xml -> application/json
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryJSON2", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.xml"))))).build());
    updateUser(userPatch);
    assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryJSON2"));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 52 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class SAML2UserManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
public String update(final String username, final SAML2IdPEntity idp, final SAML2LoginResponseTO responseTO) {
    UserTO userTO = binder.getUserTO(userDAO.findKey(username));
    UserTO original = SerializationUtils.clone(userTO);
    fill(idp.getKey(), responseTO, userTO);
    UserPatch userPatch = AnyOperations.diff(userTO, original, true);
    List<SAML2IdPActions> actions = getActions(idp);
    for (SAML2IdPActions action : actions) {
        userPatch = action.beforeUpdate(userPatch, responseTO);
    }
    Pair<UserPatch, List<PropagationStatus>> updated = provisioningManager.update(userPatch, false);
    userTO = binder.getUserTO(updated.getLeft().getKey());
    for (SAML2IdPActions action : actions) {
        userTO = action.afterUpdate(userTO, responseTO);
    }
    return userTO.getUsername();
}
Also used : SAML2IdPActions(org.apache.syncope.core.provisioning.api.SAML2IdPActions) UserTO(org.apache.syncope.common.lib.to.UserTO) ArrayList(java.util.ArrayList) List(java.util.List) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class SuspendProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if (getAnyTypeKind() == AnyTypeKind.USER) {
        Pair<WorkflowResult<String>, Boolean> updated = (Pair<WorkflowResult<String>, Boolean>) exchange.getIn().getBody();
        // propagate suspension if and only if it is required by policy
        if (updated != null && updated.getValue()) {
            UserPatch userPatch = new UserPatch();
            userPatch.setKey(updated.getKey().getResult());
            List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(new WorkflowResult<>(Pair.of(userPatch, Boolean.FALSE), updated.getKey().getPropByRes(), updated.getKey().getPerformedTasks()));
            getPropagationTaskExecutor().execute(tasks, false);
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 54 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class CamelUserProvisioningManager method link.

@Override
public String link(final UserPatch anyPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:linkPort");
    sendMessage("direct:linkUser", anyPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(UserPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 55 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class CamelUserProvisioningManager method unlink.

@Override
public String unlink(final UserPatch userPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:unlinkPort");
    sendMessage("direct:unlinkUser", userPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(UserPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9