use of org.xdi.ldap.model.CustomAttribute in project oxCore by GluuFederation.
the class LdapSampleBatchJob method getUpdatedAttribute.
private static CustomAttribute getUpdatedAttribute(String attributeName, String attributeValue) {
try {
Calendar calendar = Calendar.getInstance();
Date oxLastAccessTimeDate = StaticUtils.decodeGeneralizedTime(attributeValue);
calendar.setTime(oxLastAccessTimeDate);
calendar.add(Calendar.SECOND, -1);
CustomAttribute customAttribute = new CustomAttribute();
customAttribute.setName(attributeName);
customAttribute.setDate(calendar.getTime());
return customAttribute;
} catch (ParseException e) {
log.error("Can't parse attribute", e);
}
return null;
}
use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.
the class RegisterRestWebServiceImpl method putCustomStuffIntoObject.
/**
* Puts custom object class and custom attributes in client object for persistence.
*
* @param p_client client object
* @param p_requestObject request object
*/
private void putCustomStuffIntoObject(Client p_client, JSONObject p_requestObject) throws JSONException {
// custom object class
final String customOC = appConfiguration.getDynamicRegistrationCustomObjectClass();
if (StringUtils.isNotBlank(customOC)) {
p_client.setCustomObjectClasses(new String[] { customOC });
}
// custom attributes (custom attributes must be in custom object class)
final List<String> attrList = appConfiguration.getDynamicRegistrationCustomAttributes();
if (attrList != null && !attrList.isEmpty()) {
for (String attr : attrList) {
if (p_requestObject.has(attr)) {
final JSONArray parameterValuesJsonArray = p_requestObject.optJSONArray(attr);
final List<String> parameterValues = parameterValuesJsonArray != null ? toList(parameterValuesJsonArray) : Arrays.asList(p_requestObject.getString(attr));
if (parameterValues != null && !parameterValues.isEmpty()) {
try {
boolean processed = processApplicationAttributes(p_client, attr, parameterValues);
if (!processed) {
p_client.getCustomAttributes().add(new CustomAttribute(attr, parameterValues));
}
} catch (Exception e) {
log.debug(e.getMessage(), e);
}
}
}
}
}
}
use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.
the class UserService method getUserByAttribute.
public User getUserByAttribute(String attributeName, String attributeValue) {
log.debug("Getting user information from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
User user = new User();
user.setDn(staticConfiguration.getBaseDn().getPeople());
List<CustomAttribute> customAttributes = new ArrayList<CustomAttribute>();
customAttributes.add(new CustomAttribute(attributeName, attributeValue));
user.setCustomAttributes(customAttributes);
List<User> entries = ldapEntryManager.findEntries(user);
log.debug("Found '{}' entries", entries.size());
if (entries.size() > 0) {
return entries.get(0);
} else {
return null;
}
}
use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.
the class UserService method addUserAttribute.
public boolean addUserAttribute(User user, String attributeName, String attributeValue) {
CustomAttribute customAttribute = getCustomAttribute(user, attributeName);
if (customAttribute == null) {
customAttribute = new CustomAttribute(attributeName, attributeValue);
user.getCustomAttributes().add(customAttribute);
} else {
List<String> currentAttributeValues = customAttribute.getValues();
List<String> newAttributeValues = new ArrayList<String>();
newAttributeValues.addAll(currentAttributeValues);
if (newAttributeValues.contains(attributeValue)) {
return false;
} else {
newAttributeValues.add(attributeValue);
}
customAttribute.setValues(newAttributeValues);
}
return true;
}
use of org.xdi.ldap.model.CustomAttribute in project oxAuth by GluuFederation.
the class UserService method removeUserAttribute.
public User removeUserAttribute(String userId, String attributeName, String attributeValue) {
log.debug("Remove user attribute from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
User user = getUser(userId);
if (user == null) {
return null;
}
CustomAttribute customAttribute = getCustomAttribute(user, attributeName);
if (customAttribute != null) {
List<String> currentAttributeValues = customAttribute.getValues();
if (currentAttributeValues.contains(attributeValue)) {
List<String> newAttributeValues = new ArrayList<String>();
newAttributeValues.addAll(currentAttributeValues);
if (currentAttributeValues.contains(attributeValue)) {
newAttributeValues.remove(attributeValue);
} else {
return null;
}
customAttribute.setValues(newAttributeValues);
}
}
return updateUser(user);
}
Aggregations