use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.
the class AnySearchTest method groupOrderBy.
@Test
public void groupOrderBy() {
AnyCond idLeafCond = new AnyCond(AnyCond.Type.LIKE);
idLeafCond.setSchema("name");
idLeafCond.setExpression("%r");
SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
assertTrue(searchCondition.isValid());
OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("name");
List<Group> groups = searchDAO.search(searchCondition, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.GROUP), groups.size());
}
use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.
the class AnySearchTest method searchByGroupNameAndKey.
@Test
public void searchByGroupNameAndKey() {
AnyCond groupNameLeafCond = new AnyCond(AnyCond.Type.EQ);
groupNameLeafCond.setSchema("name");
groupNameLeafCond.setExpression("root");
AnyCond idRightCond = new AnyCond(AnyCond.Type.EQ);
idRightCond.setSchema("id");
idRightCond.setExpression("37d15e4c-cdc1-460b-a591-8505c8133806");
SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupNameLeafCond), SearchCond.getLeafCond(idRightCond));
assertTrue(searchCondition.isValid());
List<Group> matching = searchDAO.search(searchCondition, AnyTypeKind.GROUP);
assertNotNull(matching);
assertEquals(1, matching.size());
assertEquals("root", matching.iterator().next().getName());
assertEquals("37d15e4c-cdc1-460b-a591-8505c8133806", matching.iterator().next().getKey());
}
use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.
the class DefaultRealmPullResultHandler method delete.
private List<ProvisioningReport> delete(final SyncDelta delta, final List<String> keys) throws JobExecutionException {
if (!profile.getTask().isPerformDelete()) {
LOG.debug("PullTask not configured for delete");
finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to delete {}", keys);
List<ProvisioningReport> results = new ArrayList<>();
for (String key : keys) {
Object output;
Result resultStatus = Result.FAILURE;
ProvisioningReport result = new ProvisioningReport();
try {
result.setKey(key);
result.setOperation(ResourceOperation.DELETE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
Realm realm = realmDAO.find(key);
RealmTO before = binder.getRealmTO(realm, true);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Realm '%s' not found", key));
} else {
result.setName(before.getFullPath());
}
if (!profile.isDryRun()) {
for (PullActions action : profile.getActions()) {
action.beforeDelete(profile, delta, before);
}
try {
if (!realmDAO.findChildren(realm).isEmpty()) {
throw SyncopeClientException.build(ClientExceptionType.HasChildren);
}
Set<String> adminRealms = Collections.singleton(realm.getFullPath());
AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
keyCond.setSchema("key");
SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
if (users + groups + anyObjects > 0) {
SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
containedAnys.getElements().add(users + " user(s)");
containedAnys.getElements().add(groups + " group(s)");
containedAnys.getElements().add(anyObjects + " anyObject(s)");
throw containedAnys;
}
PropagationByResource propByRes = new PropagationByResource();
for (String resource : realm.getResourceKeys()) {
propByRes.add(ResourceOperation.DELETE, resource);
}
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
taskExecutor.execute(tasks, false);
realmDAO.delete(realm);
output = null;
resultStatus = Result.SUCCESS;
for (PullActions action : profile.getActions()) {
action.after(profile, delta, before, result);
}
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not delete {}", realm, e);
output = e;
}
finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta);
}
results.add(result);
} catch (DelegatedAdministrationException e) {
LOG.error("Not allowed to read Realm {}", key, e);
} catch (Exception e) {
LOG.error("Could not delete Realm {}", key, e);
}
}
return results;
}
use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.
the class SearchCondVisitor method createAttributeCond.
public AttributeCond createAttributeCond(final String schema) {
AttributeCond attributeCond = null;
if (schemaEquals(Resource.User, "userName", schema)) {
attributeCond = new AnyCond();
attributeCond.setSchema("username");
} else if (resource == Resource.Group && schemaEquals(Resource.Group, "displayName", schema)) {
attributeCond = new AnyCond();
attributeCond.setSchema("name");
} else if (schemaEquals(null, "meta.created", schema)) {
attributeCond = new AnyCond();
attributeCond.setSchema("creationDate");
} else if (schemaEquals(null, "meta.lastModified", schema)) {
attributeCond = new AnyCond();
attributeCond.setSchema("lastChangeDate");
}
if (resource == Resource.User) {
if (conf.getUserConf() != null) {
if (conf.getUserConf().getName() != null) {
for (Map.Entry<String, String> entry : conf.getUserConf().getName().asMap().entrySet()) {
if (schemaEquals(Resource.User, "name." + entry.getKey(), schema)) {
attributeCond = new AttributeCond();
attributeCond.setSchema(entry.getValue());
}
}
}
for (Map.Entry<String, String> entry : conf.getUserConf().asMap().entrySet()) {
if (schemaEquals(Resource.User, entry.getKey(), schema)) {
attributeCond = new AttributeCond();
attributeCond.setSchema(entry.getValue());
}
}
for (SCIMUserAddressConf address : conf.getUserConf().getAddresses()) {
for (Map.Entry<String, String> entry : address.asMap().entrySet()) {
if (schemaEquals(Resource.User, "addresses." + entry.getKey(), schema)) {
attributeCond = new AttributeCond();
attributeCond.setSchema(entry.getValue());
}
}
}
}
if (conf.getEnterpriseUserConf() != null) {
for (Map.Entry<String, String> entry : conf.getEnterpriseUserConf().asMap().entrySet()) {
if (schemaEquals(Resource.EnterpriseUser, entry.getKey(), schema)) {
attributeCond = new AttributeCond();
attributeCond.setSchema(entry.getValue());
}
}
if (conf.getEnterpriseUserConf().getManager() != null && conf.getEnterpriseUserConf().getManager().getKey() != null) {
attributeCond = new AttributeCond();
attributeCond.setSchema(conf.getEnterpriseUserConf().getManager().getKey());
}
}
}
if (attributeCond == null) {
throw new IllegalArgumentException("Could not match " + schema + " for " + resource);
}
return attributeCond;
}
use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.
the class RealmLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
Realm realm = realmDAO.findByFullPath(fullPath);
if (realm == null) {
LOG.error("Could not find realm '" + fullPath + "'");
throw new NotFoundException(fullPath);
}
if (!realmDAO.findChildren(realm).isEmpty()) {
throw SyncopeClientException.build(ClientExceptionType.HasChildren);
}
Set<String> adminRealms = Collections.singleton(realm.getFullPath());
AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
keyCond.setSchema("key");
SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
if (users + groups + anyObjects > 0) {
SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
containedAnys.getElements().add(users + " user(s)");
containedAnys.getElements().add(groups + " group(s)");
containedAnys.getElements().add(anyObjects + " anyObject(s)");
throw containedAnys;
}
PropagationByResource propByRes = new PropagationByResource();
realm.getResourceKeys().forEach(resource -> {
propByRes.add(ResourceOperation.DELETE, resource);
});
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
result.setEntity(binder.getRealmTO(realm, true));
result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
realmDAO.delete(realm);
return result;
}
Aggregations