org.springframework.security.jwt.crypto.sign.RsaSigner Java Examples

The following examples show how to use org.springframework.security.jwt.crypto.sign.RsaSigner. 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: OAuthService.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
public Jwt getExampleJWTToken() {
    final ZonedDateTime soon = ZonedDateTime.now().plusDays(365);
    final String jwtToken = "{\n" +
            "  \"aud\": [\n" +
            "    \"https://api.otto.de/api-authorization\"\n" +
            "  ],\n" +
            "  \"exp\": " + soon.toInstant().getEpochSecond() + ",\n" +
            "  \"user_name\": \"3d44bbc24614e28edd094bc54ef0497809717af5\",\n" +
            "  \"jti\": \"3cee521d-96a7-4d82-b726-7e02355f3a55\",\n" +
            "  \"client_id\": \"fe0661e5a99e4d43bd3496cc6c58025f\",\n" +
            "  \"scope\": [\n" +
            "    \"hello.read\"\n" +
            "  ]\n" +
            "}";
    final RsaSigner rsaSigner = new RsaSigner((RSAPrivateKey) keyPair.getPrivate());

    return JwtHelper.encode(jwtToken, rsaSigner);
}
 
Example #2
Source File: OAuthTestHelper.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
public String getBearerToken(final String scope) {
    final ZonedDateTime soon = ZonedDateTime.now().plusDays(365);
    final String jwtToken = "{\n" +
            "  \"aud\": [\n" +
            "    \"" + aud + "\"\n" +
            "  ],\n" +
            "  \"exp\": " + soon.toEpochSecond() + ",\n" +
            "  \"user_name\": \"3d44bbc24614e28edd094bc54ef0497809717af5\",\n" +
            "  \"jti\": \"3cee521d-96a7-4d82-b726-7e02355f3a55\",\n" +
            "  \"client_id\": \"fe0661e5a99e4d43bd3496cc6c58025f\",\n" +
            "  \"scope\": [\n" +
            "    \"" + scope + "\"\n" +
            "  ]\n" +
            "}";
    final RsaSigner rsaSigner = new RsaSigner((RSAPrivateKey) keyPair.getPrivate());
    final Jwt encode = JwtHelper.encode(jwtToken, rsaSigner);


    return "Bearer " + encode.getEncoded();
}
 
Example #3
Source File: CustomTokenConverter.java    From spring-microservice-exam with MIT License 4 votes vote down vote up
public CustomTokenConverter(KeyPair keyPair, Map<String, String> customHeaders) {
	super();
	super.setKeyPair(keyPair);
	this.signer = new RsaSigner((RSAPrivateKey) keyPair.getPrivate());
	this.customHeaders = customHeaders;
}
 
Example #4
Source File: JwtCustomHeadersAccessTokenConverter.java    From spring-security-oauth with MIT License 4 votes vote down vote up
public JwtCustomHeadersAccessTokenConverter(Map<String, String> customHeaders, KeyPair keyPair) {
    super();
    super.setKeyPair(keyPair);
    this.signer = new RsaSigner((RSAPrivateKey) keyPair.getPrivate());
    this.customHeaders = customHeaders;
}
 
Example #5
Source File: JwtGenerator.java    From cloud-security-xsuaa-integration with Apache License 2.0 3 votes vote down vote up
private static String signAndEncodeToken(String claims, Map<String, String> tokenHeaders) {
	RsaSigner signer = new RsaSigner(readPrivateKeyFromFile());

	org.springframework.security.jwt.Jwt jwt = JwtHelper.encode(claims, signer, tokenHeaders);

	return jwt.getEncoded();
}