Search in sources :

Example 46 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

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(io.jans.orm.exception.EntryPersistenceException) Client(io.jans.as.common.model.registration.Client) Parameters(org.testng.annotations.Parameters) BaseComponentTest(io.jans.as.server.BaseComponentTest) Test(org.testng.annotations.Test)

Example 47 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

the class JansPersistenceService method getExpiredObject.

public ExpiredObject getExpiredObject(String key) {
    try {
        ExpiredObject expiredObject = (ExpiredObject) this.persistenceEntryManager.find(getDnForExpiredObj(key), ExpiredObject.class, null);
        if (expiredObject != null) {
            expiredObject.setType(ExpiredObjectType.fromValue(expiredObject.getTypeString()));
            LOG.debug("Found ExpiredObject id: {} , ExpiredObject : {} ", key, expiredObject);
            return expiredObject;
        }
        LOG.error("Failed to fetch ExpiredObject by id: {} ", key);
        return null;
    } catch (Exception e) {
        if (((e instanceof EntryPersistenceException)) && (e.getMessage().contains("Failed to find entry"))) {
            LOG.warn("Failed to fetch ExpiredObject by id: {}. {} ", key, e.getMessage());
            return null;
        }
        LOG.error("Failed to fetch ExpiredObject by id: {} ", key, e);
    }
    return null;
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) ExpiredObject(io.jans.ca.common.ExpiredObject) SQLException(java.sql.SQLException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 48 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

the class JansPersistenceService method getRps.

public Set<Rp> getRps() {
    try {
        List<RpObject> rpObjects = this.persistenceEntryManager.findEntries(String.format("%s,%s", new Object[] { getRpOu(), getClientApiDn() }), RpObject.class, null);
        Set<Rp> result = new HashSet();
        for (RpObject ele : rpObjects) {
            Rp rp = MigrationService.parseRp(ele.getData());
            if (rp != null) {
                result.add(rp);
            } else {
                LOG.error("Failed to parse rp, id: {}, dn: {} ", ele.getId(), ele.getDn());
            }
        }
        return result;
    } catch (Exception e) {
        if (((e instanceof EntryPersistenceException)) && (e.getMessage().contains("Failed to find entries"))) {
            LOG.warn("Failed to fetch RpObjects. {} ", e.getMessage());
            return null;
        }
        LOG.error("Failed to fetch rps. Error: {} ", e.getMessage(), e);
    }
    return null;
}
Also used : RpObject(io.jans.ca.server.persistence.modal.RpObject) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) RpObject(io.jans.ca.server.persistence.modal.RpObject) ExpiredObject(io.jans.ca.common.ExpiredObject) Rp(io.jans.ca.server.service.Rp) SQLException(java.sql.SQLException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 49 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

the class CouchbaseEntryManager method findEntriesImpl.

protected <T> PagedResult<JsonObject> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    String[] currentLdapReturnAttributes = ldapReturnAttributes;
    if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
        currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
    }
    Filter searchFilter;
    if (objectClasses.length > 0) {
        LOG.trace("Filter: {}", filter);
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    // Find entries
    LOG.trace("-------------------------------------------------------");
    LOG.trace("Filter: {}", filter);
    LOG.trace("objectClasses count: {} ", objectClasses.length);
    LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare default sort
    Sort[] defaultSort = getDefaultSort(entryClass);
    if (StringHelper.isNotEmpty(sortBy)) {
        Sort requestedSort = buildSort(sortBy, sortOrder);
        if (ArrayHelper.isEmpty(defaultSort)) {
            defaultSort = new Sort[] { requestedSort };
        } else {
            defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
        }
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toCouchbaseKey(baseDN);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
    }
    PagedResult<JsonObject> searchResult = null;
    try {
        CouchbaseBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new CouchbaseBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
        if (searchResult == null) {
            throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression));
        }
        return searchResult;
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) MappingException(io.jans.orm.exception.MappingException) DateTimeException(java.time.DateTimeException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) DateTimeParseException(java.time.format.DateTimeParseException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) Sort(com.couchbase.client.java.query.dsl.Sort)

Example 50 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

the class CouchbaseUpateMissingEntrySample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample sqlSampleEntryManager = new CouchbaseEntryManagerSample();
    // Create SQL entry manager
    CouchbaseEntryManager sqlEntryManager = sqlSampleEntryManager.createCouchbaseEntryManager();
    String sessionId = UUID.randomUUID().toString();
    final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
    final SimpleSessionState simpleSessionState = new SimpleSessionState();
    simpleSessionState.setDn(sessionDn);
    simpleSessionState.setId(sessionId);
    simpleSessionState.setLastUsedAt(new Date());
    try {
        sqlEntryManager.merge(simpleSessionState);
        System.out.println("Updated");
    } catch (EntryPersistenceException ex) {
        LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
    }
}
Also used : SimpleSessionState(io.jans.orm.couchbase.model.SimpleSessionState) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date)

Aggregations

EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)61 SearchException (io.jans.orm.exception.operation.SearchException)33 AuthenticationException (io.jans.orm.exception.AuthenticationException)31 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)30 MappingException (io.jans.orm.exception.MappingException)30 Filter (io.jans.orm.search.filter.Filter)24 AttributeData (io.jans.orm.model.AttributeData)16 DateTimeParseException (java.time.format.DateTimeParseException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)13 ParsedKey (io.jans.orm.impl.model.ParsedKey)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)10 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)9 JsonObject (com.couchbase.client.java.document.json.JsonObject)8 ConnectionException (io.jans.orm.exception.operation.ConnectionException)8 ParseException (java.text.ParseException)8 DateTimeException (java.time.DateTimeException)7 List (java.util.List)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)6 EntryData (io.jans.orm.model.EntryData)6