CheckTokenEndpoint { @RequestMapping(value = "/oauth/check_token", method = RequestMethod.POST) @ResponseBody public Map<String, ?> checkToken(@RequestParam("token") String value) { OAuth2AccessToken token = resourceServerTokenServices.readAccessToken(value); if (token == null) { throw new InvalidTokenException("Token was not recognised"); } if (token.isExpired()) { throw new InvalidTokenException("Token has expired"); } OAuth2Authentication authentication = resourceServerTokenServices.loadAuthentication(token.getValue()); Map<String, Object> response = (Map<String, Object>)accessTokenConverter.convertAccessToken(token, authentication); response.put("active", true); return response; } CheckTokenEndpoint(ResourceServerTokenServices resourceServerTokenServices); void setExceptionTranslator(WebResponseExceptionTranslator<OAuth2Exception> exceptionTranslator); void setAccessTokenConverter(AccessTokenConverter accessTokenConverter); @RequestMapping(value = "/oauth/check_token", method = RequestMethod.POST) @ResponseBody Map<String, ?> checkToken(@RequestParam("token") String value); @ExceptionHandler(InvalidTokenException.class) ResponseEntity<OAuth2Exception> handleException(Exception e);  }
@Test public void checkTokenWhenTokenValidThenReturnActiveAttribute() throws Exception { Map<String, ?> response = this.checkTokenEndpoint.checkToken("access-token-1234"); Object active = response.get("active"); assertNotNull("active is null", active); assertEquals("active not true", Boolean.TRUE, active); }