Search in sources :

Example 11 with EntryPersistenceException

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

Example 12 with EntryPersistenceException

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);
}
Also used : EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Parameters(org.testng.annotations.Parameters)

Example 13 with EntryPersistenceException

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<>();
    }
}
Also used : Filter(org.gluu.search.filter.Filter) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 14 with EntryPersistenceException

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);
    }
}
Also used : Calendar(java.util.Calendar) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Example 15 with EntryPersistenceException

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;
}
Also used : Filter(org.gluu.search.filter.Filter) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

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