use of org.xdi.oxauth.model.common.User 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);
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class UserService method getUser.
public User getUser(String userId, String... returnAttributes) {
log.debug("Getting user information from LDAP: userId = {}", userId);
if (StringHelper.isEmpty(userId)) {
return null;
}
Filter userUidFilter = Filter.createEqualityFilter("uid", userId);
List<User> entries = ldapEntryManager.findEntries(staticConfiguration.getBaseDn().getPeople(), User.class, returnAttributes, userUidFilter);
log.debug("Found {} entries for user id = {}", entries.size(), userId);
if (entries.size() > 0) {
return entries.get(0);
} else {
return null;
}
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method authenticate.
/*
* Utility method which can be used in custom scripts
*/
public boolean authenticate(GluuLdapConfiguration ldapAuthConfig, LdapEntryManager ldapAuthEntryManager, String keyValue, String password, String primaryKey, String localPrimaryKey) {
log.debug("Attempting to find userDN by primary key: '{}' and key value: '{}', credentials: '{}'", primaryKey, keyValue, System.identityHashCode(credentials));
List<?> baseDNs;
if (ldapAuthConfig == null) {
baseDNs = Arrays.asList(userService.getDnForUser(null));
} else {
baseDNs = ldapAuthConfig.getBaseDNs();
}
if (baseDNs != null && !baseDNs.isEmpty()) {
for (Object baseDnProperty : baseDNs) {
String baseDn;
if (baseDnProperty instanceof SimpleProperty) {
baseDn = ((SimpleProperty) baseDnProperty).getValue();
} else {
baseDn = baseDnProperty.toString();
}
User user = getUserByAttribute(ldapAuthEntryManager, baseDn, primaryKey, keyValue);
if (user != null) {
String userDn = user.getDn();
log.debug("Attempting to authenticate userDN: {}", userDn);
if (ldapAuthEntryManager.authenticate(userDn, password)) {
log.debug("User authenticated: {}", userDn);
log.debug("Attempting to find userDN by local primary key: {}", localPrimaryKey);
User localUser = userService.getUserByAttribute(localPrimaryKey, keyValue);
if (localUser != null) {
if (!checkUserStatus(localUser)) {
return false;
}
configureAuthenticatedUser(localUser);
updateLastLogonUserTime(localUser);
log.trace("authenticate_external: credentials: '{}', credentials.userName: '{}', authenticatedUser.userId: '{}'", System.identityHashCode(credentials), credentials.getUsername(), getAuthenticatedUserId());
return true;
}
}
}
}
} else {
log.error("There are no baseDns specified in authentication configuration.");
}
return false;
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method onSuccessfulLogin.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void onSuccessfulLogin(SessionState sessionUser) {
log.info("Attempting to redirect user: SessionUser: {}", sessionUser);
if ((sessionUser == null) || StringUtils.isBlank(sessionUser.getUserDn())) {
return;
}
User user = userService.getUserByDn(sessionUser.getUserDn());
log.info("Attempting to redirect user: User: {}", user);
if (user != null) {
final Map<String, String> result = sessionUser.getSessionAttributes();
Map<String, String> allowedParameters = getAllowedParameters(result);
result.put(SESSION_STATE, sessionUser.getId());
log.trace("Logged in successfully! User: {}, page: /authorize.xhtml, map: {}", user, allowedParameters);
facesService.redirect("/authorize.xhtml", (Map) allowedParameters);
}
}
use of org.xdi.oxauth.model.common.User 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);
}
Aggregations