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"));
}
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();
}
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);
}
}
}
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();
}
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();
}
Aggregations