Search in sources :

Example 1 with SimpleBranch

use of io.jans.orm.model.base.SimpleBranch in project jans by JanssenProject.

the class PairwiseIdentifierService method addBranch.

public void addBranch(final String userInum) {
    SimpleBranch branch = new SimpleBranch();
    branch.setOrganizationalUnitName("pairwiseIdentifiers");
    branch.setDn(getBaseDnForPairwiseIdentifiers(userInum));
    ldapEntryManager.persist(branch);
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch)

Example 2 with SimpleBranch

use of io.jans.orm.model.base.SimpleBranch in project jans by JanssenProject.

the class MetricService method removeExpiredMetricEntries.

public void removeExpiredMetricEntries(final Date expirationDate, final ApplicationType applicationType, int count, int chunkSize) {
    createApplicationBaseBranch(applicationType);
    final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, expirationDate, new Date());
    // Remove expired entries
    for (final String baseDnForPeriod : keepBaseDnForPeriod) {
        DefaultBatchOperation<MetricEntry> metricEntryBatchOperation = new DefaultBatchOperation<MetricEntry>() {

            @Override
            public boolean collectSearchResult(int size) {
                return false;
            }

            @Override
            public void performAction(List<MetricEntry> entries) {
                for (MetricEntry metricEntry : entries) {
                    remove(metricEntry);
                }
            }
        };
        getExpiredMetricEntries(metricEntryBatchOperation, applicationType, baseDnForPeriod, expirationDate, count, chunkSize);
    }
    if (!getEntryManager().hasBranchesSupport(buildDn(null, null, applicationType))) {
        DefaultBatchOperation<SimpleBranch> batchOperation = new DefaultBatchOperation<SimpleBranch>() {

            @Override
            public boolean collectSearchResult(int size) {
                return false;
            }

            @Override
            public void performAction(List<SimpleBranch> objects) {
                String baseDn = buildDn(null, null, applicationType);
                Set<String> periodBranchesStrings = new HashSet<String>();
                for (SimpleBranch periodBranch : objects) {
                    if (!StringHelper.equalsIgnoreCase(baseDn, periodBranch.getDn())) {
                        periodBranchesStrings.add(periodBranch.getDn());
                    }
                }
                periodBranchesStrings.removeAll(keepBaseDnForPeriod);
                // Remove expired months
                for (String baseDnForPeriod : periodBranchesStrings) {
                    removeBranch(baseDnForPeriod);
                }
            }
        };
        findAllPeriodBranches(batchOperation, applicationType, count, chunkSize);
    }
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch) MetricEntry(io.jans.model.metric.ldap.MetricEntry) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation)

Example 3 with SimpleBranch

use of io.jans.orm.model.base.SimpleBranch in project jans by JanssenProject.

the class UmaResourceService method addBranch.

public void addBranch() {
    SimpleBranch branch = new SimpleBranch();
    branch.setOrganizationalUnitName("resources");
    branch.setDn(getDnForResource(null));
    persistenceEntryManager.persist(branch);
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch)

Example 4 with SimpleBranch

use of io.jans.orm.model.base.SimpleBranch in project jans by JanssenProject.

the class NativePersistenceCacheProvider method create.

@Override
public void create() {
    try {
        baseDn = cacheConfiguration.getNativePersistenceConfiguration().getBaseDn();
        deleteExpiredOnGetRequest = cacheConfiguration.getNativePersistenceConfiguration().isDeleteExpiredOnGetRequest();
        if (StringUtils.isBlank(baseDn)) {
            log.error("Failed to create NATIVE_PERSISTENCE cache provider. 'baseDn' in CacheConfiguration is not initialized. It has to be set by client application (e.g. oxAuth has to set it in ApplicationFactory.)");
            throw new RuntimeException("Failed to create NATIVE_PERSISTENCE cache provider. 'baseDn' in CacheConfiguration is not initialized. It has to be set by client application.");
        }
        String branchDn = String.format("ou=cache,%s", baseDn);
        if (entryManager.hasBranchesSupport(branchDn)) {
            if (!entryManager.contains(branchDn, SimpleBranch.class)) {
                SimpleBranch branch = new SimpleBranch();
                branch.setOrganizationalUnitName("cache");
                branch.setDn(branchDn);
                entryManager.persist(branch);
            }
        }
        baseDn = branchDn;
        cacheConfiguration.getNativePersistenceConfiguration().setBaseDn(baseDn);
        String persistenceType = entryManager.getPersistenceType(baseDn);
        // CouchbaseEntryManagerFactory.PERSISTENCE_TYPE
        skipRemoveBeforePut = "couchbase".equals(persistenceType);
        attemptUpdateBeforeInsert = "sql".equals(persistenceType);
        log.info("Created NATIVE_PERSISTENCE cache provider. `baseDn`: " + baseDn);
    } catch (Exception e) {
        log.error("Failed to create NATIVE_PERSISTENCE cache provider.", e);
        throw new RuntimeException("Failed to create NATIVE_PERSISTENCE cache provider.", e);
    }
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Example 5 with SimpleBranch

use of io.jans.orm.model.base.SimpleBranch in project jans by JanssenProject.

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(io.jans.orm.model.base.SimpleBranch) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException)

Aggregations

SimpleBranch (io.jans.orm.model.base.SimpleBranch)16 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 ProcessBatchOperation (io.jans.orm.model.ProcessBatchOperation)2 List (java.util.List)2 Fido2AuthenticationEntry (io.jans.fido2.model.entry.Fido2AuthenticationEntry)1 Fido2RegistrationEntry (io.jans.fido2.model.entry.Fido2RegistrationEntry)1 MetricEntry (io.jans.model.metric.ldap.MetricEntry)1 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)1 SearchException (io.jans.orm.exception.operation.SearchException)1 DefaultBatchOperation (io.jans.orm.model.DefaultBatchOperation)1