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);
}
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);
}
}
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);
}
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);
}
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();
}
}
Aggregations