Java Code Examples for org.apache.cxf.rs.security.jose.jwt.JwtClaims#asMap()

The following examples show how to use org.apache.cxf.rs.security.jose.jwt.JwtClaims#asMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwtRequestCodeFilter.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public MultivaluedMap<String, String> process(MultivaluedMap<String, String> params,
                                              UserSubject endUser,
                                              Client client) {
    String requestToken = params.getFirst(REQUEST_PARAM);
    if (requestToken == null) {
        String requestUri = params.getFirst(REQUEST_URI_PARAM);
        if (isRequestUriValid(client, requestUri)) {
            requestToken = WebClient.create(requestUri).get(String.class);
        }
    }
    if (requestToken != null) {
        JweDecryptionProvider theDecryptor = super.getInitializedDecryptionProvider(client.getClientSecret());
        JwsSignatureVerifier theSigVerifier = getInitializedSigVerifier(client);
        JwtToken jwt = getJwtToken(requestToken, theDecryptor, theSigVerifier);
        JwtClaims claims = jwt.getClaims();

        // Check issuer
        String iss = issuer != null ? issuer : client.getClientId();
        if (!iss.equals(claims.getIssuer())) {
            throw new SecurityException();
        }

        // Check client_id - if present it must match the client_id specified in the request
        if (claims.getClaim(OAuthConstants.CLIENT_ID) != null
            && !claims.getStringProperty(OAuthConstants.CLIENT_ID).equals(client.getClientId())) {
            throw new SecurityException();
        }

        // Check response_type - if present it must match the response_type specified in the request
        String tokenResponseType = (String)claims.getClaim(OAuthConstants.RESPONSE_TYPE);
        if (tokenResponseType != null
            && !tokenResponseType.equals(params.getFirst(OAuthConstants.RESPONSE_TYPE))) {
            throw new SecurityException();
        }

        MultivaluedMap<String, String> newParams = new MetadataMap<>(params);
        Map<String, Object> claimsMap = claims.asMap();
        for (Map.Entry<String, Object> entry : claimsMap.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (value instanceof Map) {
                Map<String, Object> map = CastUtils.cast((Map<?, ?>)value);
                value = jsonHandler.toJson(map);
            } else if (value instanceof List) {
                List<Object> list = CastUtils.cast((List<?>)value);
                value = jsonHandler.toJson(list);
            }
            newParams.putSingle(key, value.toString());
        }
        return newParams;
    }
    return params;
}
 
Example 2
Source File: AbstractUserInfo.java    From cxf with Apache License 2.0 4 votes vote down vote up
public AbstractUserInfo(JwtClaims claims) {
    this(claims.asMap());
}
 
Example 3
Source File: IdToken.java    From cxf with Apache License 2.0 4 votes vote down vote up
public IdToken(JwtClaims claims) {
    this(claims.asMap());
}
 
Example 4
Source File: UserInfo.java    From cxf with Apache License 2.0 4 votes vote down vote up
public UserInfo(JwtClaims claims) {
    this(claims.asMap());
}