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