Search in sources :

Example 11 with CustomAttribute

use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.

the class User method setAttribute.

public void setAttribute(String attributeName, String attributeValue) {
    CustomAttribute attribute = new CustomAttribute(attributeName, attributeValue);
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 12 with CustomAttribute

use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.

the class User method setAttribute.

public void setAttribute(String attributeName, List<String> attributeValues) {
    CustomAttribute attribute = new CustomAttribute(attributeName, attributeValues);
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 13 with CustomAttribute

use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.

the class User method setAttribute.

public void setAttribute(String attributeName, String[] attributeValues) {
    CustomAttribute attribute = new CustomAttribute(attributeName, Arrays.asList(attributeValues));
    removeAttribute(attributeName);
    getCustomAttributes().add(attribute);
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 14 with CustomAttribute

use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.

the class AuthenticationService method getUserByAttribute.

private User getUserByAttribute(LdapEntryManager 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<CustomAttribute> customAttributes = new ArrayList<CustomAttribute>();
    customAttributes.add(new CustomAttribute(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 : SimpleUser(org.xdi.oxauth.model.common.SimpleUser) User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser) CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 15 with CustomAttribute

use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.

the class AuthenticationService method updateLastLogonUserTime.

private void updateLastLogonUserTime(User user) {
    if (!appConfiguration.getUpdateUserLastLogonTime()) {
        return;
    }
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(user.getDn());
    customEntry.setCustomObjectClasses(UserService.USER_OBJECT_CLASSES);
    CustomAttribute customAttribute = new CustomAttribute("oxLastLogonTime", new Date());
    customEntry.getCustomAttributes().add(customAttribute);
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastLoginTime of user '{}'", user.getUserId());
    }
}
Also used : CustomEntry(org.xdi.ldap.model.CustomEntry) CustomAttribute(org.xdi.ldap.model.CustomAttribute) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Aggregations

CustomAttribute (org.xdi.ldap.model.CustomAttribute)17 User (org.xdi.oxauth.model.common.User)5 ArrayList (java.util.ArrayList)4 JSONArray (org.codehaus.jettison.json.JSONArray)2 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)2 CustomEntry (org.xdi.ldap.model.CustomEntry)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONException (org.codehaus.jettison.json.JSONException)1 SearchScope (org.xdi.ldap.model.SearchScope)1 Scope (org.xdi.oxauth.model.common.Scope)1 SimpleUser (org.xdi.oxauth.model.common.SimpleUser)1