Package org.apache.cxf.rs.security.oauth2.jwt

Examples of org.apache.cxf.rs.security.oauth2.jwt.JwtToken


                    return handler;
                }
            }
            // Lets try the default grant handler
            if (grantHandlers.size() == 0) {
                AuthorizationCodeGrantHandler handler = new AuthorizationCodeGrantHandler();
                if (handler.getSupportedGrantTypes().contains(grantType)) {
                    handler.setDataProvider(
                            (AuthorizationCodeDataProvider)super.getDataProvider());
                    return handler;
                }
            }
        }
View Full Code Here


        Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
        SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
       
        String assertion =  SAMLUtils.createAssertion(new SamlCallbackHandler(),
                                                      signInfo).assertionToString();
        Saml2BearerGrant grant = new Saml2BearerGrant(assertion);
        ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
                                        new OAuthClientUtils.Consumer("alice", "alice"),
                                        grant,
                                        false);
        assertNotNull(at.getTokenKey());
View Full Code Here

   
    public JwsJwtCompactProducer(JwtToken token) {
        this(token, null);
    }
    public JwsJwtCompactProducer(JwtClaims claims) {
        this(new JwtToken(null, claims), null);
    }
View Full Code Here

    }
    public JwsJwtCompactProducer(JwtHeaders headers, JwtClaims claims) {
        this(headers, claims, null);
    }
    public JwsJwtCompactProducer(JwtHeaders headers, JwtClaims claims, JwtTokenWriter w) {
        this(new JwtToken(headers, claims), w);
    }
View Full Code Here

        if (assertion == null) {
            throw new OAuthServiceException(OAuthConstants.INVALID_GRANT);
        }
        try {
            JwsJwtCompactConsumer jwsReader = getJwsReader(assertion);
            JwtToken jwtToken = jwsReader.getJwtToken();
            super.validateSignature(jwtToken.getHeaders(),
                                    jwsReader.getUnsignedEncodedPayload(),
                                    jwsReader.getDecodedSignature());
           
                  
            super.validateClaims(client, jwtToken.getClaims());
            UserSubject grantSubject = new UserSubject(jwtToken.getClaims().getSubject());
           
            return doCreateAccessToken(client,
                                       grantSubject,
                                       Constants.JWT_BEARER_GRANT,
                                       OAuthUtils.parseScope(params.getFirst(OAuthConstants.SCOPE)));
View Full Code Here

        String signed = writer.getSignedEncodedJws();
       
        JwsJwtCompactConsumer reader = new JwsJwtCompactConsumer(signed);
        assertEquals(0, reader.getDecodedSignature().length);
       
        JwtToken token = reader.getJwtToken();
        assertEquals(new JwtToken(headers, claims), token);
    }
View Full Code Here

    @Test
    public void testReadJwsSignedByMacSpecExample() throws Exception {
        JwsJwtCompactConsumer jws = new JwsJwtCompactConsumer(ENCODED_TOKEN_SIGNED_BY_MAC);
        assertTrue(jws.verifySignatureWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY)));
        JwtToken token = jws.getJwtToken();
        JwtHeaders headers = token.getHeaders();
        assertEquals(JwtConstants.TYPE_JWT, headers.getType());
        assertEquals(Algorithm.HmacSHA256.getJwtName(), headers.getAlgorithm());
        validateSpecClaim(token.getClaims());
    }
View Full Code Here

        JwtClaims claims = new JwtClaims();
        claims.setIssuer("joe");
        claims.setExpiryTime(1300819380);
        claims.setClaim("http://example.com/is_root", Boolean.TRUE);
       
        JwtToken token = new JwtToken(headers, claims);
        JwsCompactProducer jws = new JwsJwtCompactProducer(token, getWriter());
        jws.signWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY));
       
        assertEquals(ENCODED_TOKEN_WITH_JSON_KEY_SIGNED_BY_MAC, jws.getSignedEncodedJws());
    }
View Full Code Here

   
    @Test
    public void testReadJwsWithJwkSignedByMac() throws Exception {
        JwsJwtCompactConsumer jws = new JwsJwtCompactConsumer(ENCODED_TOKEN_WITH_JSON_KEY_SIGNED_BY_MAC);
        assertTrue(jws.verifySignatureWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY)));
        JwtToken token = jws.getJwtToken();
        JwtHeaders headers = token.getHeaders();
        assertEquals(JwtConstants.TYPE_JWT, headers.getType());
        assertEquals(Algorithm.HmacSHA256.getJwtName(), headers.getAlgorithm());
       
        JsonWebKey key = headers.getJsonWebKey();
        assertEquals(JsonWebKey.KEY_TYPE_OCTET, key.getKeyType());
        List<String> keyOps = key.getKeyOperation();
        assertEquals(2, keyOps.size());
        assertEquals(JsonWebKey.KEY_OPER_SIGN, keyOps.get(0));
        assertEquals(JsonWebKey.KEY_OPER_VERIFY, keyOps.get(1));
       
        validateSpecClaim(token.getClaims());
    }
View Full Code Here

    @Test
    public void testReadJwsSignedByPrivateKey() throws Exception {
        JwsJwtCompactConsumer jws = new JwsJwtCompactConsumer(ENCODED_TOKEN_SIGNED_BY_PRIVATE_KEY);
        RSAPublicKey key = CryptoUtils.getRSAPublicKey(RSA_MODULUS_ENCODED, RSA_PUBLIC_EXPONENT_ENCODED);
        assertTrue(jws.verifySignatureWith(new PublicKeyJwsSignatureVerifier(key)));
        JwtToken token = jws.getJwtToken();
        JwtHeaders headers = token.getHeaders();
        assertEquals(Algorithm.SHA256withRSA.getJwtName(), headers.getAlgorithm());
        validateSpecClaim(token.getClaims());
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.rs.security.oauth2.jwt.JwtToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.