Search in sources :

Example 1 with CustomObjectAttribute

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

the class User method setAttribute.

public void setAttribute(String attributeName, String attributeValue, Boolean multiValued) {
    CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
    if (multiValued != null) {
        attribute.setMultiValued(multiValued);
    }
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 2 with CustomObjectAttribute

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

the class User method setAttribute.

public void setAttribute(String attributeName, String[] attributeValues, Boolean multiValued) {
    CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, Arrays.asList(attributeValues));
    if (multiValued != null) {
        attribute.setMultiValued(multiValued);
    }
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 3 with CustomObjectAttribute

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

the class User method setAttribute.

public void setAttribute(String attributeName, List<String> attributeValues, Boolean multiValued) {
    CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValues);
    if (multiValued != null) {
        attribute.setMultiValued(multiValued);
    }
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 4 with CustomObjectAttribute

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

the class UserService method getUniqueUserByAttributes.

public User getUniqueUserByAttributes(List<String> attributeNames, String attributeValue) {
    log.debug("Getting user information from LDAP: attributeNames = '{}', attributeValue = '{}'", attributeNames, attributeValue);
    if (attributeNames != null) {
        for (String attributeName : attributeNames) {
            User searchUser = new User();
            searchUser.setDn(getPeopleBaseDn());
            List<CustomObjectAttribute> customAttributes = new ArrayList<>();
            customAttributes.add(new CustomObjectAttribute(attributeName, attributeValue));
            searchUser.setCustomAttributes(customAttributes);
            try {
                List<User> entries = persistenceEntryManager.findEntries(searchUser);
                log.debug(Constants.LOG_FOUND, entries.size());
                if (entries.size() == 1) {
                    return entries.get(0);
                } else if (entries.size() > 1) {
                    break;
                }
            } catch (Exception e) {
                log.debug(e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArrayList(java.util.ArrayList)

Example 5 with CustomObjectAttribute

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

the class UserService method addUserAttribute.

public boolean addUserAttribute(User user, String attributeName, Object attributeValue, Boolean multiValued) {
    CustomObjectAttribute customAttribute = getCustomAttribute(user, attributeName);
    if (customAttribute == null) {
        customAttribute = new CustomObjectAttribute(attributeName, attributeValue);
        user.getCustomAttributes().add(customAttribute);
    } else {
        List<Object> currentAttributeValues = customAttribute.getValues();
        List<Object> newAttributeValues = new ArrayList<>();
        newAttributeValues.addAll(currentAttributeValues);
        if (newAttributeValues.contains(attributeValue)) {
            return false;
        } else {
            newAttributeValues.add(attributeValue);
        }
        customAttribute.setValues(newAttributeValues);
    }
    if (multiValued != null) {
        customAttribute.setMultiValued(multiValued);
    }
    return true;
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) ArrayList(java.util.ArrayList)

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