Search in sources :

Example 16 with UPlainAttr

use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.

the class PlainAttrTest method saveWithEnum.

@Test
public void saveWithEnum() throws ClassNotFoundException {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    assertNotNull(user);
    PlainSchema gender = plainSchemaDAO.find("gender");
    assertNotNull(gender);
    assertNotNull(gender.getType());
    assertNotNull(gender.getEnumerationValues());
    UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
    attribute.setOwner(user);
    attribute.setSchema(gender);
    user.add(attribute);
    Exception thrown = null;
    try {
        attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNotNull(thrown);
    attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    InvalidEntityException iee = null;
    try {
        userDAO.save(user);
    } catch (InvalidEntityException e) {
        iee = e;
    }
    assertNull(iee);
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ValidationException(javax.validation.ValidationException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ValidationException(javax.validation.ValidationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 17 with UPlainAttr

use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.

the class PlainAttrTest method delete.

@Test
public void delete() {
    UPlainAttr attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
    String attrSchemaName = attribute.getSchema().getKey();
    plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class);
    PlainSchema schema = plainSchemaDAO.find(attrSchemaName);
    assertNotNull(schema);
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 18 with UPlainAttr

use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.

the class RoleTest method dynMembership.

@Test
public void dynMembership() {
    // 0. create user matching the condition below
    User user = entityFactory.newEntity(User.class);
    user.setUsername("username");
    user.setRealm(realmDAO.findByFullPath("/even/two"));
    user.add(anyTypeClassDAO.find("other"));
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(plainSchemaDAO.find("cool"));
    attr.add("true", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    user.add(attr);
    user = userDAO.save(user);
    String newUserKey = user.getKey();
    assertNotNull(newUserKey);
    // 1. create role with dynamic membership
    Role role = entityFactory.newEntity(Role.class);
    role.setKey("new");
    role.add(realmDAO.getRoot());
    role.add(realmDAO.findByFullPath("/even/two"));
    role.getEntitlements().add(StandardEntitlement.LOG_LIST);
    role.getEntitlements().add(StandardEntitlement.LOG_SET_LEVEL);
    DynRoleMembership dynMembership = entityFactory.newEntity(DynRoleMembership.class);
    dynMembership.setFIQLCond("cool==true");
    dynMembership.setRole(role);
    role.setDynMembership(dynMembership);
    Role actual = roleDAO.save(role);
    assertNotNull(actual);
    roleDAO.flush();
    // 2. verify that dynamic membership is there
    actual = roleDAO.find(actual.getKey());
    assertNotNull(actual);
    assertNotNull(actual.getDynMembership());
    assertNotNull(actual.getDynMembership().getKey());
    assertEquals(actual, actual.getDynMembership().getRole());
    // 3. verify that expected users have the created role dynamically assigned
    List<String> members = roleDAO.findDynMembers(actual);
    assertEquals(2, members.size());
    assertEquals(new HashSet<>(Arrays.asList("c9b2dec2-00a7-4855-97c0-d854842b4b24", newUserKey)), new HashSet<>(members));
    user = userDAO.find("c9b2dec2-00a7-4855-97c0-d854842b4b24");
    assertNotNull(user);
    Collection<Role> dynRoleMemberships = findDynRoles(user);
    assertEquals(1, dynRoleMemberships.size());
    assertTrue(dynRoleMemberships.contains(actual.getDynMembership().getRole()));
    // 4. delete the new user and verify that dynamic membership was updated
    userDAO.delete(newUserKey);
    userDAO.flush();
    actual = roleDAO.find(actual.getKey());
    members = roleDAO.findDynMembers(actual);
    assertEquals(1, members.size());
    assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", members.get(0));
    // 5. delete role and verify that dynamic membership was also removed
    String dynMembershipKey = actual.getDynMembership().getKey();
    roleDAO.delete(actual);
    roleDAO.flush();
    assertNull(entityManager().find(JPADynRoleMembership.class, dynMembershipKey));
    dynRoleMemberships = findDynRoles(user);
    assertTrue(dynRoleMemberships.isEmpty());
}
Also used : Role(org.apache.syncope.core.persistence.api.entity.Role) User(org.apache.syncope.core.persistence.api.entity.user.User) JPADynRoleMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPADynRoleMembership) DynRoleMembership(org.apache.syncope.core.persistence.api.entity.user.DynRoleMembership) JPADynRoleMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPADynRoleMembership) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)18 User (org.apache.syncope.core.persistence.api.entity.user.User)13 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)13 Test (org.junit.jupiter.api.Test)13 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)10 Transactional (org.springframework.transaction.annotation.Transactional)5 InvalidEntityException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException)4 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)4 Group (org.apache.syncope.core.persistence.api.entity.group.Group)4 Date (java.util.Date)3 List (java.util.List)3 UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Optional (java.util.Optional)2 ValidationException (javax.validation.ValidationException)2 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)2 InvalidPlainAttrValueException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)2 UPlainAttrValue (org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue)2 URelationship (org.apache.syncope.core.persistence.api.entity.user.URelationship)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2