Search in sources :

Example 6 with CustomAttribute

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

the class RegisterRestWebServiceImpl method putCustomAttributesInResponse.

private void putCustomAttributesInResponse(Client client, JSONObject responseJsonObject) {
    final List<String> allowedCustomAttributeNames = appConfiguration.getDynamicRegistrationCustomAttributes();
    final List<CustomAttribute> customAttributes = client.getCustomAttributes();
    if (allowedCustomAttributeNames == null || allowedCustomAttributeNames.isEmpty() || customAttributes == null) {
        return;
    }
    for (CustomAttribute attribute : customAttributes) {
        if (!allowedCustomAttributeNames.contains(attribute.getName()))
            continue;
        if (attribute.isMultiValued()) {
            Util.addToJSONObjectIfNotNull(responseJsonObject, attribute.getName(), attribute.getValues());
        } else {
            Util.addToJSONObjectIfNotNull(responseJsonObject, attribute.getName(), attribute.getValue());
        }
    }
}
Also used : CustomAttribute(org.gluu.persist.model.base.CustomAttribute)

Example 7 with CustomAttribute

use of org.gluu.persist.model.base.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.getId();
                    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.oxauth.persistence.model.Scope) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) JSONArray(org.json.JSONArray)

Example 8 with CustomAttribute

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

the class ClientService method setCustomAttribute.

public void setCustomAttribute(Client client, String attributeName, String attributeValue) {
    org.gluu.persist.model.base.CustomAttribute customAttribute = getCustomAttribute(client, attributeName);
    if (customAttribute == null) {
        customAttribute = new org.gluu.persist.model.base.CustomAttribute(attributeName);
        client.getCustomAttributes().add(customAttribute);
    }
    customAttribute.setValue(attributeValue);
}
Also used : CustomAttribute(org.gluu.persist.model.base.CustomAttribute)

Example 9 with CustomAttribute

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

the class ClientService method updateAccessTime.

public void updateAccessTime(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();
    String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
    CustomAttribute customAttributeLastAccessTime = new CustomAttribute("oxLastAccessTime", nowDateString);
    customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
    if (isUpdateLogonTime) {
        CustomAttribute customAttributeLastLogonTime = new CustomAttribute("oxLastLogonTime", nowDateString);
        customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
    }
    try {
        ldapEntryManager.merge(customEntry);
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update oxLastAccessTime and oxLastLogonTime of client '{}'", clientDn);
    }
    removeFromCache(client);
}
Also used : CustomEntry(org.gluu.persist.model.base.CustomEntry) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Aggregations

CustomAttribute (org.gluu.persist.model.base.CustomAttribute)9 SimpleSession (org.gluu.ldap.model.SimpleSession)2 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)2 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)2 CustomEntry (org.gluu.persist.model.base.CustomEntry)2 Filter (org.gluu.search.filter.Filter)2 JSONArray (org.json.JSONArray)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 SimpleAttribute (org.gluu.ldap.model.SimpleAttribute)1 SimpleClient (org.gluu.ldap.model.SimpleClient)1 SimpleGrant (org.gluu.ldap.model.SimpleGrant)1 SimpleTokenLdap (org.gluu.ldap.model.SimpleTokenLdap)1 SimpleUser (org.gluu.ldap.model.SimpleUser)1 InvalidJwtException (org.gluu.oxauth.model.exception.InvalidJwtException)1 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)1 DefaultBatchOperation (org.gluu.persist.model.DefaultBatchOperation)1