Search in sources :

Example 16 with CustomObjectAttribute

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

the class SqlUserSearchSample method addTestUsers.

private static void addTestUsers(SqlEntryManager sqlEntryManager, int countUsers) {
    long startTime = System.currentTimeMillis();
    for (int j = 137; j <= countUsers; j++) {
        String uid = "user" + j;
        /*String.format("user%06d", userUid);*/
        SimpleUser newUser = new SimpleUser();
        newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
        newUser.setUserId(uid);
        newUser.setUserPassword("topsecret" + uid);
        newUser.setUserRole(j % 2 == 0 ? UserRole.ADMIN : UserRole.USER);
        newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
        newUser.setAttributeValue("givenName", "Agent Smith");
        newUser.getCustomAttributes().add(new CustomObjectAttribute("address", Arrays.asList("London", "Texas", "Kiev")));
        newUser.getCustomAttributes().add(new CustomObjectAttribute("transientId", "transientId"));
        List<Object> jansExtUid = Arrays.asList(1, 11);
        if (j % 2 == 0) {
            jansExtUid = Arrays.asList(1, 11, 2, 22);
        } else if (j % 3 == 0) {
            jansExtUid = Arrays.asList(2, 22, 3, 33);
        } else if (j % 5 == 0) {
            jansExtUid = Arrays.asList(1, 11, 2, 22, 3, 33, 4, 44);
        }
        newUser.getCustomAttributes().add(new CustomObjectAttribute("jansExtUid", jansExtUid));
        newUser.getCustomAttributes().add(new CustomObjectAttribute("birthdate", new Date()));
        newUser.getCustomAttributes().add(new CustomObjectAttribute("jansActive", false));
        sqlEntryManager.persist(newUser);
        if (j % 1000 == 0) {
            LOG.info("Added: '{}'", j);
        }
    }
    long endTime = System.currentTimeMillis();
    long duration = (endTime - startTime) / 1000L;
    LOG.info("Duration: '{}'", duration);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.sql.model.SimpleUser) Date(java.util.Date)

Example 17 with CustomObjectAttribute

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

the class AuthenticationService method checkUserStatus.

private boolean checkUserStatus(User user) {
    CustomObjectAttribute userStatus = userService.getCustomAttribute(user, "jansStatus");
    if ((userStatus != null) && GluuStatus.ACTIVE.equals(GluuStatus.getByValue(StringHelper.toString(userStatus.getValue())))) {
        return true;
    }
    log.warn("User '{}' was disabled", user.getUserId());
    return false;
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 18 with CustomObjectAttribute

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

the class CouchbaseCustomMultiValuedTypesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    // Add dummy user
    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"));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("fuzzy", "test_value"));
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    newUser.setAttributeValue("givenName", "john");
    couchbaseEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    LOG.info("Persisted custom attributes '{}'", newUser.getCustomAttributes());
    // Find added dummy user
    SimpleUser foundUser = couchbaseEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    // Update custom attributes
    foundUser.setAttributeValues("streetAddress", Arrays.asList("London", "Texas", "Kiev", "Dublin"));
    foundUser.setAttributeValues("test", Arrays.asList("test_value_1", "test_value_2", "test_value_3", "test_value_4"));
    foundUser.setAttributeValues("fuzzy", Arrays.asList("fuzzy_value_1", "fuzzy_value_2"));
    foundUser.setAttributeValue("simple", "simple");
    CustomObjectAttribute multiValuedSingleValue = new CustomObjectAttribute("multivalued", "multivalued_single_valued");
    multiValuedSingleValue.setMultiValued(true);
    foundUser.getCustomAttributes().add(multiValuedSingleValue);
    couchbaseEntryManager.merge(foundUser);
    LOG.info("Updated custom attributes '{}'", foundUser.getCustomAttributes());
    // Find updated dummy user
    SimpleUser foundUpdatedUser = couchbaseEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUpdatedUser, foundUpdatedUser.getUserId(), foundUpdatedUser.getDn());
    LOG.info("Cusom attributes '{}'", foundUpdatedUser.getCustomAttributes());
    Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("givenName"), StringHelper.toLowerCase("jon"));
    List<SimpleUser> foundUpdatedUsers = couchbaseEntryManager.findEntries("o=jans", SimpleUser.class, filter);
    System.out.println(foundUpdatedUsers);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.couchbase.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager)

Example 19 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute 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 20 with CustomObjectAttribute

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

the class SpannerCustomMultiValuedTypesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    // Add dummy user
    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("jansOptOuts", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansExtUid", "test_value").multiValued());
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansPPID", "test_value").multiValued());
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    newUser.setAttributeValue("givenName", "john");
    sqlEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    LOG.info("Persisted custom attributes '{}'", newUser.getCustomAttributes());
    // Find added dummy user
    SimpleUser foundUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    // Dump custom attributes
    for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
        System.out.println(attr.getName() + " - " + attr.getValues());
    }
    // Update custom attributes
    foundUser.setAttributeValues("jansOptOuts", Arrays.asList("London", "Texas", "Kiev", "Dublin"));
    foundUser.setAttributeValues("jansExtUid", Arrays.asList("test_value_11", "test_value_22", "test_value_33", "test_value_44"));
    foundUser.setAttributeValues("jansExtUid", Arrays.asList(11, 22, 33, 44));
    foundUser.setAttributeValues("jansPPID", Arrays.asList("fuzzy_value_1", "fuzzy_value_2"));
    foundUser.setAttributeValue("jansGuid", "simple");
    CustomObjectAttribute multiValuedSingleValue = new CustomObjectAttribute("jansAssociatedClnt", "multivalued_single_valued");
    multiValuedSingleValue.setMultiValued(true);
    foundUser.getCustomAttributes().add(multiValuedSingleValue);
    sqlEntryManager.merge(foundUser);
    LOG.info("Updated custom attributes '{}'", foundUser.getCustomAttributes());
    // Find updated dummy user
    SimpleUser foundUpdatedUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUpdatedUser, foundUpdatedUser.getUserId(), foundUpdatedUser.getDn());
    LOG.info("Cusom attributes '{}'", foundUpdatedUser.getCustomAttributes());
    // Dump custom attributes
    for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
        System.out.println(attr.getName() + " - " + attr.getValues());
    }
    Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("givenName"), StringHelper.toLowerCase("john"));
    List<SimpleUser> foundUpdatedUsers = sqlEntryManager.findEntries("o=jans", SimpleUser.class, filter);
    System.out.println(foundUpdatedUsers);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.cloud.spanner.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Aggregations

CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)32 User (io.jans.as.common.model.common.User)12 Filter (io.jans.orm.search.filter.Filter)9 Test (org.testng.annotations.Test)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SimpleUser (io.jans.orm.cloud.spanner.model.SimpleUser)4 SimpleUser (io.jans.orm.sql.model.SimpleUser)4 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)3 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)3 CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)3 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)3 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)3 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)3 SimpleUser (io.jans.as.common.model.common.SimpleUser)1 GluuAttribute (io.jans.model.GluuAttribute)1 SimpleAttribute (io.jans.orm.cloud.spanner.model.SimpleAttribute)1 SimpleGrant (io.jans.orm.cloud.spanner.model.SimpleGrant)1 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)1