use of org.apache.syncope.core.persistence.api.entity.DynRealm in project syncope by apache.
the class DynRealmLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.DYNREALM_DELETE + "')")
public DynRealmTO delete(final String key) {
DynRealm dynRealm = dynRealmDAO.find(key);
if (dynRealm == null) {
LOG.error("Could not find dynamic realm '" + key + "'");
throw new NotFoundException(key);
}
DynRealmTO deleted = binder.getDynRealmTO(dynRealm);
dynRealmDAO.delete(key);
return deleted;
}
use of org.apache.syncope.core.persistence.api.entity.DynRealm 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.DynRealm in project syncope by apache.
the class AbstractAnyDAO method findDynRealms.
@Transactional(readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<String> findDynRealms(final String key) {
Query query = entityManager().createNativeQuery("SELECT dynRealm_id FROM " + JPADynRealmDAO.DYNMEMB_TABLE + " WHERE any_id=?");
query.setParameter(1, key);
List<String> result = new ArrayList<>();
query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered((actualKey) -> {
DynRealm dynRealm = dynRealmDAO().find(actualKey.toString());
if (dynRealm == null) {
LOG.error("Could not find dynRealm with id {}, even though returned by the native query", actualKey);
} else if (!result.contains(actualKey.toString())) {
result.add(actualKey.toString());
}
});
return result;
}
use of org.apache.syncope.core.persistence.api.entity.DynRealm in project syncope by apache.
the class JPADynRealmDAO method delete.
@Override
public void delete(final String key) {
DynRealm dynRealm = find(key);
if (dynRealm == null) {
return;
}
clearDynMembers(dynRealm);
entityManager().remove(dynRealm);
}
Aggregations