Search in sources :

Example 11 with User

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

Example 12 with 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;
    }
}
Also used : User(org.xdi.oxauth.model.common.User) Filter(com.unboundid.ldap.sdk.Filter)

Example 13 with User

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

Example 14 with User

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

Example 15 with User

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

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