@Test public void test_getAppTokenContents_invalidSignature() { String APP_ID = "app_id"; String APP_NAME = "app_name"; String PROVIDER_ID = "provider_id"; String TOKEN_ID = "token_id"; String wrongSigningSecret = "ar19Lgc6fKZ8LONpoDXE0bcn7gT+UJoy6ti7/PvmcvMg4GZMp5X2nvEkXpfhLzpdGYzULXWh4q/NJUANLr6yAA=="; String compactJws = Jwts .builder() .setSubject(APP_NAME) .claim("appId", APP_ID) .claim("tokenId", TOKEN_ID) .claim("providerId", PROVIDER_ID) .signWith(SignatureAlgorithm.HS512, wrongSigningSecret).compact(); IAppToken token = serviceToTest.getAppTokenContents(compactJws); Assert.assertNull(token); }
@Override public IAppToken getAppTokenContents(String token) { IAppToken appToken = new AppToken(); try { Jws<Claims> jws = Jwts.parser().setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)).parseClaimsJws(token); Claims claims = jws.getBody(); appToken.setAppId(claims.get("appId", String.class)); appToken.setId(claims.get("tokenId", String.class)); appToken.setProviderId(claims.get("providerId", String.class)); appToken.setAuthorizationType(claims.get("authorizationType", String.class)); } catch (io.jsonwebtoken.ExpiredJwtException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } catch (SignatureException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } return appToken; }
TokenService implements ITokenService { @Override public IAppToken getAppTokenContents(String token) { IAppToken appToken = new AppToken(); try { Jws<Claims> jws = Jwts.parser().setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)).parseClaimsJws(token); Claims claims = jws.getBody(); appToken.setAppId(claims.get("appId", String.class)); appToken.setId(claims.get("tokenId", String.class)); appToken.setProviderId(claims.get("providerId", String.class)); appToken.setAuthorizationType(claims.get("authorizationType", String.class)); } catch (io.jsonwebtoken.ExpiredJwtException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } catch (SignatureException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } return appToken; } }
TokenService implements ITokenService { @Override public IAppToken getAppTokenContents(String token) { IAppToken appToken = new AppToken(); try { Jws<Claims> jws = Jwts.parser().setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)).parseClaimsJws(token); Claims claims = jws.getBody(); appToken.setAppId(claims.get("appId", String.class)); appToken.setId(claims.get("tokenId", String.class)); appToken.setProviderId(claims.get("providerId", String.class)); appToken.setAuthorizationType(claims.get("authorizationType", String.class)); } catch (io.jsonwebtoken.ExpiredJwtException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } catch (SignatureException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } return appToken; }  }
TokenService implements ITokenService { @Override public IAppToken getAppTokenContents(String token) { IAppToken appToken = new AppToken(); try { Jws<Claims> jws = Jwts.parser().setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)).parseClaimsJws(token); Claims claims = jws.getBody(); appToken.setAppId(claims.get("appId", String.class)); appToken.setId(claims.get("tokenId", String.class)); appToken.setProviderId(claims.get("providerId", String.class)); appToken.setAuthorizationType(claims.get("authorizationType", String.class)); } catch (io.jsonwebtoken.ExpiredJwtException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } catch (SignatureException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } return appToken; }  @Override String generateApiToken(User user); @Override IApiTokenContents getApiTokenContents(String token); @Override IAppToken generateAppToken(IRegisteredApp app); @Override IAppToken getAppTokenContents(String token); }
TokenService implements ITokenService { @Override public IAppToken getAppTokenContents(String token) { IAppToken appToken = new AppToken(); try { Jws<Claims> jws = Jwts.parser().setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)).parseClaimsJws(token); Claims claims = jws.getBody(); appToken.setAppId(claims.get("appId", String.class)); appToken.setId(claims.get("tokenId", String.class)); appToken.setProviderId(claims.get("providerId", String.class)); appToken.setAuthorizationType(claims.get("authorizationType", String.class)); } catch (io.jsonwebtoken.ExpiredJwtException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } catch (SignatureException e) { messageHandler.handleMessage(e.getMessage(), e, MessageType.ERROR); return null; } return appToken; }  @Override String generateApiToken(User user); @Override IApiTokenContents getApiTokenContents(String token); @Override IAppToken generateAppToken(IRegisteredApp app); @Override IAppToken getAppTokenContents(String token);  }