@Test public void test_should_get_user_details_for_given_token() { OAuth2Authentication oAuth2Authentication = mock(OAuth2Authentication.class); final String accessToken = "c80e0ade-f48d-4077-b0d2-4e58526a6bfd"; when(tokenStore.readAuthentication(accessToken)).thenReturn(oAuth2Authentication); SecureUser secureUser = new SecureUser(getUser()); when(oAuth2Authentication.getPrincipal()).thenReturn(secureUser); final List<Action> expectedActions = getActions(); when(actionRestRepository.getActionByRoleCodes(getRoleCodes(), "default")).thenReturn(expectedActions); UserDetail actualUserDetails = tokenService.getUser(accessToken); assertEquals(secureUser, actualUserDetails.getSecureUser()); }
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);  }