@Test public void isCurrentUserAuthenticatedShouldNotBeAuthenticatedWhenUserIsLoggedAndNotAuthenticated() { UserDetailsAdapter userDetailsAdapter = new UserDetailsAdapter(USER_ID, USER_PASSWORD, USER_NAME); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken(userDetailsAdapter, null)); boolean result = springSecurityAuthenticationService.isCurrentUserAuthenticated(); assertFalse(result); }
@Override public boolean isCurrentUserAuthenticated() { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated() && !(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken); }
SpringSecurityAuthenticationService implements AuthenticationService { @Override public boolean isCurrentUserAuthenticated() { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated() && !(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken); } }
SpringSecurityAuthenticationService implements AuthenticationService { @Override public boolean isCurrentUserAuthenticated() { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated() && !(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken); }  }
SpringSecurityAuthenticationService implements AuthenticationService { @Override public boolean isCurrentUserAuthenticated() { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated() && !(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken); }  @Override UserDetailsAdapter getCurrentUserDetails(); @Override boolean isCurrentUserAuthenticated(); }
SpringSecurityAuthenticationService implements AuthenticationService { @Override public boolean isCurrentUserAuthenticated() { return SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated() && !(SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken); }  @Override UserDetailsAdapter getCurrentUserDetails(); @Override boolean isCurrentUserAuthenticated();  }