Search in sources :

Example 16 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.

the class AuthenticationITCase method userSchemaAuthorization.

@Test
public void userSchemaAuthorization() {
    String schemaName = "authTestSchema" + getUUIDString();
    // 1. create a schema (as admin)
    PlainSchemaTO schemaTO = new PlainSchemaTO();
    schemaTO.setKey(schemaName);
    schemaTO.setMandatoryCondition("false");
    schemaTO.setType(AttrSchemaType.String);
    PlainSchemaTO newPlainSchemaTO = createSchema(SchemaType.PLAIN, schemaTO);
    assertEquals(schemaTO, newPlainSchemaTO);
    // 2. create an user with the role created above (as admin)
    UserTO userTO = UserITCase.getUniqueSampleTO("auth@test.org");
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // 3. read the schema created above (as admin) - success
    schemaTO = schemaService.read(SchemaType.PLAIN, schemaName);
    assertNotNull(schemaTO);
    // 4. read the schema created above (as user) - success
    SchemaService schemaService2 = clientFactory.create(userTO.getUsername(), "password123").getService(SchemaService.class);
    schemaTO = schemaService2.read(SchemaType.PLAIN, schemaName);
    assertNotNull(schemaTO);
    // 5. update the schema create above (as user) - failure
    try {
        schemaService2.update(SchemaType.PLAIN, schemaTO);
        fail("Schema update as user should not work");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    assertEquals(0, getFailedLogins(userService, userTO.getKey()));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) ForbiddenException(javax.ws.rs.ForbiddenException) SchemaService(org.apache.syncope.common.rest.api.service.SchemaService) UserTO(org.apache.syncope.common.lib.to.UserTO) Test(org.junit.jupiter.api.Test)

Example 17 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.

the class ConfigurationITCase method create.

@Test
public void create() {
    PlainSchemaTO testKey = new PlainSchemaTO();
    testKey.setKey("testKey" + getUUIDString());
    testKey.setType(AttrSchemaType.String);
    createSchema(SchemaType.PLAIN, testKey);
    AttrTO conf = new AttrTO.Builder().schema(testKey.getKey()).value("testValue").build();
    configurationService.set(conf);
    AttrTO actual = configurationService.get(conf.getSchema());
    actual.setSchemaInfo(null);
    assertEquals(actual, conf);
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Test(org.junit.jupiter.api.Test)

Example 18 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.

the class ConfigurationITCase method issueSYNCOPE418.

@Test
public void issueSYNCOPE418() {
    PlainSchemaTO failing = new PlainSchemaTO();
    failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
    failing.setType(AttrSchemaType.String);
    try {
        createSchema(SchemaType.PLAIN, failing);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
        assertNotNull(e.getElements());
        assertEquals(1, e.getElements().size());
        assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 19 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.

the class PlainSchemaITCase method createWithNotPermittedName.

@Test
public void createWithNotPermittedName() {
    PlainSchemaTO schemaTO = new PlainSchemaTO();
    schemaTO.setKey("failedLogins");
    schemaTO.setType(AttrSchemaType.String);
    try {
        createSchema(SchemaType.PLAIN, schemaTO);
        fail("This should not be reacheable");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
        boolean entityViolationTypeCheck = false;
        for (String element : e.getElements()) {
            if (!entityViolationTypeCheck) {
                entityViolationTypeCheck = element.contains(EntityViolationType.InvalidKey.name());
            }
        }
        assertTrue(entityViolationTypeCheck);
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 20 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.

the class PlainSchemaITCase method delete.

@Test
public void delete() {
    PlainSchemaTO schemaTO = buildPlainSchemaTO("todelete", AttrSchemaType.String);
    schemaTO.setMandatoryCondition("false");
    createSchema(SchemaType.PLAIN, schemaTO);
    schemaService.delete(SchemaType.PLAIN, schemaTO.getKey());
    PlainSchemaTO firstname = null;
    try {
        firstname = schemaService.read(SchemaType.PLAIN, schemaTO.getKey());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
    assertNull(firstname);
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

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