Search in sources :

Example 1 with ProcessBatchOperation

use of io.jans.orm.model.ProcessBatchOperation in project jans by JanssenProject.

the class CouchbaseBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    final CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    BatchOperation<SimpleTokenCouchbase> tokenCouchbaseBatchOperation = new ProcessBatchOperation<SimpleTokenCouchbase>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleTokenCouchbase> objects) {
            for (SimpleTokenCouchbase simpleTokenCouchbase : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(couchbaseEntryManager, simpleTokenCouchbase.getDn(), "exp", simpleTokenCouchbase.getAttribute("exp"));
                    simpleTokenCouchbase.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    couchbaseEntryManager.merge(simpleTokenCouchbase);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("exp");
    couchbaseEntryManager.findEntries("o=jans", SimpleTokenCouchbase.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenCouchbaseBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(couchbaseEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    couchbaseEntryManager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    couchbaseEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = couchbaseEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = couchbaseEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : SimpleTokenCouchbase(io.jans.orm.couchbase.model.SimpleTokenCouchbase) CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) List(java.util.List) SimpleClient(io.jans.orm.couchbase.model.SimpleClient) SimpleSession(io.jans.orm.couchbase.model.SimpleSession)

Example 2 with ProcessBatchOperation

use of io.jans.orm.model.ProcessBatchOperation in project jans by JanssenProject.

the class RegistrationPersistenceService method cleanup.

public void cleanup(Date now, int batchSize) {
    // Cleaning expired entries
    BatchOperation<Fido2RegistrationEntry> cleanerRegistrationBatchService = new ProcessBatchOperation<Fido2RegistrationEntry>() {

        @Override
        public void performAction(List<Fido2RegistrationEntry> entries) {
            for (Fido2RegistrationEntry p : entries) {
                log.debug("Removing Fido2 registration entry: {}, Creation date: {}", p.getChallange(), p.getCreationDate());
                try {
                    persistenceEntryManager.remove(p);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    String baseDn = getDnForUser(null);
    persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, getExpiredRegistrationFilter(baseDn), SearchScope.SUB, new String[] { "jansCodeChallenge", "creationDate" }, cleanerRegistrationBatchService, 0, 0, batchSize);
    String branchDn = getDnForUser(null);
    if (persistenceEntryManager.hasBranchesSupport(branchDn)) {
        // Cleaning empty branches
        BatchOperation<SimpleBranch> cleanerBranchBatchService = new ProcessBatchOperation<SimpleBranch>() {

            @Override
            public void performAction(List<SimpleBranch> entries) {
                for (SimpleBranch p : entries) {
                    try {
                        persistenceEntryManager.remove(p);
                    } catch (Exception e) {
                        log.error("Failed to remove entry", e);
                    }
                }
            }
        };
        persistenceEntryManager.findEntries(branchDn, SimpleBranch.class, getEmptyRegistrationBranchFilter(), SearchScope.SUB, new String[] { "ou" }, cleanerBranchBatchService, 0, 0, batchSize);
    }
}
Also used : Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) SimpleBranch(io.jans.orm.model.base.SimpleBranch) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) Fido2RuntimeException(io.jans.fido2.exception.Fido2RuntimeException)

Example 3 with ProcessBatchOperation

use of io.jans.orm.model.ProcessBatchOperation in project jans by JanssenProject.

the class LdapBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapEntryManagerSample ldapEntryManagerSample = new LdapEntryManagerSample();
    // Create LDAP entry manager
    final LdapEntryManager ldapEntryManager = ldapEntryManagerSample.createLdapEntryManager();
    BatchOperation<SimpleTokenLdap> tokenLdapBatchOperation = new ProcessBatchOperation<SimpleTokenLdap>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleTokenLdap> objects) {
            for (SimpleTokenLdap simpleTokenLdap : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, simpleTokenLdap.getDn(), "exp", simpleTokenLdap.getAttribute("exp"));
                    simpleTokenLdap.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleTokenLdap);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("exp");
    ldapEntryManager.findEntries("o=jans", SimpleTokenLdap.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenLdapBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    ldapEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = ldapEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = ldapEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : SimpleTokenLdap(io.jans.orm.ldap.model.SimpleTokenLdap) CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) LdapEntryManager(io.jans.orm.ldap.impl.LdapEntryManager) Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) SimpleClient(io.jans.orm.ldap.model.SimpleClient) SimpleSession(io.jans.orm.ldap.model.SimpleSession)

Example 4 with ProcessBatchOperation

use of io.jans.orm.model.ProcessBatchOperation in project jans by JanssenProject.

the class AuthenticationPersistenceService method cleanup.

public void cleanup(Date now, int batchSize) {
    // Cleaning expired entries
    BatchOperation<Fido2AuthenticationEntry> cleanerAuthenticationBatchService = new ProcessBatchOperation<Fido2AuthenticationEntry>() {

        @Override
        public void performAction(List<Fido2AuthenticationEntry> entries) {
            for (Fido2AuthenticationEntry p : entries) {
                log.debug("Removing Fido2 authentication entry: {}, Creation date: {}", p.getChallange(), p.getCreationDate());
                try {
                    persistenceEntryManager.remove(p);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    String baseDn = getDnForUser(null);
    persistenceEntryManager.findEntries(baseDn, Fido2AuthenticationEntry.class, getExpiredAuthenticationFilter(baseDn), SearchScope.SUB, new String[] { "jansCodeChallenge", "creationDate" }, cleanerAuthenticationBatchService, 0, 0, batchSize);
    String branchDn = getDnForUser(null);
    if (persistenceEntryManager.hasBranchesSupport(branchDn)) {
        // Cleaning empty branches
        BatchOperation<SimpleBranch> cleanerBranchBatchService = new ProcessBatchOperation<SimpleBranch>() {

            @Override
            public void performAction(List<SimpleBranch> entries) {
                for (SimpleBranch p : entries) {
                    try {
                        persistenceEntryManager.remove(p);
                    } catch (Exception e) {
                        log.error("Failed to remove entry", e);
                    }
                }
            }
        };
        persistenceEntryManager.findEntries(getDnForUser(null), SimpleBranch.class, getEmptyAuthenticationBranchFilter(), SearchScope.SUB, new String[] { "ou" }, cleanerBranchBatchService, 0, 0, batchSize);
    }
}
Also used : SimpleBranch(io.jans.orm.model.base.SimpleBranch) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) Fido2AuthenticationEntry(io.jans.fido2.model.entry.Fido2AuthenticationEntry) List(java.util.List) Fido2RuntimeException(io.jans.fido2.exception.Fido2RuntimeException)

Example 5 with ProcessBatchOperation

use of io.jans.orm.model.ProcessBatchOperation in project jans by JanssenProject.

the class SpannerBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    final SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    BatchOperation<SimpleToken> tokenSQLBatchOperation = new ProcessBatchOperation<SimpleToken>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleToken> objects) {
            for (SimpleToken simpleTokenSQL : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(sqlEntryManager, simpleTokenSQL.getDn(), "exp", simpleTokenSQL.getAttribute("exp"));
                    simpleTokenSQL.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    sqlEntryManager.merge(simpleTokenSQL);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed tokens: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("exp");
    sqlEntryManager.findEntries("o=jans", SimpleToken.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenSQLBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            int currentProcessedCount = 0;
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(sqlEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    sqlEntryManager.merge(simpleSession);
                    processedCount++;
                    currentProcessedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Currnet batch count processed sessions: " + currentProcessedCount);
            LOG.info("Total processed sessions: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    sqlEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed clients: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = sqlEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed clients: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = sqlEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) SimpleClient(io.jans.orm.cloud.spanner.model.SimpleClient) SimpleSession(io.jans.orm.cloud.spanner.model.SimpleSession) SimpleToken(io.jans.orm.cloud.spanner.model.SimpleToken) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Aggregations

ProcessBatchOperation (io.jans.orm.model.ProcessBatchOperation)8 List (java.util.List)8 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)6 Filter (io.jans.orm.search.filter.Filter)6 DefaultBatchOperation (io.jans.orm.model.DefaultBatchOperation)4 CustomAttribute (io.jans.orm.model.base.CustomAttribute)4 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)2 SimpleBranch (io.jans.orm.model.base.SimpleBranch)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Test (org.testng.annotations.Test)2 Fido2AuthenticationEntry (io.jans.fido2.model.entry.Fido2AuthenticationEntry)1 Fido2RegistrationEntry (io.jans.fido2.model.entry.Fido2RegistrationEntry)1 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)1 SimpleClient (io.jans.orm.cloud.spanner.model.SimpleClient)1 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)1 SimpleToken (io.jans.orm.cloud.spanner.model.SimpleToken)1 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)1 CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)1 SimpleClient (io.jans.orm.couchbase.model.SimpleClient)1