Skip to content

Commit

Permalink
fix: cb ttl update sdk 3 (#2434)
Browse files Browse the repository at this point in the history
* fix: CB SDK 3.x duration expiration max value can be 18 250 days

* chore: merge samples

Co-authored-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
  • Loading branch information
yuremm and yurem authored Sep 21, 2022
1 parent 74e5476 commit 534c6cb
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.couchbase;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jans.orm.couchbase.impl.CouchbaseEntryManager;
import io.jans.orm.couchbase.operation.impl.CouchbaseConnectionProvider;
import io.jans.orm.model.base.SimpleUser;
import io.jans.orm.search.filter.Filter;

/**
* @author Yuriy Movchan Date: 11/03/2016
*/
public final class CouchbaseAuthenticationSample {

private static final Logger LOG = LoggerFactory.getLogger(CouchbaseConnectionProvider.class);

private CouchbaseAuthenticationSample() {
}

public static void main(String[] args) {
// Prepare sample connection details
CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();

// Create Couchbase entry manager
CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();

List<SimpleUser> users = couchbaseEntryManager.findEntries("ou=people,o=gluu", SimpleUser.class, null);
for (SimpleUser user : users) {
LOG.info("User with uid: '{}' with DN: '{}'", user.getUserId(), user.getDn());
}

boolean authenticated = couchbaseEntryManager.authenticate("ou=people,o=gluu", SimpleUser.class, "test_user", "test_user_password");
LOG.info("User with uid: '{}' with DN: '{}'", "test_user", authenticated);

Filter userUidFilter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), "test_user");
List<SimpleUser> foundUsers = couchbaseEntryManager.findEntries("ou=people,o=gluu", SimpleUser.class, userUidFilter);
if (foundUsers.size() > 0) {
SimpleUser user = foundUsers.get(0);
LOG.info("Found uid: '{}' with custom attributes: '{}'", user.getUserId(), user.getCustomAttributes());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ protected CouchbaseEntryManager(CouchbaseOperationService operationService) {
protected <T> Integer getExpirationValue(Object entry, Class<T> entryClass, boolean merge) {
Integer value = super.getExpirationValue(entry, entryClass, merge);

// if expiration is more then 30 days we must convert it to absolute Unit time stamp to avoid immediate expiration https://docs.couchbase.com/java-sdk/current/concept-docs/documents.html#setting-document-expiration
if (value != null && value >= EXPIRATION_30_DAYS) {
final int now = (int) (System.currentTimeMillis() / 1000);
value = now + value;
}

return value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.sql;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.jans.orm.search.filter.Filter;
import io.jans.orm.sql.impl.SqlEntryManager;
import io.jans.orm.sql.model.SimpleGroup;
import io.jans.orm.sql.operation.impl.SqlConnectionProvider;
import io.jans.orm.sql.persistence.SqlEntryManagerSample;

/**
* @author Yuriy Movchan Date: 01/15/2020
*/
public final class SqlCheckGroupSample {

private static final Logger LOG = LoggerFactory.getLogger(SqlConnectionProvider.class);

private SqlCheckGroupSample() {
}

public static void main(String[] args) {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();

// Create SQL entry manager
SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();

// EQ -- String
Filter searchFilter = Filter.create("(&(dn=inum=60B7,ou=groups,o=gluu)(|(owner=inum=78c0ea07-d9db-4ccd-9039-4911a6426a0c,ou=people,o=gluu)(member=inum=78c0ea07-d9db-4ccd-9039-4911a6426a0c,ou=people,o=gluu)))");

boolean isMemberOrOwner = sqlEntryManager.findEntries("inum=60B7,ou=groups,o=gluu", SimpleGroup.class, searchFilter, 1).size() > 0;
System.out.println(isMemberOrOwner);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.sql.model;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.orm.sql.operation;

import java.util.HashMap;
Expand Down

0 comments on commit 534c6cb

Please sign in to comment.