@Test(expected = ExpirationException.class) public void testParseJwtPayloadExpired() { prepareJwtScenario(true); doReturn(mockPublicKey).when(rsaKeyUtils).getPublicKeyFromCertificate(null); JwtPayload jwtPayload = jwtAuthentication.parseJwtPayload(MOCK_CONFIG_ID, mockJwt); assertEquals(mockJwtPayload, jwtPayload); }
public JwtPayload parseJwtPayload(String configurationId, String jwt) { Integration integration = getIntegrationAndCheckAvailability(configurationId); String appId = properties.getApplicationId(integration.getSettings().getType()); PublicKey rsaVerifier = podPublicSignatureVerifierCache.getUnchecked(appId); Jws<Claims> jws = null; try { jws = Jwts.parser().setSigningKey(rsaVerifier).parseClaimsJws(jwt); } catch (ExpiredJwtException e) { Date expiration = e.getClaims().getExpiration(); throw new ExpirationException(logMessage.getMessage(JWT_EXPIRED, expiration.toString()), e, logMessage.getMessage(JWT_EXPIRED_SOLUTION)); } String actualAlgorithm = jws.getHeader().getAlgorithm(); String expectedAlgorithm = SignatureAlgorithm.RS512.name(); if (!actualAlgorithm.equals(expectedAlgorithm)) { throw new MalformedParameterException( logMessage.getMessage(JWT_INVALID_ALGORITHM, actualAlgorithm), logMessage.getMessage(JWT_INVALID_ALGORITHM_SOLUTION, expectedAlgorithm)); } try { String json = new ObjectMapper().writeValueAsString(jws.getBody()); JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.deserialize(json, JwtPayload.class); } catch (JsonProcessingException | RemoteApiException e) { throw new MalformedParameterException(logMessage.getMessage(JWT_DESERIALIZE), e, logMessage.getMessage(JWT_DESERIALIZE_SOLUTION)); } }
JwtAuthenticationImpl implements JwtAuthentication { public JwtPayload parseJwtPayload(String configurationId, String jwt) { Integration integration = getIntegrationAndCheckAvailability(configurationId); String appId = properties.getApplicationId(integration.getSettings().getType()); PublicKey rsaVerifier = podPublicSignatureVerifierCache.getUnchecked(appId); Jws<Claims> jws = null; try { jws = Jwts.parser().setSigningKey(rsaVerifier).parseClaimsJws(jwt); } catch (ExpiredJwtException e) { Date expiration = e.getClaims().getExpiration(); throw new ExpirationException(logMessage.getMessage(JWT_EXPIRED, expiration.toString()), e, logMessage.getMessage(JWT_EXPIRED_SOLUTION)); } String actualAlgorithm = jws.getHeader().getAlgorithm(); String expectedAlgorithm = SignatureAlgorithm.RS512.name(); if (!actualAlgorithm.equals(expectedAlgorithm)) { throw new MalformedParameterException( logMessage.getMessage(JWT_INVALID_ALGORITHM, actualAlgorithm), logMessage.getMessage(JWT_INVALID_ALGORITHM_SOLUTION, expectedAlgorithm)); } try { String json = new ObjectMapper().writeValueAsString(jws.getBody()); JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.deserialize(json, JwtPayload.class); } catch (JsonProcessingException | RemoteApiException e) { throw new MalformedParameterException(logMessage.getMessage(JWT_DESERIALIZE), e, logMessage.getMessage(JWT_DESERIALIZE_SOLUTION)); } } }
JwtAuthenticationImpl implements JwtAuthentication { public JwtPayload parseJwtPayload(String configurationId, String jwt) { Integration integration = getIntegrationAndCheckAvailability(configurationId); String appId = properties.getApplicationId(integration.getSettings().getType()); PublicKey rsaVerifier = podPublicSignatureVerifierCache.getUnchecked(appId); Jws<Claims> jws = null; try { jws = Jwts.parser().setSigningKey(rsaVerifier).parseClaimsJws(jwt); } catch (ExpiredJwtException e) { Date expiration = e.getClaims().getExpiration(); throw new ExpirationException(logMessage.getMessage(JWT_EXPIRED, expiration.toString()), e, logMessage.getMessage(JWT_EXPIRED_SOLUTION)); } String actualAlgorithm = jws.getHeader().getAlgorithm(); String expectedAlgorithm = SignatureAlgorithm.RS512.name(); if (!actualAlgorithm.equals(expectedAlgorithm)) { throw new MalformedParameterException( logMessage.getMessage(JWT_INVALID_ALGORITHM, actualAlgorithm), logMessage.getMessage(JWT_INVALID_ALGORITHM_SOLUTION, expectedAlgorithm)); } try { String json = new ObjectMapper().writeValueAsString(jws.getBody()); JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.deserialize(json, JwtPayload.class); } catch (JsonProcessingException | RemoteApiException e) { throw new MalformedParameterException(logMessage.getMessage(JWT_DESERIALIZE), e, logMessage.getMessage(JWT_DESERIALIZE_SOLUTION)); } }  }
JwtAuthenticationImpl implements JwtAuthentication { public JwtPayload parseJwtPayload(String configurationId, String jwt) { Integration integration = getIntegrationAndCheckAvailability(configurationId); String appId = properties.getApplicationId(integration.getSettings().getType()); PublicKey rsaVerifier = podPublicSignatureVerifierCache.getUnchecked(appId); Jws<Claims> jws = null; try { jws = Jwts.parser().setSigningKey(rsaVerifier).parseClaimsJws(jwt); } catch (ExpiredJwtException e) { Date expiration = e.getClaims().getExpiration(); throw new ExpirationException(logMessage.getMessage(JWT_EXPIRED, expiration.toString()), e, logMessage.getMessage(JWT_EXPIRED_SOLUTION)); } String actualAlgorithm = jws.getHeader().getAlgorithm(); String expectedAlgorithm = SignatureAlgorithm.RS512.name(); if (!actualAlgorithm.equals(expectedAlgorithm)) { throw new MalformedParameterException( logMessage.getMessage(JWT_INVALID_ALGORITHM, actualAlgorithm), logMessage.getMessage(JWT_INVALID_ALGORITHM_SOLUTION, expectedAlgorithm)); } try { String json = new ObjectMapper().writeValueAsString(jws.getBody()); JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.deserialize(json, JwtPayload.class); } catch (JsonProcessingException | RemoteApiException e) { throw new MalformedParameterException(logMessage.getMessage(JWT_DESERIALIZE), e, logMessage.getMessage(JWT_DESERIALIZE_SOLUTION)); } }  @PostConstruct void init(); Long getUserIdFromAuthorizationHeader(String configurationId, String authorizationHeader); JwtPayload getJwtToken(String configurationId, String authorizationHeader); Long getUserId(JwtPayload token); String authenticate(String configurationId); boolean isValidTokenPair(String configurationId, String applicationToken,
      String symphonyToken); JwtPayload parseJwtPayload(String configurationId, String jwt); @Override boolean checkPodInfo(String configurationId, String podId); }
JwtAuthenticationImpl implements JwtAuthentication { public JwtPayload parseJwtPayload(String configurationId, String jwt) { Integration integration = getIntegrationAndCheckAvailability(configurationId); String appId = properties.getApplicationId(integration.getSettings().getType()); PublicKey rsaVerifier = podPublicSignatureVerifierCache.getUnchecked(appId); Jws<Claims> jws = null; try { jws = Jwts.parser().setSigningKey(rsaVerifier).parseClaimsJws(jwt); } catch (ExpiredJwtException e) { Date expiration = e.getClaims().getExpiration(); throw new ExpirationException(logMessage.getMessage(JWT_EXPIRED, expiration.toString()), e, logMessage.getMessage(JWT_EXPIRED_SOLUTION)); } String actualAlgorithm = jws.getHeader().getAlgorithm(); String expectedAlgorithm = SignatureAlgorithm.RS512.name(); if (!actualAlgorithm.equals(expectedAlgorithm)) { throw new MalformedParameterException( logMessage.getMessage(JWT_INVALID_ALGORITHM, actualAlgorithm), logMessage.getMessage(JWT_INVALID_ALGORITHM_SOLUTION, expectedAlgorithm)); } try { String json = new ObjectMapper().writeValueAsString(jws.getBody()); JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.deserialize(json, JwtPayload.class); } catch (JsonProcessingException | RemoteApiException e) { throw new MalformedParameterException(logMessage.getMessage(JWT_DESERIALIZE), e, logMessage.getMessage(JWT_DESERIALIZE_SOLUTION)); } }  @PostConstruct void init(); Long getUserIdFromAuthorizationHeader(String configurationId, String authorizationHeader); JwtPayload getJwtToken(String configurationId, String authorizationHeader); Long getUserId(JwtPayload token); String authenticate(String configurationId); boolean isValidTokenPair(String configurationId, String applicationToken,
      String symphonyToken); JwtPayload parseJwtPayload(String configurationId, String jwt); @Override boolean checkPodInfo(String configurationId, String podId);  }