List of usage examples for org.springframework.security.jwt.crypto.sign RsaVerifier RsaVerifier
public RsaVerifier(String key)
From source file:org.cloudfoundry.identity.uaa.oauth.token.SignerProvider.java
public SignatureVerifier getVerifier() { if (isAssymetricKey(signingKey)) { return new RsaVerifier(verifierKey); } else {//from w ww. j a va 2 s. c om return new MacSigner(verifierKey); } }
From source file:org.cloudfoundry.identity.uaa.oauth.JwtTokenEnhancerTests.java
@Test public void rsaKeyCreatesValidRsaSignedTokens() throws Exception { String rsaKey = "-----BEGIN RSA PRIVATE KEY----- \n" + "MIIBywIBAAJhAOTeb4AZ+NwOtPh+ynIgGqa6UWNVe6JyJi+loPmPZdpHtzoqubnC \n" + "wEs6JSiSZ3rButEAw8ymgLV6iBY02hdjsl3h5Z0NWaxx8dzMZfXe4EpfB04ISoqq\n" + "hZCxchvuSDP4eQIDAQABAmEAqUuYsuuDWFRQrZgsbGsvC7G6zn3HLIy/jnM4NiJK\n" + "t0JhWNeN9skGsR7bqb1Sak2uWqW8ZqnqgAC32gxFRYHTavJEk6LTaHWovwDEhPqc\n" + "Zs+vXd6tZojJQ35chR/slUEBAjEA/sAd1oFLWb6PHkaz7r2NllwUBTvXL4VcMWTS\n" + "pN+5cU41i9fsZcHw6yZEl+ZCicDxAjEA5f3R+Bj42htNI7eylebew1+sUnFv1xT8\n" + "jlzxSzwVkoZo+vef7OD6OcFLeInAHzAJAjEAs6izolK+3ETa1CRSwz0lPHQlnmdM\n" + "Y/QuR5tuPt6U/saEVuJpkn4LNRtg5qt6I4JRAjAgFRYTG7irBB/wmZFp47izXEc3\n" + "gOdvA1hvq3tlWU5REDrYt24xpviA0fvrJpwMPbECMAKDKdiDi6Q4/iBkkzNMefA8\n" + "7HX27b9LR33don/1u/yvzMUo+lrRdKAFJ+9GPE9XFA== \n" + "-----END RSA PRIVATE KEY----- "; tokenEnhancer.setSigningKey(rsaKey); OAuth2Authentication authentication = new OAuth2Authentication(new DefaultAuthorizationRequest("foo", null), userAuthentication);//w w w .j a v a 2s . c o m OAuth2AccessToken token = tokenEnhancer.enhance(new DefaultOAuth2AccessToken("FOO"), authentication); JwtHelper.decodeAndVerify(token.getValue(), new RsaVerifier(rsaKey)); }
From source file:org.cloudfoundry.identity.uaa.oauth.JwtTokenEnhancer.java
@Override public void afterPropertiesSet() throws Exception { // Check the signing and verification keys match if (signer instanceof RsaSigner) { RsaVerifier verifier;// w ww. java 2 s . c o m try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { logger.warn("Unable to create an RSA verifier from verifierKey"); return; } byte[] test = "test".getBytes(); try { verifier.verify(test, signer.sign(test)); logger.info("Signing and verification RSA keys match"); } catch (InvalidSignatureException e) { logger.error("Signing and verification RSA keys do not match"); } } else { // Avoid a race condition where Assert.state(this.signingKey == this.verifierKey, "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key"); } }
From source file:com.ge.predix.uaa.token.lib.FastTokenServices.java
private static SignatureVerifier getVerifier(final String signingKey) { if (isAssymetricKey(signingKey)) { return new RsaVerifier(signingKey); }/*from ww w . j ava 2 s .co m*/ throw new IllegalArgumentException("Unsupported key detected. " + "FastRemoteTokenService only supports RSA public keys for token verification."); }
From source file:org.cloudfoundry.identity.uaa.oauth.SignerProvider.java
/** * Sets the JWT signing key and corresponding key for verifying siugnatures produced by this class. * * The signing key can be either a simple MAC key or an RSA * key. RSA keys should be in OpenSSH format, * as produced by <tt>ssh-keygen</tt>. * * @param signingKey the key to be used for signing JWTs. *//*ww w . j a v a2 s. co m*/ public void setSigningKey(String signingKey) { Assert.hasText(signingKey); signingKey = signingKey.trim(); this.signingKey = signingKey; if (isAssymetricKey(signingKey)) { KeyPair keyPair = parseKeyPair(signingKey); signer = new RsaSigner(signingKey); pemEncodePublicKey(keyPair); logger.debug("Configured with RSA signing key"); try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { throw new RuntimeException("Unable to create an RSA verifier from verifierKey", e); } byte[] test = "test".getBytes(); try { verifier.verify(test, signer.sign(test)); logger.debug("Signing and verification RSA keys match"); } catch (InvalidSignatureException e) { throw new RuntimeException("Signing and verification RSA keys do not match", e); } type = "RSA"; } else { // Assume it's an HMAC key this.verifierKey = signingKey; MacSigner macSigner = new MacSigner(signingKey); signer = macSigner; verifier = macSigner; Assert.state(this.verifierKey == null || this.signingKey == this.verifierKey, "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key"); type = "MAC"; } }
From source file:org.cloudfoundry.identity.uaa.oauth.token.SignerProvider.java
@Override public void afterPropertiesSet() throws Exception { if (signer instanceof RsaSigner) { type = "RSA"; RsaVerifier verifier;//from ww w . j a va 2s .c om try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { throw new RuntimeException("Unable to create an RSA verifier from verifierKey", e); } byte[] test = "test".getBytes(); try { verifier.verify(test, signer.sign(test)); logger.debug("Signing and verification RSA keys match"); } catch (InvalidSignatureException e) { throw new RuntimeException("Signing and verification RSA keys do not match", e); } } else { Assert.state(this.signingKey == this.verifierKey, "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key"); } }
From source file:org.springframework.security.oauth2.provider.token.JwtTokenEnhancer.java
public void afterPropertiesSet() throws Exception { // Check the signing and verification keys match if (signer instanceof RsaSigner) { RsaVerifier verifier;/*from w w w . java 2 s . c o m*/ try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { logger.warn("Unable to create an RSA verifier from verifierKey"); return; } byte[] test = "test".getBytes(); try { verifier.verify(test, signer.sign(test)); logger.info("Signing and verification RSA keys match"); } catch (InvalidSignatureException e) { logger.error("Signing and verification RSA keys do not match"); } } else { // Avoid a race condition where Assert.state(this.signingKey == this.verifierKey, "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key"); } SignatureVerifier verifier = new MacSigner(verifierKey); try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { logger.warn("Unable to create an RSA verifier from verifierKey"); } this.verifier = verifier; }
From source file:org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter.java
public void afterPropertiesSet() throws Exception { // Check the signing and verification keys match if (signer instanceof RsaSigner) { RsaVerifier verifier;// w w w . j av a 2s . co m try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { logger.warn("Unable to create an RSA verifier from verifierKey"); return; } byte[] test = "test".getBytes(); try { verifier.verify(test, signer.sign(test)); logger.info("Signing and verification RSA keys match"); } catch (InvalidSignatureException e) { logger.error("Signing and verification RSA keys do not match"); } } else { // Avoid a race condition where setters are called in the wrong order. Use of == is intentional. Assert.state(this.signingKey == this.verifierKey, "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key"); } SignatureVerifier verifier = new MacSigner(verifierKey); try { verifier = new RsaVerifier(verifierKey); } catch (Exception e) { logger.warn("Unable to create an RSA verifier from verifierKey"); } this.verifier = verifier; }