@Test(expected = InvalidAccessTokenException.class) public void test_should_throw_exception_when_access_token_is_not_present_in_token_store() { when(tokenStore.readAuthentication("accessToken")).thenReturn(null); tokenService.getUser("accessToken"); }
public UserDetail getUser(String accessToken) { if (StringUtils.isEmpty(accessToken)) { throw new InvalidAccessTokenException(); } OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken); if (authentication == null) { throw new InvalidAccessTokenException(); } SecureUser secureUser = ((SecureUser) authentication.getPrincipal()); return new UserDetail(secureUser, null); }
TokenService { public UserDetail getUser(String accessToken) { if (StringUtils.isEmpty(accessToken)) { throw new InvalidAccessTokenException(); } OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken); if (authentication == null) { throw new InvalidAccessTokenException(); } SecureUser secureUser = ((SecureUser) authentication.getPrincipal()); return new UserDetail(secureUser, null); } }
TokenService { public UserDetail getUser(String accessToken) { if (StringUtils.isEmpty(accessToken)) { throw new InvalidAccessTokenException(); } OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken); if (authentication == null) { throw new InvalidAccessTokenException(); } SecureUser secureUser = ((SecureUser) authentication.getPrincipal()); return new UserDetail(secureUser, null); } private  TokenService(TokenStore tokenStore, ActionRestRepository actionRestRepository); }
TokenService { public UserDetail getUser(String accessToken) { if (StringUtils.isEmpty(accessToken)) { throw new InvalidAccessTokenException(); } OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken); if (authentication == null) { throw new InvalidAccessTokenException(); } SecureUser secureUser = ((SecureUser) authentication.getPrincipal()); return new UserDetail(secureUser, null); } private  TokenService(TokenStore tokenStore, ActionRestRepository actionRestRepository); UserDetail getUser(String accessToken); }
TokenService { public UserDetail getUser(String accessToken) { if (StringUtils.isEmpty(accessToken)) { throw new InvalidAccessTokenException(); } OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken); if (authentication == null) { throw new InvalidAccessTokenException(); } SecureUser secureUser = ((SecureUser) authentication.getPrincipal()); return new UserDetail(secureUser, null); } private  TokenService(TokenStore tokenStore, ActionRestRepository actionRestRepository); UserDetail getUser(String accessToken);  }