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());
}
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()));
}
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());
}
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;
}
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());
}
}
}
});
}
Aggregations