@Test public void test_validateToken_revokedId() throws GeneralSecurityException, IOException, InvalidTokenException { IRegisteredApp app = new RegisteredApp(); app.setId(REVOKED_APP_ID); app.setName("App"); app.setTokenIds(Arrays.asList(TOKEN_ID)); Mockito.when(appManager.getApp(REVOKED_APP_ID)).thenReturn(app); CheckerResult result = checkerToTest.validateToken(REVOKED_TOKEN, APP_ID); Assert.assertEquals(ValidationResult.REVOKED, result.getResult()); Assert.assertNotNull(result.getPayload()); }
@Override public CheckerResult validateToken(String token, String appId) throws GeneralSecurityException, IOException, InvalidTokenException { IAppToken appToken; try { appToken = tokenService.getAppTokenContents(token); } catch (MalformedJwtException | IllegalArgumentException e) { throw new InvalidTokenException("The provided token is not a valid JWT token.", e); } CheckerResult result = new CheckerResult(); result.setPayload(appToken); if (appToken == null) { result.setResult(ValidationResult.INVALID); return result; } IRegisteredApp registeredApp = appManager.getApp(appToken.getAppId()); if (registeredApp == null) { result.setResult(ValidationResult.REVOKED); return result; } if (registeredApp.getTokenIds().contains(appToken.getId())) { result.setResult(ValidationResult.VALID); return result; } result.setResult(ValidationResult.REVOKED); return result; }
AppTokenChecker implements IChecker { @Override public CheckerResult validateToken(String token, String appId) throws GeneralSecurityException, IOException, InvalidTokenException { IAppToken appToken; try { appToken = tokenService.getAppTokenContents(token); } catch (MalformedJwtException | IllegalArgumentException e) { throw new InvalidTokenException("The provided token is not a valid JWT token.", e); } CheckerResult result = new CheckerResult(); result.setPayload(appToken); if (appToken == null) { result.setResult(ValidationResult.INVALID); return result; } IRegisteredApp registeredApp = appManager.getApp(appToken.getAppId()); if (registeredApp == null) { result.setResult(ValidationResult.REVOKED); return result; } if (registeredApp.getTokenIds().contains(appToken.getId())) { result.setResult(ValidationResult.VALID); return result; } result.setResult(ValidationResult.REVOKED); return result; } }
AppTokenChecker implements IChecker { @Override public CheckerResult validateToken(String token, String appId) throws GeneralSecurityException, IOException, InvalidTokenException { IAppToken appToken; try { appToken = tokenService.getAppTokenContents(token); } catch (MalformedJwtException | IllegalArgumentException e) { throw new InvalidTokenException("The provided token is not a valid JWT token.", e); } CheckerResult result = new CheckerResult(); result.setPayload(appToken); if (appToken == null) { result.setResult(ValidationResult.INVALID); return result; } IRegisteredApp registeredApp = appManager.getApp(appToken.getAppId()); if (registeredApp == null) { result.setResult(ValidationResult.REVOKED); return result; } if (registeredApp.getTokenIds().contains(appToken.getId())) { result.setResult(ValidationResult.VALID); return result; } result.setResult(ValidationResult.REVOKED); return result; }  }
AppTokenChecker implements IChecker { @Override public CheckerResult validateToken(String token, String appId) throws GeneralSecurityException, IOException, InvalidTokenException { IAppToken appToken; try { appToken = tokenService.getAppTokenContents(token); } catch (MalformedJwtException | IllegalArgumentException e) { throw new InvalidTokenException("The provided token is not a valid JWT token.", e); } CheckerResult result = new CheckerResult(); result.setPayload(appToken); if (appToken == null) { result.setResult(ValidationResult.INVALID); return result; } IRegisteredApp registeredApp = appManager.getApp(appToken.getAppId()); if (registeredApp == null) { result.setResult(ValidationResult.REVOKED); return result; } if (registeredApp.getTokenIds().contains(appToken.getId())) { result.setResult(ValidationResult.VALID); return result; } result.setResult(ValidationResult.REVOKED); return result; }  @Override String getId(); @Override CheckerResult validateToken(String token, String appId); }
AppTokenChecker implements IChecker { @Override public CheckerResult validateToken(String token, String appId) throws GeneralSecurityException, IOException, InvalidTokenException { IAppToken appToken; try { appToken = tokenService.getAppTokenContents(token); } catch (MalformedJwtException | IllegalArgumentException e) { throw new InvalidTokenException("The provided token is not a valid JWT token.", e); } CheckerResult result = new CheckerResult(); result.setPayload(appToken); if (appToken == null) { result.setResult(ValidationResult.INVALID); return result; } IRegisteredApp registeredApp = appManager.getApp(appToken.getAppId()); if (registeredApp == null) { result.setResult(ValidationResult.REVOKED); return result; } if (registeredApp.getTokenIds().contains(appToken.getId())) { result.setResult(ValidationResult.VALID); return result; } result.setResult(ValidationResult.REVOKED); return result; }  @Override String getId(); @Override CheckerResult validateToken(String token, String appId); final static String ID; }