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());
}
}
}
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;
}
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);
}
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);
}
Aggregations