Search in sources :

Example 6 with CustomObjectAttribute

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

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(org.gluu.persist.model.base.CustomObjectAttribute)

Example 7 with CustomObjectAttribute

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

the class AuthenticationService method checkUserStatus.

private boolean checkUserStatus(User user) {
    CustomObjectAttribute userStatus = userService.getCustomAttribute(user, "gluuStatus");
    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(org.gluu.persist.model.base.CustomObjectAttribute)

Example 8 with CustomObjectAttribute

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

the class AuthenticationService method getUserByAttribute.

private User getUserByAttribute(PersistenceEntryManager ldapAuthEntryManager, String baseDn, String attributeName, String attributeValue) {
    log.debug("Getting user information from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
    if (StringHelper.isEmpty(attributeValue)) {
        return null;
    }
    SimpleUser sampleUser = new SimpleUser();
    sampleUser.setDn(baseDn);
    List<CustomObjectAttribute> customAttributes = new ArrayList<CustomObjectAttribute>();
    customAttributes.add(new CustomObjectAttribute(attributeName, attributeValue));
    sampleUser.setCustomAttributes(customAttributes);
    log.debug("Searching user by attributes: '{}', baseDn: '{}'", customAttributes, baseDn);
    List<User> entries = ldapAuthEntryManager.findEntries(sampleUser, 1);
    log.debug("Found '{}' entries", entries.size());
    if (entries.size() > 0) {
        SimpleUser foundUser = entries.get(0);
        return ldapAuthEntryManager.find(User.class, foundUser.getDn());
    } else {
        return null;
    }
}
Also used : CustomObjectAttribute(org.gluu.persist.model.base.CustomObjectAttribute) SimpleUser(org.gluu.oxauth.model.common.SimpleUser) SimpleUser(org.gluu.oxauth.model.common.SimpleUser) User(org.gluu.oxauth.model.common.User)

Example 9 with CustomObjectAttribute

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

the class UserService method replaceUserAttribute.

public User replaceUserAttribute(String userId, String attributeName, String oldAttributeValue, String newAttributeValue, Boolean multiValued) {
    log.debug("Replace user attribute in LDAP: attributeName = '{}', oldAttributeValue = '{}', newAttributeValue = '{}'", attributeName, oldAttributeValue, newAttributeValue);
    User user = getUser(userId);
    if (user == null) {
        return null;
    }
    CustomObjectAttribute customAttribute = getCustomAttribute(user, attributeName);
    if (customAttribute != null) {
        List<Object> currentAttributeValues = customAttribute.getValues();
        List<Object> newAttributeValues = new ArrayList<Object>();
        newAttributeValues.addAll(currentAttributeValues);
        if (currentAttributeValues.contains(oldAttributeValue)) {
            newAttributeValues.remove(oldAttributeValue);
        }
        if (!newAttributeValues.contains(newAttributeValue)) {
            newAttributeValues.add(newAttributeValue);
        }
        customAttribute.setValues(newAttributeValues);
    }
    if (multiValued != null) {
        customAttribute.setMultiValued(multiValued);
    }
    return updateUser(user);
}
Also used : CustomObjectAttribute(org.gluu.persist.model.base.CustomObjectAttribute) User(org.gluu.oxauth.model.common.User) ArrayList(java.util.ArrayList)

Example 10 with CustomObjectAttribute

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

the class UserService method getUniqueUserByAttributes.

public User getUniqueUserByAttributes(List<String> attributeNames, String attributeValue) {
    log.debug("Getting user information from LDAP: attributeNames = '{}', attributeValue = '{}'", attributeNames, attributeValue);
    User user = null;
    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("Found '{}' entries", entries.size());
                if (entries.size() == 0) {
                    continue;
                } else if (entries.size() == 1) {
                    user = entries.get(0);
                    break;
                } else if (entries.size() > 0) {
                    break;
                }
            } catch (Exception e) {
                log.debug(e.getMessage());
            }
        }
    }
    return 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