use of org.apache.syncope.common.lib.to.PlainSchemaTO 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.PlainSchemaTO 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.PlainSchemaTO in project syncope by apache.
the class SCIMConfManager method set.
@PreAuthorize("hasRole('" + SCIMEntitlement.SCIM_CONF_SET + "')")
public void set(final SCIMConf conf) {
try {
schemaLogic.read(SchemaType.PLAIN, SCIMConf.KEY);
} catch (NotFoundException e) {
PlainSchemaTO scimConf = new PlainSchemaTO();
scimConf.setKey(SCIMConf.KEY);
scimConf.setType(AttrSchemaType.Binary);
scimConf.setMimeType(MediaType.APPLICATION_JSON);
schemaLogic.create(SchemaType.PLAIN, scimConf);
}
conf.setLastChangeDate(new Date());
configurationLogic.set(new AttrTO.Builder().schema(SCIMConf.KEY).value(Base64.encode(POJOHelper.serialize(conf).getBytes())).build());
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class ParametersDirectoryPanel method getColumns.
@Override
protected List<IColumn<AttrTO, String>> getColumns() {
final List<IColumn<AttrTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("schema"), "schema"));
columns.add(new PropertyColumn<AttrTO, String>(new ResourceModel("values"), "values") {
private static final long serialVersionUID = -1822504503325964706L;
@Override
public void populateItem(final Item<ICellPopulator<AttrTO>> item, final String componentId, final IModel<AttrTO> rowModel) {
PlainSchemaTO modelSchemaTO = (PlainSchemaTO) rowModel.getObject().getSchemaInfo();
AttrSchemaType type = modelSchemaTO.getType();
if (type == AttrSchemaType.Binary || type == AttrSchemaType.Encrypted) {
item.add(new Label(componentId, type.name()).add(new AttributeModifier("style", "font-style:italic")));
} else {
super.populateItem(item, componentId, rowModel);
}
}
});
return columns;
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class ParametersCreateWizardPanel method onApplyInternal.
@Override
protected Serializable onApplyInternal(final ParametersForm modelObject) {
final PlainSchemaTO plainSchemaTO = modelObject.getPlainSchemaTO();
plainSchemaTO.setKey(modelObject.getAttrTO().getSchema());
schemaRestClient.create(SchemaType.PLAIN, plainSchemaTO);
try {
confRestClient.set(modelObject.getAttrTO());
} catch (Exception e) {
LOG.error("While setting {}, removing {}", modelObject.getAttrTO(), plainSchemaTO, e);
schemaRestClient.deletePlainSchema(plainSchemaTO.getKey());
throw e;
}
return modelObject.getAttrTO();
}
Aggregations