use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class AbstractAnyLogic method beforeDelete.
protected Pair<TO, List<LogicActions>> beforeDelete(final TO input) {
Realm realm = realmDAO.findByFullPath(input.getRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add(input.getRealm());
throw sce;
}
TO any = input;
List<LogicActions> actions = getActions(realm);
for (LogicActions action : actions) {
any = action.beforeDelete(any);
}
LOG.debug("Input: {}\nOutput: {}\n", input, any);
return ImmutablePair.of(any, actions);
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPAAnySearchDAO method getQuery.
private String getQuery(final AssignableCond cond, final List<Object> parameters, final SearchSupport svs) {
Realm realm;
try {
realm = check(cond);
} catch (IllegalArgumentException e) {
return EMPTY_QUERY;
}
StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").append(svs.field().name).append(" WHERE (");
if (cond.isFromGroup()) {
realmDAO.findDescendants(realm).forEach(current -> {
query.append("realm_id=?").append(setParameter(parameters, current.getKey())).append(" OR ");
});
query.setLength(query.length() - 4);
} else {
for (Realm current = realm; current.getParent() != null; current = current.getParent()) {
query.append("realm_id=?").append(setParameter(parameters, current.getKey())).append(" OR ");
}
query.append("realm_id=?").append(setParameter(parameters, realmDAO.getRoot().getKey()));
}
query.append(')');
return query.toString();
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPAAnySearchDAO method getAdminRealmsFilter.
private Pair<String, Set<String>> getAdminRealmsFilter(final Set<String> adminRealms, final SearchSupport svs, final List<Object> parameters) {
Set<String> realmKeys = new HashSet<>();
Set<String> dynRealmKeys = new HashSet<>();
RealmUtils.normalize(adminRealms).forEach(realmPath -> {
if (realmPath.startsWith("/")) {
Realm realm = realmDAO.findByFullPath(realmPath);
if (realm == null) {
SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
noRealm.getElements().add("Invalid realm specified: " + realmPath);
throw noRealm;
} else {
realmKeys.addAll(realmDAO.findDescendants(realm).stream().map(r -> r.getKey()).collect(Collectors.toSet()));
}
} else {
DynRealm dynRealm = dynRealmDAO.find(realmPath);
if (dynRealm == null) {
LOG.warn("Ignoring invalid dynamic realm {}", realmPath);
} else {
dynRealmKeys.add(dynRealm.getKey());
}
}
});
if (!dynRealmKeys.isEmpty()) {
realmKeys.addAll(realmDAO.findAll().stream().map(r -> r.getKey()).collect(Collectors.toSet()));
}
StringBuilder adminRealmFilter = new StringBuilder("u.any_id IN (").append("SELECT any_id FROM ").append(svs.field().name).append(" WHERE realm_id IN (SELECT id AS realm_id FROM Realm");
boolean firstRealm = true;
for (String realmKey : realmKeys) {
if (firstRealm) {
adminRealmFilter.append(" WHERE");
firstRealm = false;
} else {
adminRealmFilter.append(" OR");
}
adminRealmFilter.append(" id=?").append(setParameter(parameters, realmKey));
}
adminRealmFilter.append("))");
return Pair.of(adminRealmFilter.toString(), dynRealmKeys);
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPAGroupDAO method countByRealm.
@Override
public Map<String, Integer> countByRealm() {
Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM " + JPAGroup.class.getSimpleName() + " e GROUP BY e.realm");
@SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
return results.stream().collect(Collectors.toMap(result -> ((Realm) result[0]).getFullPath(), result -> ((Number) result[1]).intValue()));
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class JPAUserDAO method getPasswordPolicies.
private List<PasswordPolicy> getPasswordPolicies(final User user) {
List<PasswordPolicy> policies = new ArrayList<>();
PasswordPolicy policy;
// add resource policies
for (ExternalResource resource : findAllResources(user)) {
policy = resource.getPasswordPolicy();
if (policy != null) {
policies.add(policy);
}
}
// add realm policies
for (Realm realm : realmDAO().findAncestors(user.getRealm())) {
policy = realm.getPasswordPolicy();
if (policy != null) {
policies.add(policy);
}
}
return policies;
}
Aggregations