How to Get the Current Logged-In Username or id in Spring Security

CustomUserDetail vasitesile

Object principal =  
        SecurityContextHolder
                .getContext()
                .getAuthentication()
                .getPrincipal();

if(principal instanceof CustomUserDetail){ 
    //some code
} else {
    //some code
}

Comments

Popular posts from this blog

Validation for AZ phone numbers with RegEx in Java

Java necə işləyir, kod nədir ?