use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class CleanUpClientTest method cleanUpClient.
@Test
@Parameters(value = "usedClients")
public void cleanUpClient(String usedClients) {
Assert.assertNotNull(usedClients);
List<String> usedClientsList = Arrays.asList(StringHelper.split(usedClients, ",", true, false));
output("Used clients: " + usedClientsList);
int clientsResultSetSize = 50;
int countResults = 0;
int countRemoved = 0;
boolean existsMoreClients = true;
while (existsMoreClients && countResults < 10000) {
List<Client> clients = clientService.getAllClients(new String[] { "inum" }, clientsResultSetSize);
existsMoreClients = clients.size() == clientsResultSetSize;
countResults += clients.size();
Assert.assertNotNull(clients);
output("Found clients: " + clients.size());
output("Total clients: " + countResults);
for (Client client : clients) {
String clientId = client.getClientId();
if (!usedClientsList.contains(clientId)) {
try {
clientService.remove(client);
} catch (EntryPersistenceException ex) {
output("Failed to remove client: " + ex.getMessage());
}
countRemoved++;
}
}
}
output("Removed clients: " + countRemoved);
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class SessionIdService method mergeWithRetry.
private void mergeWithRetry(final SessionId sessionId) {
final Pair<Date, Integer> expiration = expirationDate(sessionId.getCreationDate(), sessionId.getState());
sessionId.setExpirationDate(expiration.getFirst());
sessionId.setTtl(expiration.getSecond());
EntryPersistenceException lastException = null;
for (int i = 1; i <= MAX_MERGE_ATTEMPTS; i++) {
try {
if (appConfiguration.getSessionIdPersistInCache()) {
cacheService.put(expiration.getSecond(), sessionId.getDn(), sessionId);
} else {
persistenceEntryManager.merge(sessionId);
}
localCacheService.put(DEFAULT_LOCAL_CACHE_EXPIRATION, sessionId.getDn(), sessionId);
externalEvent(new SessionEvent(SessionEventType.UPDATED, sessionId));
return;
} catch (EntryPersistenceException ex) {
lastException = ex;
if (ex.getCause() instanceof LDAPException) {
LDAPException parentEx = ((LDAPException) ex.getCause());
log.debug("LDAP exception resultCode: '{}'", parentEx.getResultCode().intValue());
if ((parentEx.getResultCode().intValue() == ResultCode.NO_SUCH_ATTRIBUTE_INT_VALUE) || (parentEx.getResultCode().intValue() == ResultCode.ATTRIBUTE_OR_VALUE_EXISTS_INT_VALUE)) {
log.warn("Session entry update attempt '{}' was unsuccessfull", i);
continue;
}
}
throw ex;
}
}
log.error("Session entry update attempt was unsuccessfull after '{}' attempts", MAX_MERGE_ATTEMPTS);
throw lastException;
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.
the class AuthenticationService method updateLastLogonUserTime.
private void updateLastLogonUserTime(User user) {
if (!appConfiguration.getUpdateUserLastLogonTime()) {
return;
}
CustomEntry customEntry = new CustomEntry();
customEntry.setDn(user.getDn());
List<String> personCustomObjectClassList = appConfiguration.getPersonCustomObjectClassList();
if ((personCustomObjectClassList != null) && !personCustomObjectClassList.isEmpty()) {
// Combine object classes from LDAP and configuration in one list
Set<Object> customPersonCustomObjectClassList = new HashSet<Object>();
customPersonCustomObjectClassList.add("gluuPerson");
customPersonCustomObjectClassList.addAll(personCustomObjectClassList);
if (user.getCustomObjectClasses() != null) {
customPersonCustomObjectClassList.addAll(Arrays.asList(user.getCustomObjectClasses()));
}
customEntry.setCustomObjectClasses(customPersonCustomObjectClassList.toArray(new String[customPersonCustomObjectClassList.size()]));
} else {
customEntry.setCustomObjectClasses(UserService.USER_OBJECT_CLASSES);
}
Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
CustomAttribute customAttribute = new CustomAttribute("oxLastLogonTime", nowDateString);
customEntry.getCustomAttributes().add(customAttribute);
try {
ldapEntryManager.merge(customEntry);
} catch (EntryPersistenceException epe) {
log.error("Failed to update oxLastLogonTime of user '{}'", user.getUserId());
}
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class CacheRefreshTimer method updateTargetEntryViaCopy.
private boolean updateTargetEntryViaCopy(GluuSimplePerson sourcePerson, String targetInum, String[] targetCustomObjectClasses, Map<String, String> targetServerAttributesMapping) {
String targetPersonDn = personService.getDnForPerson(targetInum);
GluuCustomPerson targetPerson = null;
boolean updatePerson;
if (personService.contains(targetPersonDn)) {
try {
targetPerson = personService.findPersonByDn(targetPersonDn);
log.debug("Found person by inum '{}'", targetInum);
} catch (EntryPersistenceException ex) {
log.error("Failed to find person '{}'", targetInum, ex);
return false;
}
updatePerson = true;
} else {
targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
updatePerson = false;
}
targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
targetPerson.setSourceServerUserDn(sourcePerson.getDn());
cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
// Execute interceptor script
boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
if (!executionResult) {
log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
return false;
}
try {
if (updatePerson) {
personService.updatePerson(targetPerson);
log.debug("Updated person '{}'", targetInum);
} else {
personService.addPerson(targetPerson);
log.debug("Added new person '{}'", targetInum);
}
} catch (Exception ex) {
log.error("Failed to '{}' person '{}'", updatePerson ? "update" : "add", targetInum, ex);
return false;
}
return true;
}
use of org.gluu.persist.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class ImportPersonConfiguration method prepareAttributes.
private List<GluuAttribute> prepareAttributes() throws Exception {
List<GluuAttribute> result = new ArrayList<GluuAttribute>();
List<ImportPerson> mappings = configurationFactory.getImportPersonConfig().getMappings();
Iterator<ImportPerson> it = mappings.iterator();
while (it.hasNext()) {
ImportPerson importPerson = (ImportPerson) it.next();
String attributeName = importPerson.getLdapName();
boolean required = importPerson.getRequired();
if (StringHelper.isNotEmpty(attributeName)) {
GluuAttribute attr = null;
try {
attr = attributeService.getAttributeByName(attributeName);
} catch (EntryPersistenceException ex) {
log.error("Failed to load attribute '{}' definition from LDAP", attributeName, ex);
}
if (attr == null) {
log.warn("Failed to find attribute '{}' definition in LDAP", attributeName);
attr = createAttributeFromConfig(importPerson);
if (attr == null) {
log.error("Failed to find attribute '{}' definition in '{}'", attributeName, GLUU_IMPORT_PERSON_PROPERTIES_FILE);
continue;
}
} else {
attr.setRequred(required);
}
result.add(attr);
}
// }
}
return result;
}
Aggregations