Search in sources :

Example 31 with PlainSchemaTO

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());
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) Test(org.junit.jupiter.api.Test)

Example 32 with PlainSchemaTO

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()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 33 with PlainSchemaTO

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());
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 34 with PlainSchemaTO

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;
}
Also used : ArrayList(java.util.ArrayList) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Label(org.apache.wicket.markup.html.basic.Label) AttributeModifier(org.apache.wicket.AttributeModifier) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) StringResourceModel(org.apache.wicket.model.StringResourceModel) ResourceModel(org.apache.wicket.model.ResourceModel)

Example 35 with PlainSchemaTO

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();
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO)

Aggregations

PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)39 Test (org.junit.jupiter.api.Test)26 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)19 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)11 UserTO (org.apache.syncope.common.lib.to.UserTO)9 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 Set (java.util.Set)4 StandardCharsets (java.nio.charset.StandardCharsets)3 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 SchemaService (org.apache.syncope.common.rest.api.service.SchemaService)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 ListIterator (java.util.ListIterator)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2