master
parent
61a880688d
commit
96aab84b83
|
|
@ -1,5 +1,6 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import com.boot.security.server.dto.LoginUser;
|
||||
|
|
@ -7,9 +8,12 @@ import com.boot.security.server.dto.LoginUser;
|
|||
public class UserUtil {
|
||||
|
||||
public static LoginUser getLoginUser() {
|
||||
LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null) {
|
||||
return (LoginUser) authentication.getPrincipal();
|
||||
}
|
||||
|
||||
return loginUser;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue