Search in sources :

Example 1 with Pair

use of org.gluu.util.Pair in project oxAuth by GluuFederation.

the class AuthenticationService method localAuthenticate.

private Pair<Boolean, User> localAuthenticate(String nameValue, String password, String... nameAttributes) {
    String lowerNameValue = StringHelper.toString(nameValue);
    User user = userService.getUserByAttributes(lowerNameValue, nameAttributes, new String[] { "uid", "gluuStatus" });
    if (user != null) {
        if (!checkUserStatus(user)) {
            return new Pair<Boolean, User>(false, user);
        }
        // Use local LDAP server for user authentication
        boolean authenticated = ldapEntryManager.authenticate(user.getDn(), User.class, password);
        if (authenticated) {
            configureAuthenticatedUser(user);
            updateLastLogonUserTime(user);
            log.trace("Authenticate: credentials: '{}', credentials.userName: '{}', authenticatedUser.userId: '{}'", System.identityHashCode(credentials), credentials.getUsername(), getAuthenticatedUserId());
        }
        return new Pair<Boolean, User>(authenticated, user);
    }
    return new Pair<Boolean, User>(false, null);
}
Also used : SimpleUser(org.gluu.oxauth.model.common.SimpleUser) User(org.gluu.oxauth.model.common.User) Pair(org.gluu.util.Pair)

Example 2 with Pair

use of org.gluu.util.Pair in project oxTrust by GluuFederation.

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    Date runDate = new Date(this.lastFinishedTime);
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
            try {
                inumDbPersistenceEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BasePersistenceException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BasePersistenceException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.gluu.util.Pair)

Example 3 with Pair

use of org.gluu.util.Pair in project oxAuth by GluuFederation.

the class IntrospectionWebService method getAuthorizationGrant.

/**
 * @return we return pair of authorization grant or otherwise true - if it's basic client authentication or false if it is not
 * @throws UnsupportedEncodingException when encoding is not supported
 */
private Pair<AuthorizationGrant, Boolean> getAuthorizationGrant(String authorization, String accessToken) throws UnsupportedEncodingException {
    AuthorizationGrant grant = tokenService.getBearerAuthorizationGrant(authorization);
    if (grant != null) {
        final String authorizationAccessToken = tokenService.getBearerToken(authorization);
        final AbstractToken accessTokenObject = grant.getAccessToken(authorizationAccessToken);
        if (accessTokenObject != null && accessTokenObject.isValid()) {
            return new Pair<>(grant, false);
        } else {
            log.error("Access token is not valid: " + authorizationAccessToken);
            return EMPTY;
        }
    }
    grant = tokenService.getBasicAuthorizationGrant(authorization);
    if (grant != null) {
        return new Pair<>(grant, false);
    }
    if (tokenService.isBasicAuthToken(authorization)) {
        String encodedCredentials = tokenService.getBasicToken(authorization);
        String token = new String(Base64.decodeBase64(encodedCredentials), StandardCharsets.UTF_8);
        int delim = token.indexOf(":");
        if (delim != -1) {
            String clientId = URLDecoder.decode(token.substring(0, delim), Util.UTF8_STRING_ENCODING);
            String password = URLDecoder.decode(token.substring(delim + 1), Util.UTF8_STRING_ENCODING);
            if (clientService.authenticate(clientId, password)) {
                grant = authorizationGrantList.getAuthorizationGrantByAccessToken(accessToken);
                if (grant != null && !grant.getClientId().equals(clientId)) {
                    log.trace("Failed to match grant object clientId and client id provided during authentication.");
                    return EMPTY;
                }
                return new Pair<>(grant, true);
            } else {
                log.trace("Failed to perform basic authentication for client: " + clientId);
            }
        }
    }
    return EMPTY;
}
Also used : AbstractToken(org.gluu.oxauth.model.common.AbstractToken) AuthorizationGrant(org.gluu.oxauth.model.common.AuthorizationGrant) Pair(org.gluu.util.Pair)

Example 4 with Pair

use of org.gluu.util.Pair in project oxAuth by GluuFederation.

the class RequestParameterService method getParameterValueWithType.

public Pair<String, String> getParameterValueWithType(String p_name) {
    String value = null;
    String clazz = null;
    final Object o = identity.getWorkingParameter(p_name);
    if (o instanceof String) {
        final String s = (String) o;
        value = s;
        clazz = String.class.getName();
    } else if (o instanceof Integer) {
        final Integer i = (Integer) o;
        value = i.toString();
        clazz = Integer.class.getName();
    } else if (o instanceof Boolean) {
        final Boolean b = (Boolean) o;
        value = b.toString();
        clazz = Boolean.class.getName();
    }
    return new Pair<String, String>(value, clazz);
}
Also used : JSONObject(org.json.JSONObject) Pair(org.gluu.util.Pair)

Example 5 with Pair

use of org.gluu.util.Pair in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceImpl method getPair.

private Pair<SessionId, AuthorizationGrant> getPair(String idTokenHint, String sid, HttpServletRequest httpRequest) {
    AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByIdToken(idTokenHint);
    if (authorizationGrant == null) {
        Boolean endSessionWithAccessToken = appConfiguration.getEndSessionWithAccessToken();
        if ((endSessionWithAccessToken != null) && endSessionWithAccessToken) {
            authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(idTokenHint);
        }
    }
    SessionId ldapSessionId = null;
    try {
        String id = cookieService.getSessionIdFromCookie(httpRequest);
        if (StringHelper.isNotEmpty(id)) {
            ldapSessionId = sessionIdService.getSessionId(id);
        }
        if (StringUtils.isNotBlank(sid) && ldapSessionId == null) {
            ldapSessionId = sessionIdService.getSessionBySid(sid);
        }
    } catch (Exception e) {
        log.error("Failed to current session id.", e);
    }
    return new Pair<>(ldapSessionId, authorizationGrant);
}
Also used : AuthorizationGrant(org.gluu.oxauth.model.common.AuthorizationGrant) SessionId(org.gluu.oxauth.model.common.SessionId) URISyntaxException(java.net.URISyntaxException) InvalidJwtException(org.gluu.oxauth.model.exception.InvalidJwtException) WebApplicationException(javax.ws.rs.WebApplicationException) Pair(org.gluu.util.Pair)

Aggregations

Pair (org.gluu.util.Pair)6 AuthorizationGrant (org.gluu.oxauth.model.common.AuthorizationGrant)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 HttpResponse (org.apache.http.HttpResponse)1 AbstractToken (org.gluu.oxauth.model.common.AbstractToken)1 SessionId (org.gluu.oxauth.model.common.SessionId)1 SimpleUser (org.gluu.oxauth.model.common.SimpleUser)1 User (org.gluu.oxauth.model.common.User)1 InvalidJwtException (org.gluu.oxauth.model.exception.InvalidJwtException)1 RptIntrospectionResponse (org.gluu.oxauth.model.uma.RptIntrospectionResponse)1 UmaPermission (org.gluu.oxauth.model.uma.UmaPermission)1 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)1 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)1 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)1 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)1