@Test public void testGetCurrentUser() { String login = "waiter"; String password = "waiter"; SecurityRestService securityService = getServiceClientFactory().create(SecurityRestService.class, new ServiceClientConfigBuilder().host("localhost").authBasic().userLogin(login).userPassword(password) .buildMap()); UserProfileTo userProfile = securityService.getCurrentUser(); assertThat(userProfile.getLogin()).isEqualTo(login); }
@Override @PermitAll public UserProfileTo getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = null; if (context != null) { authentication = context.getAuthentication(); } if (authentication == null) { throw new NoActiveUserException(); } UserDetails user = (UserDetails) authentication.getPrincipal(); UserProfileTo profile = new UserProfileTo(); profile.setLogin(user.getUsername()); return profile; }
SecurityRestServiceImpl implements SecurityRestService { @Override @PermitAll public UserProfileTo getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = null; if (context != null) { authentication = context.getAuthentication(); } if (authentication == null) { throw new NoActiveUserException(); } UserDetails user = (UserDetails) authentication.getPrincipal(); UserProfileTo profile = new UserProfileTo(); profile.setLogin(user.getUsername()); return profile; } }
SecurityRestServiceImpl implements SecurityRestService { @Override @PermitAll public UserProfileTo getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = null; if (context != null) { authentication = context.getAuthentication(); } if (authentication == null) { throw new NoActiveUserException(); } UserDetails user = (UserDetails) authentication.getPrincipal(); UserProfileTo profile = new UserProfileTo(); profile.setLogin(user.getUsername()); return profile; }  }
SecurityRestServiceImpl implements SecurityRestService { @Override @PermitAll public UserProfileTo getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = null; if (context != null) { authentication = context.getAuthentication(); } if (authentication == null) { throw new NoActiveUserException(); } UserDetails user = (UserDetails) authentication.getPrincipal(); UserProfileTo profile = new UserProfileTo(); profile.setLogin(user.getUsername()); return profile; }  @Override @PermitAll CsrfToken getCsrfToken(HttpServletRequest request, HttpServletResponse response); @Override @PermitAll UserProfileTo getCurrentUser(); @Inject void setCsrfTokenRepository(CsrfTokenRepository csrfTokenRepository); }
SecurityRestServiceImpl implements SecurityRestService { @Override @PermitAll public UserProfileTo getCurrentUser() { SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = null; if (context != null) { authentication = context.getAuthentication(); } if (authentication == null) { throw new NoActiveUserException(); } UserDetails user = (UserDetails) authentication.getPrincipal(); UserProfileTo profile = new UserProfileTo(); profile.setLogin(user.getUsername()); return profile; }  @Override @PermitAll CsrfToken getCsrfToken(HttpServletRequest request, HttpServletResponse response); @Override @PermitAll UserProfileTo getCurrentUser(); @Inject void setCsrfTokenRepository(CsrfTokenRepository csrfTokenRepository);  }