Search in sources :

Example 1 with User

use of org.gluu.oxtrust.model.User in project oxTrust by GluuFederation.

the class SecurityService method isUseAdminUser.

public boolean isUseAdminUser(String userName) {
    try {
        User user = personService.getUserByUid(userName);
        GluuUserRole[] roles = getUserRoles(user);
        for (GluuUserRole role : roles) {
            if (GluuUserRole.MANAGER.equals(role)) {
                return true;
            }
        }
    } catch (Exception ex) {
        log.error("Failed to find user '{}' in ldap", ex, userName);
    }
    return false;
}
Also used : User(org.gluu.oxtrust.model.User) GluuUserRole(org.xdi.model.GluuUserRole)

Example 2 with User

use of org.gluu.oxtrust.model.User in project oxTrust by GluuFederation.

the class PersonService method getUserByUid.

/* (non-Javadoc)
	 * @see org.gluu.oxtrust.ldap.service.IPersonService#getUserByUid(java.lang.String)
	 */
@Override
public User getUserByUid(String uid) {
    User user = new User();
    user.setBaseDn(getDnForPerson(null));
    user.setUid(uid);
    // getLdapEntryManagerInstance().findEntries(person);
    List<User> users = ldapEntryManager.findEntries(user);
    if ((users != null) && (users.size() > 0)) {
        return users.get(0);
    }
    return null;
}
Also used : User(org.gluu.oxtrust.model.User)

Example 3 with User

use of org.gluu.oxtrust.model.User in project oxTrust by GluuFederation.

the class Authenticator method Shibboleth3Authenticate.

/**
	 * Authenticate using credentials passed from web request header
	 */
public boolean Shibboleth3Authenticate() {
    log.debug("Checking if user authenticated with shibboleth already");
    boolean result = false;
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String authType = request.getAuthType();
    String userUid = request.getHeader("REMOTE_USER");
    String userUidlower = request.getHeader("remote_user");
    Enumeration<?> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        log.trace(headerName + "-->" + request.getHeader(headerName));
    }
    log.debug("Username is " + userUid);
    log.debug("UsernameLower is " + userUidlower);
    log.debug("AuthType is " + authType);
    Map<String, String[]> headers = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderValuesMap();
    for (String name : headers.keySet()) {
        log.trace(name + "==>" + StringUtils.join(headers.get(name)));
    }
    if (StringHelper.isEmpty(userUid) || StringHelper.isEmpty(authType) || !authType.equals("shibboleth")) {
        result = false;
        return result;
    }
    Pattern pattern = Pattern.compile(".+@.+\\.[a-z]+");
    Matcher matcher = pattern.matcher(userUid);
    User user = null;
    if (matcher.matches()) {
        // Find user by uid
        user = personService.getPersonByEmail(userUid);
    } else {
        // Find user by uid
        user = personService.getUserByUid(userUid);
    }
    if (user == null) {
        result = false;
        return result;
    }
    log.debug("Person Inum is " + user.getInum());
    if (GluuStatus.ACTIVE.getValue().equals(user.getAttribute("gluuStatus"))) {
        credentials.setUsername(user.getUid());
        // credentials.setPassword("");
        Principal principal = new SimplePrincipal(user.getUid());
        log.debug("Principal is " + principal.toString());
        identity.acceptExternallyAuthenticatedPrincipal(principal);
        log.info("User '{}' authenticated with shibboleth already", userUid);
        identity.quietLogin();
        postLogin(user);
        identity.getSessionMap().put(OxTrustConstants.APPLICATION_AUTHORIZATION_TYPE, OxTrustConstants.APPLICATION_AUTHORIZATION_NAME_SHIBBOLETH3);
        result = true;
    } else {
        result = false;
    }
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Pattern(java.util.regex.Pattern) User(org.gluu.oxtrust.model.User) Matcher(java.util.regex.Matcher) SimplePrincipal(org.xdi.model.security.SimplePrincipal) Principal(java.security.Principal) SimplePrincipal(org.xdi.model.security.SimplePrincipal)

Example 4 with User

use of org.gluu.oxtrust.model.User in project oxTrust by GluuFederation.

the class Authenticator method authenticate.

public boolean authenticate() {
    String userName = null;
    try {
        userName = identity.getOauthData().getUserUid();
        identity.getCredentials().setUsername(userName);
        log.info("Authenticating user '{}'", userName);
        User user = findUserByUserName(userName);
        if (user == null) {
            log.error("Person '{}' not found in LDAP", userName);
            return false;
        } else if (GluuStatus.EXPIRED.getValue().equals(user.getAttribute("gluuStatus")) || GluuStatus.REGISTER.getValue().equals(user.getAttribute("gluuStatus"))) {
            HashMap<String, Object> params = new HashMap<String, Object>();
            params.put("inum", user.getInum());
            facesService.redirect("/register.xhtml", params);
            return false;
        }
        postLogin(user);
        log.info("User '{}' authenticated successfully", userName);
    } catch (Exception ex) {
        log.error("Failed to authenticate user '{}'", ex, userName);
        return false;
    }
    return true;
}
Also used : User(org.gluu.oxtrust.model.User) EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

User (org.gluu.oxtrust.model.User)4 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Principal (java.security.Principal)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JSONException (org.codehaus.jettison.json.JSONException)1 GluuUserRole (org.xdi.model.GluuUserRole)1 SimplePrincipal (org.xdi.model.security.SimplePrincipal)1 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)1 EncryptionException (org.xdi.util.security.StringEncrypter.EncryptionException)1