Playframework oauth small upgrade (#12332)

* update surefire to newer version

* small tweak to add support for "leeway" when verifying oauth tokens.

Co-authored-by: William Cheng <wing328hk@gmail.com>
Co-authored-by: Bruno Flamand <bflamand@stingray.com>
This commit is contained in:
bflamand 2022-05-11 03:19:59 -04:00 committed by GitHub
parent 6931f15e80
commit 575b6b4330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 39 additions and 0 deletions

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
{{#hasOAuthMethods}} {{#hasOAuthMethods}}
{{#oauthMethods}} {{#oauthMethods}}
@ -135,6 +137,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_token", "https://keycloak-dev.business.stingray.com/auth/realms/CSLocal/protocol/openid-connect/token/introspect"); tokenIntrospectEndpoints.put("petstore_token", "https://keycloak-dev.business.stingray.com/auth/realms/CSLocal/protocol/openid-connect/token/introspect");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }

View File

@ -42,6 +42,7 @@ public class SecurityAPIUtils {
private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>(); private final HashMap<String, String> tokenIntrospectEndpoints = new HashMap<>();
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final long leeway;
// Offline validation // Offline validation
private final HashMap<String, String> jwksEndpoints = new HashMap<>(); private final HashMap<String, String> jwksEndpoints = new HashMap<>();
@ -54,6 +55,7 @@ public class SecurityAPIUtils {
clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : ""; clientId = configuration.hasPath("oauth.clientId") ? configuration.getString("oauth.clientId") : "";
clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : ""; clientSecret = configuration.hasPath("oauth.clientSecret") ? configuration.getString("oauth.clientSecret") : "";
leeway = configuration.hasPath("oauth.leeway") ? configuration.getLong("oauth.leeway") : 3;
tokenIntrospectEndpoints.put("petstore_auth", ""); tokenIntrospectEndpoints.put("petstore_auth", "");
@ -127,6 +129,7 @@ public class SecurityAPIUtils {
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null); Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
tokenVerifier = JWT.require(algorithm) tokenVerifier = JWT.require(algorithm)
.withIssuer(issuer) .withIssuer(issuer)
.acceptLeeway(leeway)
.build(); .build();
tokenKeyId = keyId; tokenKeyId = keyId;
} }