use of org.apache.syncope.common.lib.to.AnyTypeClassTO in project syncope by apache.
the class CamelRouteITCase method scriptingUpdate.
@Test
public void scriptingUpdate() {
assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
CamelRouteTO oldRoute = camelRouteService.read(AnyTypeKind.USER, "createUser");
// updating route content including new attribute management
String routeContent = "" + " <route id=\"createUser\">\n" + " <from uri=\"direct:createUser\"/>\n" + " <setProperty propertyName=\"actual\">\n" + " <simple>${body}</simple>\n" + " </setProperty>\n" + " <setBody>\n" + " <groovy>\n" + "request.body.getPlainAttr(\"camelAttribute\").get().getValues().set(0,\"true\")\n" + " return request.body\n" + " </groovy>\n" + " </setBody>\n" + " <doTry>\n" + " <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n" + " ${property.enabled},${property.storePassword})\"/>\n" + " <to uri=\"propagate:create?anyTypeKind=USER\"/>\n" + " <to uri=\"direct:createPort\"/>\n" + " <doCatch> \n" + " <exception>java.lang.RuntimeException</exception>\n" + " <handled>\n" + " <constant>false</constant>\n" + " </handled>\n" + " <to uri=\"direct:createPort\"/>\n" + " </doCatch>\n" + " </doTry>\n" + " </route> ";
try {
doUpdate(AnyTypeKind.USER, "createUser", routeContent);
// creating new schema attribute for user
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("camelAttribute");
schemaTO.setType(AttrSchemaType.String);
createSchema(SchemaType.PLAIN, schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("camelAttribute");
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
UserTO userTO = new UserTO();
userTO.setRealm(SyncopeConstants.ROOT_REALM);
userTO.getAuxClasses().add(typeClass.getKey());
String userId = getUUIDString() + "camelUser@syncope.apache.org";
userTO.setUsername(userId);
userTO.setPassword("password123");
userTO.getPlainAttrs().add(attrTO("userId", userId));
userTO.getPlainAttrs().add(attrTO("fullname", userId));
userTO.getPlainAttrs().add(attrTO("surname", userId));
userTO.getPlainAttrs().add(attrTO("camelAttribute", "false"));
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals("true", userTO.getPlainAttr("camelAttribute").get().getValues().get(0));
} finally {
doUpdate(AnyTypeKind.USER, oldRoute.getKey(), oldRoute.getContent());
}
}
use of org.apache.syncope.common.lib.to.AnyTypeClassTO in project syncope by apache.
the class ExceptionMapperITCase method uniqueSchemaConstraint.
@Test
public void uniqueSchemaConstraint() {
// 1. create an user schema with unique constraint
PlainSchemaTO schemaTO = new PlainSchemaTO();
String schemaUID = getUUIDString();
schemaTO.setKey("unique" + schemaUID);
schemaTO.setType(AttrSchemaType.String);
schemaTO.setUniqueConstraint(true);
createSchema(SchemaType.PLAIN, schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("camelAttribute" + getUUIDString());
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
// 2. create an user with mandatory attributes and unique
UserTO userTO1 = new UserTO();
userTO1.setRealm(SyncopeConstants.ROOT_REALM);
userTO1.getAuxClasses().add(typeClass.getKey());
String userId1 = getUUIDString() + "issue654_1@syncope.apache.org";
userTO1.setUsername(userId1);
userTO1.setPassword("password123");
userTO1.getPlainAttrs().add(attrTO("userId", userId1));
userTO1.getPlainAttrs().add(attrTO("fullname", userId1));
userTO1.getPlainAttrs().add(attrTO("surname", userId1));
userTO1.getPlainAttrs().add(attrTO("unique" + schemaUID, "unique" + schemaUID));
createUser(userTO1);
// 3. create an other user with mandatory attributes and unique with the same value of userTO1
UserTO userTO2 = new UserTO();
userTO2.setRealm(SyncopeConstants.ROOT_REALM);
userTO2.getAuxClasses().add(typeClass.getKey());
String userId2 = getUUIDString() + "issue654_2@syncope.apache.org";
userTO2.setUsername(userId2);
userTO2.setPassword("password123");
userTO2.getPlainAttrs().add(attrTO("userId", userId2));
userTO2.getPlainAttrs().add(attrTO("fullname", userId2));
userTO2.getPlainAttrs().add(attrTO("surname", userId2));
userTO2.getPlainAttrs().add(attrTO("unique" + schemaUID, "unique" + schemaUID));
try {
createUser(userTO2);
fail("This should not happen");
} catch (Exception e) {
String message = ERROR_MESSAGES.getProperty("errMessage.UniqueConstraintViolation");
assertEquals("EntityExists [" + message + "]", e.getMessage());
}
}
use of org.apache.syncope.common.lib.to.AnyTypeClassTO in project syncope by apache.
the class GroupITCase method createWithMandatorySchema.
@Test
public void createWithMandatorySchema() {
// 1. create a mandatory schema
PlainSchemaTO badge = new PlainSchemaTO();
badge.setKey("badge" + getUUIDString());
badge.setMandatoryCondition("true");
schemaService.create(SchemaType.PLAIN, badge);
// 2. create a group *without* an attribute for that schema: it works
GroupTO groupTO = getSampleTO("lastGroup");
assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
// 3. add the new mandatory schema to the default group type
AnyTypeTO type = anyTypeService.read(AnyTypeKind.GROUP.name());
String typeClassName = type.getClasses().get(0);
AnyTypeClassTO typeClass = anyTypeClassService.read(typeClassName);
typeClass.getPlainSchemas().add(badge.getKey());
anyTypeClassService.update(typeClass);
typeClass = anyTypeClassService.read(typeClassName);
assertTrue(typeClass.getPlainSchemas().contains(badge.getKey()));
try {
// 4. update group: failure since no values are provided and it is mandatory
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
try {
updateGroup(groupPatch);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
}
// 5. also add an actual attribute for badge - it will work
groupPatch.getPlainAttrs().add(attrAddReplacePatch(badge.getKey(), "xxxxxxxxxx"));
groupTO = updateGroup(groupPatch).getEntity();
assertNotNull(groupTO);
assertNotNull(groupTO.getPlainAttr(badge.getKey()));
} finally {
// restore the original group class
typeClass.getPlainSchemas().remove(badge.getKey());
anyTypeClassService.update(typeClass);
typeClass = anyTypeClassService.read(typeClassName);
assertFalse(typeClass.getPlainSchemas().contains(badge.getKey()));
}
}
use of org.apache.syncope.common.lib.to.AnyTypeClassTO in project syncope by apache.
the class SAML2IdPDataBinderImpl method update.
@Override
public SAML2IdP update(final SAML2IdP idp, final SAML2IdPTO idpTO) {
idp.setEntityID(idpTO.getEntityID());
idp.setName(idpTO.getName());
idp.setMetadata(Base64.getMimeDecoder().decode(idpTO.getMetadata()));
idp.setCreateUnmatching(idpTO.isCreateUnmatching());
idp.setSelfRegUnmatching(idpTO.isSelfRegUnmatching());
idp.setUpdateMatching(idpTO.isUpdateMatching());
idp.setUseDeflateEncoding(idpTO.isUseDeflateEncoding());
idp.setSupportUnsolicited(idpTO.isSupportUnsolicited());
idp.setBindingType(idpTO.getBindingType());
if (idpTO.getUserTemplate() == null) {
idp.setUserTemplate(null);
} else {
SAML2UserTemplate userTemplate = idp.getUserTemplate();
if (userTemplate == null) {
userTemplate = entityFactory.newEntity(SAML2UserTemplate.class);
userTemplate.setAnyType(anyTypeDAO.findUser());
userTemplate.setIdP(idp);
idp.setUserTemplate(userTemplate);
}
userTemplate.set(idpTO.getUserTemplate());
}
idp.getItems().clear();
AnyTypeClassTO allowedSchemas = new AnyTypeClassTO();
anyTypeDAO.findUser().getClasses().forEach(anyTypeClass -> {
allowedSchemas.getPlainSchemas().addAll(anyTypeClass.getPlainSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
allowedSchemas.getDerSchemas().addAll(anyTypeClass.getDerSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
allowedSchemas.getVirSchemas().addAll(anyTypeClass.getVirSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
});
populateItems(idpTO, idp, allowedSchemas);
idp.getActionsClassNames().clear();
idp.getActionsClassNames().addAll(idpTO.getActionsClassNames());
return saml2IdPDAO.save(idp);
}
use of org.apache.syncope.common.lib.to.AnyTypeClassTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE260.
@Test
public void issueSYNCOPE260() {
// create new virtual schema for the resource below
ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope260" + getUUIDString());
virSchema.setExtAttrName("companyName");
virSchema.setResource(RESOURCE_NAME_WS2);
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope260" + 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 user and check virtual attribute value propagation
// ----------------------------------
UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
userTO.getResources().add(RESOURCE_NAME_WS2);
ProvisioningResult<UserTO> result = createUser(userTO);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user virtual attribute and check virtual attribute value update propagation
// ----------------------------------
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// suspend/reactivate user and check virtual attribute value (unchanged)
// ----------------------------------
StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("suspended", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertEquals("active", userTO.getStatus());
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user attribute and check virtual attribute value (unchanged)
// ----------------------------------
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
result = updateUser(userPatch);
assertNotNull(result);
assertFalse(result.getPropagationStatuses().isEmpty());
assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
userTO = result.getEntity();
connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
// virtual attribute value did not change
assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
Aggregations