Search in sources :

Example 21 with EntryPersistenceException

use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class ClientService method updateAccessTime.

public void updateAccessTime(Client client, boolean isUpdateLogonTime) {
    if (!appConfiguration.getUpdateClientAccessTime()) {
        return;
    }
    String clientDn = client.getDn();
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(clientDn);
    customEntry.setCustomObjectClasses(CLIENT_OBJECT_CLASSES);
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttributeLastAccessTime = new CustomAttribute("oxLastAccessTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
    if (isUpdateLogonTime) {
        CustomAttribute customAttributeLastLogonTime = new CustomAttribute("oxLastLogonTime", nowDateString);
        customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
    }
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastAccessTime and oxLastLogonTime of client '{}'", clientDn);
    }
    removeFromCache(client);
}
Also used : CustomEntry(org.gluu.persist.model.base.CustomEntry) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 22 with EntryPersistenceException

use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class CookieService method removeOutdatedCurrentSessions.

private void removeOutdatedCurrentSessions(Set<String> currentSessions, SessionId session) {
    if (session != null) {
        final String oldSessionId = session.getSessionAttributes().get(SessionId.OLD_SESSION_ID_ATTR_KEY);
        if (StringUtils.isNotBlank(oldSessionId)) {
            currentSessions.remove(oldSessionId);
        }
    }
    if (currentSessions.isEmpty()) {
        return;
    }
    // avoid cycle dependency
    SessionIdService sessionIdService = CdiUtil.bean(SessionIdService.class);
    Set<String> toRemove = Sets.newHashSet();
    for (String sessionId : currentSessions) {
        SessionId sessionIdObject = null;
        try {
            sessionIdObject = sessionIdService.getSessionId(sessionId, true);
        } catch (EntryPersistenceException e) {
        // ignore - valid case if session is outdated
        }
        if (sessionIdObject == null) {
            toRemove.add(sessionId);
        }
    }
    currentSessions.removeAll(toRemove);
}
Also used : EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) SessionId(org.gluu.oxauth.model.common.SessionId)

Example 23 with EntryPersistenceException

use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class UserGroupService method isUserInGroupOrMember.

public boolean isUserInGroupOrMember(String groupDn, String personDn) {
    Filter ownerFilter = Filter.createEqualityFilter("owner", personDn);
    Filter memberFilter = Filter.createEqualityFilter("member", personDn);
    Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
    boolean isMemberOrOwner = false;
    try {
        isMemberOrOwner = ldapEntryManager.findEntries(groupDn, UserGroup.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;
}
Also used : Filter(org.gluu.search.filter.Filter) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) UserGroup(org.gluu.oxauth.model.ldap.UserGroup)

Example 24 with EntryPersistenceException

use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class StatService method setupCurrentEntry.

private void setupCurrentEntry(Date now) {
    final String month = PERIOD_DATE_FORMAT.format(now);
    // jansId=<id>,ou=yyyyMM,ou=stat,o=gluu
    String dn = String.format("jansId=%s,%s", nodeId, monthlyDn);
    if (currentEntry != null && month.equals(currentEntry.getStat().getMonth())) {
        return;
    }
    try {
        StatEntry entryFromPersistence = entryManager.find(StatEntry.class, dn);
        if (entryFromPersistence != null && month.equals(entryFromPersistence.getStat().getMonth())) {
            hll = HLL.fromBytes(Base64.getDecoder().decode(entryFromPersistence.getUserHllData()));
            tokenCounters = new ConcurrentHashMap<>(entryFromPersistence.getStat().getTokenCountPerGrantType());
            currentEntry = entryFromPersistence;
            log.trace("Stat entry loaded.");
            return;
        }
    } catch (EntryPersistenceException e) {
        log.trace("Stat entry is not found in persistence.");
    }
    if (currentEntry == null) {
        log.trace("Creating stat entry ...");
        hll = newHll();
        tokenCounters = new ConcurrentHashMap<>();
        currentEntry = new StatEntry();
        currentEntry.setId(nodeId);
        currentEntry.setDn(dn);
        currentEntry.setUserHllData(Base64.getEncoder().encodeToString(hll.toBytes()));
        currentEntry.getStat().setMonth(PERIOD_DATE_FORMAT.format(new Date()));
        entryManager.persist(currentEntry);
        log.trace("Created stat entry. nodeId:" + nodeId);
    }
}
Also used : StatEntry(org.gluu.oxauth.model.stat.StatEntry) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) Date(java.util.Date)

Example 25 with EntryPersistenceException

use of org.gluu.persist.exception.EntryPersistenceException in project oxAuth by GluuFederation.

the class StatService method createBranch.

public void createBranch(String branchDn, String ou) {
    try {
        SimpleBranch branch = new SimpleBranch();
        branch.setOrganizationalUnitName(ou);
        branch.setDn(branchDn);
        entryManager.persist(branch);
    } catch (EntryPersistenceException ex) {
        // Check if another process added this branch already
        if (!entryManager.contains(branchDn, SimpleBranch.class)) {
            throw ex;
        }
    }
}
Also used : SimpleBranch(org.gluu.persist.model.base.SimpleBranch) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

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