Search in sources :

Example 6 with EntryPersistenceException

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);
}
Also used : EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) Client(org.gluu.oxauth.model.registration.Client) Parameters(org.testng.annotations.Parameters) BaseComponentTest(org.gluu.oxauth.BaseComponentTest) Test(org.testng.annotations.Test)

Example 7 with EntryPersistenceException

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;
}
Also used : SessionEvent(org.gluu.oxauth.service.external.session.SessionEvent) LDAPException(com.unboundid.ldap.sdk.LDAPException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 8 with EntryPersistenceException

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());
    }
}
Also used : CustomEntry(org.gluu.persist.model.base.CustomEntry) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 9 with EntryPersistenceException

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;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) SearchException(org.gluu.persist.exception.operation.SearchException) SocketException(java.net.SocketException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException)

Example 10 with EntryPersistenceException

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;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) ImportPerson(org.gluu.config.oxtrust.ImportPerson) GluuAttribute(org.gluu.model.GluuAttribute)

Aggregations

EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)25 Client (org.gluu.oxauth.model.registration.Client)6 ArrayList (java.util.ArrayList)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)3 AcrChangedException (org.gluu.oxauth.model.exception.AcrChangedException)3 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)3 GluuGroup (org.gluu.oxtrust.model.GluuGroup)3 Filter (org.gluu.search.filter.Filter)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Response (javax.ws.rs.core.Response)2 OAuth2AuditLog (org.gluu.oxauth.model.audit.OAuth2AuditLog)2 SessionId (org.gluu.oxauth.model.common.SessionId)2 ClientAuthorization (org.gluu.oxauth.model.ldap.ClientAuthorization)2 JsonWebResponse (org.gluu.oxauth.model.token.JsonWebResponse)2 ExternalPostAuthnContext (org.gluu.oxauth.service.external.context.ExternalPostAuthnContext)2 CustomAttribute (org.gluu.persist.model.base.CustomAttribute)2