Search in sources :

Example 71 with User

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

the class AnySearchTest method issueSYNCOPE95.

@Test
public void issueSYNCOPE95() {
    for (Group group : groupDAO.findAll(1, 100)) {
        groupDAO.delete(group.getKey());
    }
    groupDAO.flush();
    AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
    coolLeafCond.setSchema("cool");
    coolLeafCond.setExpression("true");
    SearchCond cond = SearchCond.getLeafCond(coolLeafCond);
    assertTrue(cond.isValid());
    List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(1, users.size());
    assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", users.get(0).getKey());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 72 with User

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

the class DynRealmTest method misc.

@Test
public void misc() {
    DynRealm dynRealm = entityFactory.newEntity(DynRealm.class);
    dynRealm.setKey("/name");
    DynRealmMembership memb = entityFactory.newEntity(DynRealmMembership.class);
    memb.setDynRealm(dynRealm);
    memb.setAnyType(anyTypeDAO.findUser());
    memb.setFIQLCond("cool==true");
    dynRealm.add(memb);
    memb.setDynRealm(dynRealm);
    // invalid key (starts with /)
    try {
        dynRealmDAO.save(dynRealm);
        fail("This should not happen");
    } catch (Exception e) {
        assertNotNull(e);
    }
    dynRealm.setKey("name");
    DynRealm actual = dynRealmDAO.save(dynRealm);
    assertNotNull(actual);
    dynRealmDAO.flush();
    DynRealmCond dynRealmCond = new DynRealmCond();
    dynRealmCond.setDynRealm(actual.getKey());
    List<User> matching = searchDAO.search(SearchCond.getLeafCond(dynRealmCond), AnyTypeKind.USER);
    assertNotNull(matching);
    assertFalse(matching.isEmpty());
    User user = matching.get(0);
    assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(dynRealmCond)));
    assertTrue(userDAO.findDynRealms(user.getKey()).contains(actual.getKey()));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) DynRealmCond(org.apache.syncope.core.persistence.api.dao.search.DynRealmCond) DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 73 with User

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

the class RoleTest method delete.

@Test
public void delete() {
    // 0. create role
    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);
    role = roleDAO.save(role);
    assertNotNull(role);
    // 1. create user and assign that role
    User user = entityFactory.newEntity(User.class);
    user.setUsername("username");
    user.setRealm(realmDAO.findByFullPath("/even/two"));
    user.add(role);
    user = userDAO.save(user);
    assertNotNull(user);
    // 2. remove role
    roleDAO.delete(role);
    userDAO.flush();
    // 3. verify that role was removed from user
    user = userDAO.find(user.getKey());
    assertNotNull(user);
    assertTrue(user.getRoles().isEmpty());
}
Also used : Role(org.apache.syncope.core.persistence.api.entity.Role) User(org.apache.syncope.core.persistence.api.entity.user.User) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 74 with User

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

the class CustomJWTSSOProvider method resolve.

@Transactional(readOnly = true)
@Override
public Pair<User, Set<SyncopeGrantedAuthority>> resolve(final JwtClaims jwtClaims) {
    AttributeCond userIdCond = new AttributeCond();
    userIdCond.setSchema("userId");
    userIdCond.setType(AttributeCond.Type.EQ);
    userIdCond.setExpression(jwtClaims.getSubject());
    List<User> matching = searchDAO.search(SearchCond.getLeafCond(userIdCond), AnyTypeKind.USER);
    if (matching.size() == 1) {
        User user = matching.get(0);
        Set<SyncopeGrantedAuthority> authorities = authDataAccessor.getAuthorities(user.getUsername());
        return Pair.of(user, authorities);
    }
    return null;
}
Also used : SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Transactional(org.springframework.transaction.annotation.Transactional)

Example 75 with User

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

the class GoogleAppsPullActions method afterAll.

@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
    googleAppsIds.forEach((key, value) -> {
        User user = userDAO.find(key);
        if (user == null) {
            LOG.error("Could not find user {}, skipping", key);
        } else {
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // 1. stores the __UID__ received by Google
            PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
            if (googleAppsId == null) {
                LOG.error("Could not find schema googleAppsId, skipping");
            } else {
                UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(googleAppsId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(value, anyUtils);
                        userDAO.save(user);
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
                    }
                } else {
                    LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
                }
            }
        }
    });
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (org.apache.syncope.core.persistence.api.entity.user.User)135 Test (org.junit.jupiter.api.Test)58 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)56 Transactional (org.springframework.transaction.annotation.Transactional)39 Group (org.apache.syncope.core.persistence.api.entity.group.Group)24 ArrayList (java.util.ArrayList)20 UserTO (org.apache.syncope.common.lib.to.UserTO)20 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)20 HashSet (java.util.HashSet)18 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)17 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)17 List (java.util.List)16 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)16 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Set (java.util.Set)14 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)14 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)14 Collections (java.util.Collections)11 Collectors (java.util.stream.Collectors)11