Search in sources :

Example 6 with CustomAttribute

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

the class ClientService method updatAccessTime.

public void updatAccessTime(Client client, boolean isUpdateLogonTime) {
    if (!appConfiguration.getUpdateClientAccessTime()) {
        return;
    }
    String clientDn = client.getDn();
    CustomEntry customEntry = new CustomEntry();
    customEntry.setDn(clientDn);
    customEntry.setCustomObjectClasses(CLIENT_OBJECT_CLASSES);
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    CustomAttribute customAttributeLastAccessTime = new CustomAttribute("oxLastAccessTime", now);
    customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
    if (isUpdateLogonTime) {
        CustomAttribute customAttributeLastLogonTime = new CustomAttribute("oxLastLogonTime", now);
        customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
    }
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastAccessTime and oxLastLoginTime of client '{}'", clientDn);
    }
    removeFromCache(client);
}
Also used : CustomEntry(org.xdi.ldap.model.CustomEntry) CustomAttribute(org.xdi.ldap.model.CustomAttribute) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 7 with CustomAttribute

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

the class ClientService method getAttribute.

public Object getAttribute(Client client, String clientAttribute) throws InvalidClaimException {
    Object attribute = null;
    if (clientAttribute != null) {
        if (clientAttribute.equals("displayName")) {
            attribute = client.getClientName();
        } else if (clientAttribute.equals("inum")) {
            attribute = client.getClientId();
        } else if (clientAttribute.equals("oxAuthAppType")) {
            attribute = client.getApplicationType();
        } else if (clientAttribute.equals("oxAuthIdTokenSignedResponseAlg")) {
            attribute = client.getIdTokenSignedResponseAlg();
        } else if (clientAttribute.equals("oxAuthRedirectURI") && client.getRedirectUris() != null) {
            JSONArray array = new JSONArray();
            for (String redirectUri : client.getRedirectUris()) {
                array.put(redirectUri);
            }
            attribute = array;
        } else if (clientAttribute.equals("oxAuthScope") && client.getScopes() != null) {
            JSONArray array = new JSONArray();
            for (String scopeDN : client.getScopes()) {
                Scope s = scopeService.getScopeByDn(scopeDN);
                if (s != null) {
                    String scopeName = s.getDisplayName();
                    array.put(scopeName);
                }
            }
            attribute = array;
        } else {
            for (CustomAttribute customAttribute : client.getCustomAttributes()) {
                if (customAttribute.getName().equals(clientAttribute)) {
                    List<String> values = customAttribute.getValues();
                    if (values != null) {
                        if (values.size() == 1) {
                            attribute = values.get(0);
                        } else {
                            JSONArray array = new JSONArray();
                            for (String v : values) {
                                array.put(v);
                            }
                            attribute = array;
                        }
                    }
                    break;
                }
            }
        }
    }
    return attribute;
}
Also used : Scope(org.xdi.oxauth.model.common.Scope) SearchScope(org.xdi.ldap.model.SearchScope) CustomAttribute(org.xdi.ldap.model.CustomAttribute) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 8 with CustomAttribute

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

the class UserService method replaceUserAttribute.

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

Example 9 with CustomAttribute

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

the class UserService method setCustomAttribute.

public void setCustomAttribute(User user, String attributeName, String attributeValue) {
    CustomAttribute customAttribute = getCustomAttribute(user, attributeName);
    if (customAttribute == null) {
        customAttribute = new CustomAttribute(attributeName);
        user.getCustomAttributes().add(customAttribute);
    }
    customAttribute.setValue(attributeValue);
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 10 with CustomAttribute

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

the class UserService method addDefaultUser.

public User addDefaultUser(String uid) {
    String peopleBaseDN = staticConfiguration.getBaseDn().getPeople();
    String inum = inumService.generatePeopleInum();
    User user = new User();
    user.setDn("inum=" + inum + "," + peopleBaseDN);
    user.setCustomAttributes(Arrays.asList(new CustomAttribute("inum", inum), new CustomAttribute("gluuStatus", GluuStatus.ACTIVE.getValue()), new CustomAttribute("displayName", "User " + uid + " added via oxAuth custom plugin")));
    user.setUserId(uid);
    ldapEntryManager.persist(user);
    return getUser(uid);
}
Also used : User(org.xdi.oxauth.model.common.User) CustomAttribute(org.xdi.ldap.model.CustomAttribute)

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