Search in sources :

Example 11 with CustomObjectAttribute

use of org.gluu.persist.model.base.CustomObjectAttribute in project oxAuth by GluuFederation.

the class UserService method removeUserAttribute.

public User removeUserAttribute(String userId, String attributeName, String attributeValue) {
    log.debug("Remove user attribute from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
    User user = getUser(userId);
    if (user == null) {
        return null;
    }
    CustomObjectAttribute customAttribute = getCustomAttribute(user, attributeName);
    if (customAttribute != null) {
        List<Object> currentAttributeValues = customAttribute.getValues();
        if (currentAttributeValues.contains(attributeValue)) {
            List<Object> newAttributeValues = new ArrayList<Object>();
            newAttributeValues.addAll(currentAttributeValues);
            if (currentAttributeValues.contains(attributeValue)) {
                newAttributeValues.remove(attributeValue);
            } else {
                return null;
            }
            customAttribute.setValues(newAttributeValues);
        }
    }
    return updateUser(user);
}
Also used : CustomObjectAttribute(org.gluu.persist.model.base.CustomObjectAttribute) User(org.gluu.oxauth.model.common.User) ArrayList(java.util.ArrayList)

Aggregations

CustomObjectAttribute (org.gluu.persist.model.base.CustomObjectAttribute)11 User (org.gluu.oxauth.model.common.User)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)1 SimpleUser (org.gluu.oxauth.model.common.SimpleUser)1