use of org.xdi.oxauth.model.common.User 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);
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method getUserByAttribute.
private User getUserByAttribute(LdapEntryManager ldapAuthEntryManager, String baseDn, String attributeName, String attributeValue) {
log.debug("Getting user information from LDAP: attributeName = '{}', attributeValue = '{}'", attributeName, attributeValue);
if (StringHelper.isEmpty(attributeValue)) {
return null;
}
SimpleUser sampleUser = new SimpleUser();
sampleUser.setDn(baseDn);
List<CustomAttribute> customAttributes = new ArrayList<CustomAttribute>();
customAttributes.add(new CustomAttribute(attributeName, attributeValue));
sampleUser.setCustomAttributes(customAttributes);
log.debug("Searching user by attributes: '{}', baseDn: '{}'", customAttributes, baseDn);
List<User> entries = ldapAuthEntryManager.findEntries(sampleUser, 1);
log.debug("Found '{}' entries", entries.size());
if (entries.size() > 0) {
SimpleUser foundUser = entries.get(0);
return ldapAuthEntryManager.find(User.class, foundUser.getDn());
} else {
return null;
}
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method configureEventUser.
public SessionState configureEventUser() {
User user = getAuthenticatedUser();
if (user == null) {
return null;
}
log.debug("ConfigureEventUser: username: '{}', credentials: '{}'", user.getUserId(), System.identityHashCode(credentials));
SessionState sessionState = sessionStateService.generateAuthenticatedSessionState(user.getDn());
configureEventUserContext(sessionState);
return sessionState;
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method getAuthenticatedUser.
public User getAuthenticatedUser() {
if (identity.getUser() != null) {
return identity.getUser();
} else {
SessionState sessionState = sessionStateService.getSessionState();
if (sessionState != null) {
Map<String, String> sessionIdAttributes = sessionState.getSessionAttributes();
String userId = sessionIdAttributes.get(Constants.AUTHENTICATED_USER);
if (StringHelper.isNotEmpty(userId)) {
User user = userService.getUser(userId);
identity.setUser(user);
return user;
}
}
}
return null;
}
use of org.xdi.oxauth.model.common.User in project oxAuth by GluuFederation.
the class AuthenticationService method localAuthenticate.
private boolean localAuthenticate(String userName, String password) {
User user = userService.getUser(userName);
if (user != null) {
if (!checkUserStatus(user)) {
return false;
}
// Use local LDAP server for user authentication
boolean authenticated = ldapEntryManager.authenticate(user.getDn(), password);
if (authenticated) {
configureAuthenticatedUser(user);
updateLastLogonUserTime(user);
log.trace("Authenticate: credentials: '{}', credentials.userName: '{}', authenticatedUser.userId: '{}'", System.identityHashCode(credentials), credentials.getUsername(), getAuthenticatedUserId());
}
return authenticated;
}
return false;
}
Aggregations