Search in sources :

Example 1 with JoseJwtConsumer

use of org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer in project cxf by apache.

the class DefaultEHCacheOAuthDataProvider method getAccessToken.

@Override
public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException {
    ServerAccessToken at = null;
    if (isUseJwtFormatForAccessTokens() && isStoreJwtTokenKeyOnly()) {
        String jose = getCacheValue(accessTokenCache, accessToken, String.class);
        if (jose != null) {
            JoseJwtConsumer theConsumer = jwtTokenConsumer == null ? new JoseJwtConsumer() : jwtTokenConsumer;
            at = JwtTokenUtils.createAccessTokenFromJwt(theConsumer, jose, this, super.getJwtAccessTokenClaimMap());
        }
    } else {
        at = getCacheValue(accessTokenCache, accessToken, ServerAccessToken.class);
    }
    return at;
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) JoseJwtConsumer(org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer)

Example 2 with JoseJwtConsumer

use of org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer in project cxf by apache.

the class JCacheOAuthDataProvider method getJwtAccessTokens.

protected List<ServerAccessToken> getJwtAccessTokens(Client client, UserSubject sub) {
    final Set<String> toRemove = new HashSet<>();
    final List<ServerAccessToken> tokens = new ArrayList<>();
    for (Iterator<Cache.Entry<String, String>> it = jwtAccessTokenCache.iterator(); it.hasNext(); ) {
        Cache.Entry<String, String> entry = it.next();
        String jose = entry.getValue();
        JoseJwtConsumer theConsumer = jwtTokenConsumer == null ? new JoseJwtConsumer() : jwtTokenConsumer;
        ServerAccessToken token = JwtTokenUtils.createAccessTokenFromJwt(theConsumer, jose, this, super.getJwtAccessTokenClaimMap());
        if (isExpired(token)) {
            toRemove.add(entry.getKey());
        } else if (isTokenMatched(token, client, sub)) {
            tokens.add(token);
        }
    }
    jwtAccessTokenCache.removeAll(toRemove);
    return tokens;
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) ArrayList(java.util.ArrayList) JoseJwtConsumer(org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer) HashSet(java.util.HashSet) Cache(javax.cache.Cache)

Example 3 with JoseJwtConsumer

use of org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer in project cxf by apache.

the class JCacheOAuthDataProvider method getJwtAccessToken.

protected ServerAccessToken getJwtAccessToken(String key) {
    String jose = jwtAccessTokenCache.get(key);
    ServerAccessToken token = null;
    if (jose != null) {
        JoseJwtConsumer theConsumer = jwtTokenConsumer == null ? new JoseJwtConsumer() : jwtTokenConsumer;
        token = JwtTokenUtils.createAccessTokenFromJwt(theConsumer, jose, this, super.getJwtAccessTokenClaimMap());
        if (isExpired(token)) {
            jwtAccessTokenCache.remove(key);
            token = null;
        }
    }
    return token;
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) JoseJwtConsumer(org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer)

Aggregations

JoseJwtConsumer (org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer)3 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Cache (javax.cache.Cache)1