Search in sources :

Example 16 with User

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);
}
Also used : User(org.xdi.oxauth.model.common.User) CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 17 with User

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;
    }
}
Also used : SimpleUser(org.xdi.oxauth.model.common.SimpleUser) User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser) CustomAttribute(org.xdi.ldap.model.CustomAttribute)

Example 18 with User

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;
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser)

Example 19 with User

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;
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser)

Example 20 with User

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;
}
Also used : User(org.xdi.oxauth.model.common.User) SimpleUser(org.xdi.oxauth.model.common.SimpleUser)

Aggregations

User (org.xdi.oxauth.model.common.User)25 SimpleUser (org.xdi.oxauth.model.common.SimpleUser)7 CustomAttribute (org.xdi.ldap.model.CustomAttribute)5 SessionState (org.xdi.oxauth.model.common.SessionState)5 ArrayList (java.util.ArrayList)4 Client (org.xdi.oxauth.model.registration.Client)4 Prompt (org.xdi.oxauth.model.common.Prompt)3 SignatureException (java.security.SignatureException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)2 OAuth2AuditLog (org.xdi.oxauth.model.audit.OAuth2AuditLog)2 AccessToken (org.xdi.oxauth.model.common.AccessToken)2 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)2 IdToken (org.xdi.oxauth.model.common.IdToken)2 AcrChangedException (org.xdi.oxauth.model.exception.AcrChangedException)2 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)2 ClientAuthorizations (org.xdi.oxauth.model.ldap.ClientAuthorizations)2 StringEncrypter (org.xdi.util.security.StringEncrypter)2 Filter (com.unboundid.ldap.sdk.Filter)1