@Test public void test_generateAppToken() { String APP_ID = "app_id"; String APP_NAME = "app_name"; String PROVIDER_CLIENT_ID = "provider_client_id"; String PROVIDER_ID = "provider_id"; IRegisteredApp app = new RegisteredApp(); app.setId(APP_ID); app.setName(APP_NAME); app.setProviderClientId(PROVIDER_CLIENT_ID); app.setProviderId(PROVIDER_ID); IAppToken token = serviceToTest.generateAppToken(app); Assert.assertEquals(APP_ID, token.getAppId()); Assert.assertEquals(PROVIDER_ID, token.getProviderId()); Assert.assertNotNull(token.getId()); Jws<Claims> jws = Jwts .parser() .setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .parseClaimsJws(token.getToken()); Claims claims = jws.getBody(); Assert.assertEquals(APP_NAME, claims.getSubject()); Assert.assertEquals(APP_ID, claims.get("appId")); Assert.assertEquals(PROVIDER_ID, claims.get("providerId")); Assert.assertEquals(token.getId(), claims.get("tokenId")); }
@Override public IAppToken generateAppToken(IRegisteredApp app) { String tokenId = UUID.randomUUID().toString(); String compactJws = Jwts.builder() .setSubject(app.getName()) .claim("appId", app.getId()) .claim("tokenId", tokenId) .claim("providerId", app.getProviderId()) .claim("authorizationType", app.getAuthorizationType()) .signWith(SignatureAlgorithm.HS256, propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .compact(); IAppToken token = new AppToken(); token.setToken(compactJws); token.setId(tokenId); token.setAppId(app.getId()); token.setProviderId(app.getProviderId()); token.setAuthorizationType(app.getAuthorizationType()); return token; }
TokenService implements ITokenService { @Override public IAppToken generateAppToken(IRegisteredApp app) { String tokenId = UUID.randomUUID().toString(); String compactJws = Jwts.builder() .setSubject(app.getName()) .claim("appId", app.getId()) .claim("tokenId", tokenId) .claim("providerId", app.getProviderId()) .claim("authorizationType", app.getAuthorizationType()) .signWith(SignatureAlgorithm.HS256, propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .compact(); IAppToken token = new AppToken(); token.setToken(compactJws); token.setId(tokenId); token.setAppId(app.getId()); token.setProviderId(app.getProviderId()); token.setAuthorizationType(app.getAuthorizationType()); return token; } }
TokenService implements ITokenService { @Override public IAppToken generateAppToken(IRegisteredApp app) { String tokenId = UUID.randomUUID().toString(); String compactJws = Jwts.builder() .setSubject(app.getName()) .claim("appId", app.getId()) .claim("tokenId", tokenId) .claim("providerId", app.getProviderId()) .claim("authorizationType", app.getAuthorizationType()) .signWith(SignatureAlgorithm.HS256, propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .compact(); IAppToken token = new AppToken(); token.setToken(compactJws); token.setId(tokenId); token.setAppId(app.getId()); token.setProviderId(app.getProviderId()); token.setAuthorizationType(app.getAuthorizationType()); return token; }  }
TokenService implements ITokenService { @Override public IAppToken generateAppToken(IRegisteredApp app) { String tokenId = UUID.randomUUID().toString(); String compactJws = Jwts.builder() .setSubject(app.getName()) .claim("appId", app.getId()) .claim("tokenId", tokenId) .claim("providerId", app.getProviderId()) .claim("authorizationType", app.getAuthorizationType()) .signWith(SignatureAlgorithm.HS256, propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .compact(); IAppToken token = new AppToken(); token.setToken(compactJws); token.setId(tokenId); token.setAppId(app.getId()); token.setProviderId(app.getProviderId()); token.setAuthorizationType(app.getAuthorizationType()); return token; }  @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 generateAppToken(IRegisteredApp app) { String tokenId = UUID.randomUUID().toString(); String compactJws = Jwts.builder() .setSubject(app.getName()) .claim("appId", app.getId()) .claim("tokenId", tokenId) .claim("providerId", app.getProviderId()) .claim("authorizationType", app.getAuthorizationType()) .signWith(SignatureAlgorithm.HS256, propertiesManager.getProperty(Properties.SIGNING_KEY_APPS)) .compact(); IAppToken token = new AppToken(); token.setToken(compactJws); token.setId(tokenId); token.setAppId(app.getId()); token.setProviderId(app.getProviderId()); token.setAuthorizationType(app.getAuthorizationType()); return token; }  @Override String generateApiToken(User user); @Override IApiTokenContents getApiTokenContents(String token); @Override IAppToken generateAppToken(IRegisteredApp app); @Override IAppToken getAppTokenContents(String token);  }