Search in sources :

Example 6 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseDeleteSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    String baseDn = "ou=cache,o=jans";
    Filter filter = Filter.createANDFilter(Filter.createEqualityFilter("del", true), Filter.createLessOrEqualFilter("exp", couchbaseEntryManager.encodeTime(baseDn, new Date())));
    int result = couchbaseEntryManager.remove(baseDn, DeletableEntity.class, filter, 100);
    System.out.println(result);
}
Also used : Filter(io.jans.orm.search.filter.Filter) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) Date(java.util.Date)

Example 7 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    SimpleUser newUser = new SimpleUser();
    newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
    newUser.setUserId("sample_user_" + System.currentTimeMillis());
    newUser.setUserPassword("test");
    newUser.getCustomAttributes().add(new CustomObjectAttribute("streetAddress", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("test", "test_value"));
    couchbaseEntryManager.persist(newUser);
    // SimpleUser dummyUser = couchbaseEntryManager.find(SimpleUser.class, "inum=test,o=test,o=jans");
    // LOG.info("Dummy User '{}'", dummyUser);
    // Find all users which have specified object classes defined in SimpleUser
    List<SimpleUser> users = couchbaseEntryManager.findEntries("o=@!5304.5F36.0E64.E1AC!0001!179C.62D7,o=jans", SimpleUser.class, null);
    for (SimpleUser user : users) {
        LOG.info("User with uid: '{}' with DN: '{}'", user.getUserId(), user.getDn());
    }
    if (users.size() > 0) {
        // Add attribute "streetAddress" to first user
        SimpleUser user = users.get(3);
        LOG.info("Updating: " + user.getUserId());
        String[] values = new String[] { "Somewhere: " + System.currentTimeMillis(), "Somewhere2: " + System.currentTimeMillis() };
        user.getCustomAttributes().add(new CustomObjectAttribute("streetAddress", Arrays.asList(values)));
        user.getCustomAttributes().add(new CustomObjectAttribute("test", "test_value"));
        user.getCustomAttributes().add(new CustomObjectAttribute("test2", "test_value2"));
        user.getCustomAttributes().add(new CustomObjectAttribute("test3", "test_value3"));
        user.setUserId("user1");
        user.setUserPassword("test");
        couchbaseEntryManager.merge(user);
    }
    for (SimpleUser user : users) {
        boolean result1 = couchbaseEntryManager.authenticate(user.getDn(), "test");
        boolean result2 = couchbaseEntryManager.authenticate("ou=people,o=jans", SimpleUser.class, user.getUserId(), "test");
        System.out.println("authetication result: " + result1 + ", " + result2);
    }
    Filter filter = Filter.createEqualityFilter("status", "active");
    List<SimpleAttribute> attributes = couchbaseEntryManager.findEntries("o=jans", SimpleAttribute.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
    for (SimpleAttribute attribute : attributes) {
        LOG.info("Attribute with displayName: " + attribute.getCustomAttributes().get(1));
    }
    List<SimpleSession> sessions = couchbaseEntryManager.findEntries("o=jans", SimpleSession.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
    LOG.info("Found sessions: " + sessions.size());
    List<SimpleGrant> grants = couchbaseEntryManager.findEntries("o=jans", SimpleGrant.class, null, SearchScope.SUB, new String[] { "grtId" }, null, 1, 0, 0);
    LOG.info("Found grants: " + grants.size());
    try {
        PagedResult<SimpleUser> listViewResponse = couchbaseEntryManager.findPagedEntries("o=jans", SimpleUser.class, null, new String[] { "uid", "displayName", "status" }, "uid", SortOrder.ASCENDING, 0, 6, 4);
        LOG.info("Found persons: " + listViewResponse.getEntriesCount() + ", total persons: " + listViewResponse.getTotalEntriesCount());
        for (SimpleUser user : listViewResponse.getEntries()) {
            System.out.println(user.getUserId());
        }
    } catch (Exception ex) {
        LOG.info("Failed to search", ex);
    }
    try {
        PagedResult<SimpleUser> listViewResponse = couchbaseEntryManager.findPagedEntries("o=jans", SimpleUser.class, null, new String[] { "uid", "displayName", "status" }, "uid", SortOrder.DESCENDING, 0, 6, 4);
        LOG.info("Found persons: " + listViewResponse.getEntriesCount() + ", total persons: " + listViewResponse.getTotalEntriesCount());
        for (SimpleUser user : listViewResponse.getEntries()) {
            System.out.println(user.getUserId());
        }
    } catch (Exception ex) {
        LOG.info("Failed to search", ex);
    }
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.couchbase.model.SimpleUser) SimpleAttribute(io.jans.orm.couchbase.model.SimpleAttribute) SimpleGrant(io.jans.orm.couchbase.model.SimpleGrant) Filter(io.jans.orm.search.filter.Filter) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) SimpleSession(io.jans.orm.couchbase.model.SimpleSession)

Example 8 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class UmaResourceSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager entryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    final Filter filter = Filter.createEqualityFilter("jansAssociatedClnt", "inum=AB77-1A2B,ou=clients,o=jans");
    List<UmaResource> umaResource = entryManager.findEntries("ou=resources,ou=uma,o=jans", UmaResource.class, filter);
    LOG.info("Found umaResources: " + umaResource);
}
Also used : Filter(io.jans.orm.search.filter.Filter) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) UmaResource(io.jans.orm.couchbase.model.UmaResource)

Example 9 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseUpdateAttributeSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    String uid = "sample_user_" + System.currentTimeMillis();
    String dn = String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis());
    SimpleUser newUser = new SimpleUser();
    newUser.setDn(dn);
    newUser.setUserId(uid);
    newUser.setUserPassword("test");
    couchbaseEntryManager.persist(newUser);
    SimpleUser user = couchbaseEntryManager.find(SimpleUser.class, dn);
    LOG.info("Found user '{}'", user);
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(user.getDn());
    customEntry.setCustomObjectClasses(new String[] { "jansPerson" });
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    String nowDateString = couchbaseEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttribute = new CustomAttribute("jansLastLogonTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttribute);
    couchbaseEntryManager.merge(customEntry);
    SimpleUser userAfterUpdate = couchbaseEntryManager.find(SimpleUser.class, dn);
    LOG.info("Found user after update '{}'", userAfterUpdate);
}
Also used : SimpleUser(io.jans.orm.couchbase.model.SimpleUser) CustomEntry(io.jans.orm.model.base.CustomEntry) CustomAttribute(io.jans.orm.model.base.CustomAttribute) GregorianCalendar(java.util.GregorianCalendar) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) Date(java.util.Date)

Example 10 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class ManualCouchbaseEntryManagerTest method sample.

// manual
@Test(enabled = false)
public void sample() throws IOException {
    CouchbaseEntryManager manager = createCouchbaseEntryManager();
    try {
        List<SimpleClient> attributeList = manager.findEntries("o=jans", SimpleClient.class, null);
        System.out.println(attributeList);
    } finally {
        manager.destroy();
    }
}
Also used : CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) SimpleClient(io.jans.orm.couchbase.model.SimpleClient) Test(org.testng.annotations.Test)

Aggregations

CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)16 Filter (io.jans.orm.search.filter.Filter)8 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)5 Date (java.util.Date)5 CouchbaseEntryManagerFactory (io.jans.orm.couchbase.impl.CouchbaseEntryManagerFactory)3 CustomAttribute (io.jans.orm.model.base.CustomAttribute)3 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)3 SimpleClient (io.jans.orm.couchbase.model.SimpleClient)2 SimpleSession (io.jans.orm.couchbase.model.SimpleSession)2 SimpleSessionState (io.jans.orm.couchbase.model.SimpleSessionState)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.testng.annotations.Test)2 Lookup (com.couchbase.client.core.message.kv.subdoc.multi.Lookup)1 Bucket (com.couchbase.client.java.Bucket)1 JsonDocument (com.couchbase.client.java.document.JsonDocument)1 SubdocOptionsBuilder (com.couchbase.client.java.subdoc.SubdocOptionsBuilder)1 SimpleAttribute (io.jans.orm.couchbase.model.SimpleAttribute)1 SimpleCustomStringUser (io.jans.orm.couchbase.model.SimpleCustomStringUser)1