validIssuers = ConfigHelper.getValidIssuers();
+ // Validate the issuer
+ if (decodedJWT.getIssuer() == null || !validIssuers.contains(decodedJWT.getIssuer())) {
+ throw new InvalidTokenException(token, "Invalid issuer: " + decodedJWT.getIssuer());
+ }
+
+ // Create the JWK provider with caching
+ JwkProvider urlJwkProvider = new UrlJwkProvider(decodedJWT.getIssuer());
+ JwkProvider jwkProvider = new GuavaCachedJwkProvider(urlJwkProvider);
+
+ // Get the public key and create the algorithm
+ try {
+ Jwk jwk = jwkProvider.get(decodedJWT.getKeyId());
+ RSAPublicKey publicKey = (RSAPublicKey) jwk.getPublicKey();
+
+ alg = Algorithm.RSA256(publicKey, null);
+ } catch (Exception e) {
+ throw new JWTException(token, "Error occurred in creating algorithm. " + e.getLocalizedMessage(), e);
+ }
+ } else {
+ throw new JWTException(token, "Algorithm not supported: " + algorithm);
+ }
+
+ // Verify
+ try {
+ Verification verification = JWT.require(alg);
+
+ JWTVerifier verifier = verification.build();
+ decodedJWT = verifier.verify(token);
+ } catch (TokenExpiredException e) {
+ throw new TokenExpiredException(token);
+ } catch (SignatureVerificationException | IllegalStateException e) {
+ throw new InvalidTokenException(token, "Token is invalid. " + e.getLocalizedMessage(), e);
+ } catch (Exception e) {
+ throw new JWTException(token, "Error occurred in verifying token. " + e.getLocalizedMessage(), e);
+ }
+ return decodedJWT;
+ }
+
}
diff --git a/src/main/java/com/cronos/onlinereview/util/ConfigHelper.java b/src/main/java/com/cronos/onlinereview/util/ConfigHelper.java
index 38a65953bd..ab460ef369 100644
--- a/src/main/java/com/cronos/onlinereview/util/ConfigHelper.java
+++ b/src/main/java/com/cronos/onlinereview/util/ConfigHelper.java
@@ -596,6 +596,11 @@ public class ConfigHelper {
*/
private static final String V3_JWT_AUTHORIZATION_URL = "v3jwt_authorization_url";
+ /**
+ * A String
providing the list of valid issuers
+ */
+ private static final String VALID_ISSUERS = "valid_issuers";
+
/**
* This member variable holds the submitter role id.
*/
@@ -972,6 +977,11 @@ public class ConfigHelper {
*/
private static String v3jwtAuthorizationUrl;
+ /**
+ * A List
for the valid issuers
+ */
+ private static final List validIssuers = new ArrayList();
+
/**
* Represents the ssoDomainForV3jwtCookie.
*/
@@ -1662,6 +1672,14 @@ public class ConfigHelper {
v2jwtCookieName = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, V2_JWT_COOKIE_NAME);
ssoDomainForV3jwtCookie = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, SSO_DOMAIN_FOR_V3_JWT_COOKIE);
v3jwtAuthorizationUrl = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, V3_JWT_AUTHORIZATION_URL);
+ // Read the valid issuers property
+ String validIssuersProperty = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, VALID_ISSUERS);
+ if (validIssuersProperty != null && validIssuersProperty.trim().length() != 0) {
+ String[] validIssuerStrings = validIssuersProperty.split(",");
+ for (String validIssuer : validIssuerStrings) {
+ validIssuers.add(validIssuer.trim());
+ }
+ }
ConfigManager.Property eventBus = cfgMgr.getPropertyObject(ONLINE_REVIEW_CFG_NS, "event_bus");
contestSubmissionDownloadUrl = eventBus.getValue("contestSubmissionDownloadUrl");
@@ -2535,6 +2553,14 @@ public static String getV3jwtAuthorizationUrl() {
return v3jwtAuthorizationUrl;
}
+ /**
+ * Get valid issuers.
+ * @return the valid issuers list.
+ */
+ public static List getValidIssuers() {
+ return validIssuers;
+ }
+
/**
* Get ssoDomainForV3jwtCookie.
* @return the ssoDomainForV3jwtCookie.
diff --git a/src/main/resources/applicationConfig.properties b/src/main/resources/applicationConfig.properties
index e41532790c..cc8d768180 100644
--- a/src/main/resources/applicationConfig.properties
+++ b/src/main/resources/applicationConfig.properties
@@ -49,4 +49,5 @@ workday.end_time_minutes=0
workday.locale.language=en
workday.locale.country=US
-togglz.roles=Admin Super Role,Admin Regular Role
\ No newline at end of file
+togglz.roles=administrator
+togglz.role_key=https://topcoder-dev.com/roles
\ No newline at end of file
diff --git a/src/main/resources/config.xml b/src/main/resources/config.xml
index d6974bc36d..d8d4a2742e 100644
--- a/src/main/resources/config.xml
+++ b/src/main/resources/config.xml
@@ -2074,6 +2074,9 @@
.topcoder.com
+
+ @valid_issuers@
+
diff --git a/token.properties.local b/token.properties.local
index a3848931db..26e819651a 100644
--- a/token.properties.local
+++ b/token.properties.local
@@ -272,4 +272,5 @@ aws_s3_access_key=AKIAIZNXS3HERHTLVQKA
aws_s3_secret_key=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
topcoder_event_bus_auth_proxy_server_url=https://auth0proxy.topcoder-dev.com/token
-new_auth_url=https://accounts-auth0.topcoder-dev.com
\ No newline at end of file
+new_auth_url=https://accounts-auth0.topcoder-dev.com
+valid_issuers=https://api.topcoder-dev.com,https://api.topcoder.com,https://topcoder-dev.auth0.com/,https://auth.topcoder-dev.com/
\ No newline at end of file