wu
2023-12-01 8a0ae6d19d78d2295a10b1cc97bfe17e651234ea
springboot-vue3/src/main/java/com/example/springboot/security/util/SecurityUtil.java
New file
@@ -0,0 +1,20 @@
package com.example.springboot.security.util;
import com.example.springboot.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
public class SecurityUtil {
    /**
     * 获取当前登录用户
     *
     * @return
     */
    public static User getCurrentUser() {
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated() && !subject.isRemembered()) {
            throw new RuntimeException("Log current user error: UnAuthenticated subject");
        }
        return (User) subject.getPrincipal();
    }
}