use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class MemberService method removePersonFromGroups.
private void removePersonFromGroups(GluuCustomPerson person) {
log.debug("Removing person from associated group before deletion");
String pesonDn = person.getDn();
// Remove person from associated groups
List<String> associatedGroupsDn = person.getMemberOf();
for (String groupDn : associatedGroupsDn) {
if (!groupService.contains(groupDn)) {
continue;
}
GluuGroup group = groupService.getGroupByDn(groupDn);
List<String> members = new ArrayList<String>(group.getMembers());
members.remove(pesonDn);
group.setMembers(members);
try {
groupService.updateGroup(group);
} catch (EntryPersistenceException ex) {
log.error("Failed to remove preson '{}' from group '{}'", ex);
}
}
log.debug("All group updated");
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class CleanUpTest method cleanUpGroups.
/**
* Test search
*
* @throws Exception
*/
// @Test
@Parameters(value = "test.keep.persons")
public void cleanUpGroups(String usedGroups) throws Exception {
System.out.println("cleanup person Test initialted ");
assertNotNull(usedGroups);
List<String> usedGroupsList = Arrays.asList(StringHelper.split(usedGroups, ",", true, false));
System.out.println("Used Groups: " + usedGroupsList);
int groupsResultSetSize = 50;
int countResults = 0;
int countRemoved = 0;
boolean existsMoreGroups = true;
while (existsMoreGroups && countResults < 10000) {
List<GluuGroup> groups = groupsService.getAllGroups();
existsMoreGroups = groups.size() == groupsResultSetSize;
countResults += groups.size();
assertNotNull(groups);
System.out.println("Found groups: " + groups.size());
System.out.println("Total groups: " + countResults);
for (GluuGroup group : groups) {
// String clientId = person.getClientId();
if (!usedGroupsList.contains(group.getInum())) {
try {
groupsService.removeGroup(group);
countRemoved++;
} catch (EntryPersistenceException ex) {
System.out.println("Failed to remove group: " + ex.getMessage());
}
}
}
}
System.out.println("Removed Persons: " + countRemoved);
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class Fido2DeviceService method findAllFido2Devices.
public List<GluuFido2Device> findAllFido2Devices(GluuCustomPerson person) {
try {
String baseDnForU2fDevices = getDnForFido2Device(null, person.getInum());
Filter inumFilter = Filter.createEqualityFilter(OxTrustConstants.PERSON_INUM, person.getInum());
return ldapEntryManager.findEntries(baseDnForU2fDevices, GluuFido2Device.class, inumFilter);
} catch (EntryPersistenceException e) {
log.warn("No fido2 devices enrolled for " + person.getDisplayName());
return new ArrayList<>();
}
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxCore by GluuFederation.
the class NativePersistenceCacheProvider method putImpl.
private void putImpl(String key, Object object, Date creationDate, int expirationInSeconds) {
Calendar expirationDate = Calendar.getInstance();
expirationDate.setTime(creationDate);
expirationDate.add(Calendar.SECOND, expirationInSeconds);
String originalKey = key;
key = hashKey(key);
NativePersistenceCacheEntity entity = new NativePersistenceCacheEntity();
entity.setTtl(expirationInSeconds);
entity.setData(asString(object));
entity.setId(key);
entity.setDn(createDn(key));
entity.setCreationDate(creationDate);
entity.setExpirationDate(expirationDate.getTime());
entity.setDeletable(true);
try {
if (attemptUpdateBeforeInsert) {
entryManager.merge(entity);
} else {
if (!skipRemoveBeforePut) {
silentlyRemoveEntityIfExists(entity.getDn());
}
entryManager.persist(entity);
}
} catch (EntryPersistenceException e) {
if (e.getCause() instanceof DuplicateEntryException) {
// on duplicate, remove entry and try to persist again
try {
silentlyRemoveEntityIfExists(entity.getDn());
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
if (attemptUpdateBeforeInsert) {
try {
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
} catch (Exception e) {
// log as trace since it is perfectly valid that entry is removed by timer for example
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
}
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class GroupService method isMemberOrOwner.
/*
* (non-Javadoc)
*
* @see
* org.gluu.oxtrust.ldap.service.IGroupService#isMemberOrOwner(java.lang.String,
* java.lang.String)
*/
@Override
public boolean isMemberOrOwner(String groupDN, String personDN) {
Filter ownerFilter = Filter.createEqualityFilter(OxTrustConstants.owner, personDN);
Filter memberFilter = Filter.createEqualityFilter(OxTrustConstants.member, personDN);
Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
boolean isMemberOrOwner = false;
try {
isMemberOrOwner = persistenceEntryManager.findEntries(groupDN, GluuGroup.class, searchFilter, 1).size() > 0;
} catch (EntryPersistenceException ex) {
log.error("Failed to determine if person '{}' memeber or owner of group '{}'", personDN, groupDN, ex);
}
return isMemberOrOwner;
}
Aggregations