Search in sources :

Example 1 with Pair

use of io.jans.util.Pair in project jans by JanssenProject.

the class RequestParameterService method getParameterValueWithType.

public Pair<String, String> getParameterValueWithType(String name) {
    String value = null;
    String clazz = null;
    final Object o = identity.getWorkingParameter(name);
    if (o instanceof String) {
        value = (String) o;
        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<>(value, clazz);
}
Also used : JSONObject(org.json.JSONObject) Pair(io.jans.util.Pair)

Example 2 with Pair

use of io.jans.util.Pair in project jans by JanssenProject.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
        else if (ws == fido2DeviceWS)
            switch(verb) {
                case PUT:
                    Fido2DeviceResource dev = mapper.readValue(data, Fido2DeviceResource.class);
                    response = fido2DeviceWS.updateF2Device(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fido2DeviceWS.deleteF2Device(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fido2DeviceWS.patchF2Device(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fido2DeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<>(response, idCreated);
}
Also used : BulkResponse(io.jans.scim.model.scim2.bulk.BulkResponse) Response(javax.ws.rs.core.Response) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) GroupResource(io.jans.scim.model.scim2.group.GroupResource) Pair(io.jans.util.Pair)

Example 3 with Pair

use of io.jans.util.Pair in project jans by JanssenProject.

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, "uid", "jansStatus");
    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(), 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(io.jans.as.common.model.common.SimpleUser) User(io.jans.as.common.model.common.User) Pair(io.jans.util.Pair)

Example 4 with Pair

use of io.jans.util.Pair in project jans by JanssenProject.

the class IntrospectionWebService method isBasicTokenValid.

private Pair<AuthorizationGrant, Boolean> isBasicTokenValid(String authorization, String accessToken) throws UnsupportedEncodingException {
    String encodedCredentials = tokenService.getBasicToken(authorization);
    String token = new String(Base64.decodeBase64(encodedCredentials), StandardCharsets.UTF_8);
    int delim = token.indexOf(":");
    if (delim == -1) {
        return EMPTY;
    }
    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)) {
        AuthorizationGrant 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 {
        if (log.isTraceEnabled())
            log.trace("Failed to perform basic authentication for client: {}", clientId);
    }
    return EMPTY;
}
Also used : AuthorizationGrant(io.jans.as.server.model.common.AuthorizationGrant) Pair(io.jans.util.Pair)

Example 5 with Pair

use of io.jans.util.Pair in project jans by JanssenProject.

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(io.jans.as.server.model.common.AuthorizationGrant) SessionId(io.jans.as.server.model.common.SessionId) URISyntaxException(java.net.URISyntaxException) InvalidJwtException(io.jans.as.model.exception.InvalidJwtException) WebApplicationException(javax.ws.rs.WebApplicationException) Pair(io.jans.util.Pair)

Aggregations

Pair (io.jans.util.Pair)10 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JOSEException (com.nimbusds.jose.JOSEException)1 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 JWSObject (com.nimbusds.jose.JWSObject)1 JWSVerifier (com.nimbusds.jose.JWSVerifier)1 ECDSAVerifier (com.nimbusds.jose.crypto.ECDSAVerifier)1 JwkClient (io.jans.as.client.JwkClient)1 JwkResponse (io.jans.as.client.JwkResponse)1 SimpleUser (io.jans.as.common.model.common.SimpleUser)1 User (io.jans.as.common.model.common.User)1 PublicKey (io.jans.as.model.crypto.PublicKey)1 ECDSAPublicKey (io.jans.as.model.crypto.signature.ECDSAPublicKey)1 RSAPublicKey (io.jans.as.model.crypto.signature.RSAPublicKey)1 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)1 JSONWebKey (io.jans.as.model.jwk.JSONWebKey)1 JSONWebKeySet (io.jans.as.model.jwk.JSONWebKeySet)1 AbstractToken (io.jans.as.server.model.common.AbstractToken)1