Search in sources :

Example 1 with SimpleCustomStringUser

use of io.jans.orm.cloud.spanner.model.SimpleCustomStringUser in project jans by JanssenProject.

the class SpannerCustomStringAttributesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    String randomExternalUid = "" + System.currentTimeMillis();
    // String randomExternalUid = "otp:" + System.currentTimeMillis();
    // Add dummy user
    SimpleCustomStringUser newUser = new SimpleCustomStringUser();
    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 CustomAttribute("address", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add((new CustomAttribute("jansExtUid", randomExternalUid)).multiValued());
    newUser.setUserRole(UserRole.ADMIN);
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    sqlEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    // Find added dummy user but use custom class with String values
    SimpleCustomStringUser foundUser = sqlEntryManager.find(SimpleCustomStringUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    for (CustomAttribute customAttribute : foundUser.getCustomAttributes()) {
        LOG.info("Found custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
    }
    // Find by jsExternalUid
    Filter jsExternalUidFilter = Filter.createEqualityFilter("jansExtUid", randomExternalUid).multiValued();
    List<SimpleCustomStringUser> foundUsers = sqlEntryManager.findEntries("ou=people,o=jans", SimpleCustomStringUser.class, jsExternalUidFilter);
    for (SimpleCustomStringUser foundUser2 : foundUsers) {
        LOG.info("Found User '{}' by jansExtUid with uid '{}' and key '{}'", foundUser2, foundUser2.getUserId(), foundUser2.getDn());
    }
}
Also used : Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) CustomAttribute(io.jans.orm.model.base.CustomAttribute) SimpleCustomStringUser(io.jans.orm.cloud.spanner.model.SimpleCustomStringUser) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Aggregations

SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)1 SimpleCustomStringUser (io.jans.orm.cloud.spanner.model.SimpleCustomStringUser)1 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)1 CustomAttribute (io.jans.orm.model.base.CustomAttribute)1 Filter (io.jans.orm.search.filter.Filter)1