Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package co.com.soinsoftware.altablero.utils; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; /** * * @author Carlos Rodriguez */ public class AuthenticationUtils { public static boolean isAnonymusAuthentication() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth instanceof AnonymousAuthenticationToken; } public static String getDocumentNumberFromAuthentication() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth.getName(); } public static void setAnonymusAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.clearContext(); } }