@SuppressWarnings("unchecked") @Test void currentUserIsAuthenticated_falseAnonymous() { Authentication anonymousAuthentication = mock(AnonymousAuthenticationToken.class); when(anonymousAuthentication.isAuthenticated()).thenReturn(true); GrantedAuthority authoritySu = mock(GrantedAuthority.class); when(authoritySu.getAuthority()).thenReturn("ROLE_ANONYMOUS"); when((Collection<GrantedAuthority>) anonymousAuthentication.getAuthorities()) .thenReturn(Collections.singletonList(authoritySu)); assertFalse(SecurityUtils.currentUserIsAuthenticated()); }
public static boolean currentUserIsAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && !currentUserIsAnonymous(); }
SecurityUtils { public static boolean currentUserIsAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && !currentUserIsAnonymous(); } }
SecurityUtils { public static boolean currentUserIsAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && !currentUserIsAnonymous(); } private  SecurityUtils(); }
SecurityUtils { public static boolean currentUserIsAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && !currentUserIsAnonymous(); } private  SecurityUtils(); static @Nullable @CheckForNull String getCurrentUsername(); static boolean currentUserHasRole(String... roles); static boolean currentUserIsSuOrSystem(); static boolean currentUserIsSu(); static boolean currentUserIsSystem(); static boolean currentUserIsAuthenticated(); static boolean currentUserIsAnonymous(); }
SecurityUtils { public static boolean currentUserIsAuthenticated() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && !currentUserIsAnonymous(); } private  SecurityUtils(); static @Nullable @CheckForNull String getCurrentUsername(); static boolean currentUserHasRole(String... roles); static boolean currentUserIsSuOrSystem(); static boolean currentUserIsSu(); static boolean currentUserIsSystem(); static boolean currentUserIsAuthenticated(); static boolean currentUserIsAnonymous(); static final String ANONYMOUS_USERNAME; static final String AUTHORITY_SU; static final String AUTHORITY_ANONYMOUS; static final String AUTHORITY_USER; static final String ROLE_SYSTEM; static final String ROLE_ACL_TAKE_OWNERSHIP; static final String ROLE_ACL_MODIFY_AUDITING; static final String ROLE_ACL_GENERAL_CHANGES; }