@Test public void refreshToken() throws Exception { final RefreshTokenPayload payload = new RefreshTokenPayload(refreshToken); final ConstrainedFields fields = new ConstrainedFields(RefreshTokenPayload.class); mvc.perform( post(apiPrefix + "/" + SecurityConst.ACCESS_TOKEN_URL).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(payload)) ).andExpect(status().isOk()) .andDo( restDocResHandler.document( requestFields( fields.withPath("refreshToken") .description("The refresh token provided when login was " + "previously performed") ) ) ); }
@PostMapping(SecurityConst.ACCESS_TOKEN_URL) public Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload) { String oldRefreshToken = payload.getRefreshToken(); if (oldRefreshToken != null) { try { String[] keys = {sc.getAuthoritiesHolder()}; Map<String, Object> claims = jwtService.getClaimsExtended(oldRefreshToken, keys); String sub = claims.get(JWTService.SUBJECT).toString(); String authorities = claims.get(keys[0]).toString(); Date iat = (Date) claims.get(JWTService.ISSUED_AT); String newAccessToken = jwtService.createToken(sub, authorities); String newRefreshToken = jwtService.createRefreshToken(sub, authorities); return jwtService.createLoginData(sub, newAccessToken, iat, authorities, newRefreshToken); } catch (JwtException e) { throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.invalid"); } } throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.required"); }
SecurityController { @PostMapping(SecurityConst.ACCESS_TOKEN_URL) public Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload) { String oldRefreshToken = payload.getRefreshToken(); if (oldRefreshToken != null) { try { String[] keys = {sc.getAuthoritiesHolder()}; Map<String, Object> claims = jwtService.getClaimsExtended(oldRefreshToken, keys); String sub = claims.get(JWTService.SUBJECT).toString(); String authorities = claims.get(keys[0]).toString(); Date iat = (Date) claims.get(JWTService.ISSUED_AT); String newAccessToken = jwtService.createToken(sub, authorities); String newRefreshToken = jwtService.createRefreshToken(sub, authorities); return jwtService.createLoginData(sub, newAccessToken, iat, authorities, newRefreshToken); } catch (JwtException e) { throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.invalid"); } } throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.required"); } }
SecurityController { @PostMapping(SecurityConst.ACCESS_TOKEN_URL) public Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload) { String oldRefreshToken = payload.getRefreshToken(); if (oldRefreshToken != null) { try { String[] keys = {sc.getAuthoritiesHolder()}; Map<String, Object> claims = jwtService.getClaimsExtended(oldRefreshToken, keys); String sub = claims.get(JWTService.SUBJECT).toString(); String authorities = claims.get(keys[0]).toString(); Date iat = (Date) claims.get(JWTService.ISSUED_AT); String newAccessToken = jwtService.createToken(sub, authorities); String newRefreshToken = jwtService.createRefreshToken(sub, authorities); return jwtService.createLoginData(sub, newAccessToken, iat, authorities, newRefreshToken); } catch (JwtException e) { throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.invalid"); } } throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.required"); }  }
SecurityController { @PostMapping(SecurityConst.ACCESS_TOKEN_URL) public Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload) { String oldRefreshToken = payload.getRefreshToken(); if (oldRefreshToken != null) { try { String[] keys = {sc.getAuthoritiesHolder()}; Map<String, Object> claims = jwtService.getClaimsExtended(oldRefreshToken, keys); String sub = claims.get(JWTService.SUBJECT).toString(); String authorities = claims.get(keys[0]).toString(); Date iat = (Date) claims.get(JWTService.ISSUED_AT); String newAccessToken = jwtService.createToken(sub, authorities); String newRefreshToken = jwtService.createRefreshToken(sub, authorities); return jwtService.createLoginData(sub, newAccessToken, iat, authorities, newRefreshToken); } catch (JwtException e) { throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.invalid"); } } throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.required"); }  @PostMapping("${gms.security.sign_up_url}") @ResponseStatus(HttpStatus.CREATED) @ResponseBody ResponseEntity<EUser> signUpUser(@RequestBody @Valid final Resource<? extends EUser> user); @PostMapping(SecurityConst.ACCESS_TOKEN_URL) Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload); }
SecurityController { @PostMapping(SecurityConst.ACCESS_TOKEN_URL) public Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload) { String oldRefreshToken = payload.getRefreshToken(); if (oldRefreshToken != null) { try { String[] keys = {sc.getAuthoritiesHolder()}; Map<String, Object> claims = jwtService.getClaimsExtended(oldRefreshToken, keys); String sub = claims.get(JWTService.SUBJECT).toString(); String authorities = claims.get(keys[0]).toString(); Date iat = (Date) claims.get(JWTService.ISSUED_AT); String newAccessToken = jwtService.createToken(sub, authorities); String newRefreshToken = jwtService.createRefreshToken(sub, authorities); return jwtService.createLoginData(sub, newAccessToken, iat, authorities, newRefreshToken); } catch (JwtException e) { throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.invalid"); } } throw new GmsSecurityException(SecurityConst.ACCESS_TOKEN_URL, "security.token.refresh.required"); }  @PostMapping("${gms.security.sign_up_url}") @ResponseStatus(HttpStatus.CREATED) @ResponseBody ResponseEntity<EUser> signUpUser(@RequestBody @Valid final Resource<? extends EUser> user); @PostMapping(SecurityConst.ACCESS_TOKEN_URL) Map<String, Object> refreshToken(@Valid @RequestBody final RefreshTokenPayload payload);  }