#AI
zhou zhou
8 小时以前 51877df13075ad10ef51107f15bcd21f1661febe
rsf-server/src/main/java/com/vincent/rsf/server/system/controller/BaseController.java
@@ -5,6 +5,7 @@
import com.vincent.rsf.server.common.domain.BaseParam;
import com.vincent.rsf.server.system.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.List;
@@ -39,6 +40,26 @@
    public Long getTenantId() {
        User loginUser = getLoginUser();
        return loginUser == null ? null : loginUser.getTenantId();
    }
    public boolean hasAuthority(String authority) {
        if (authority == null || authority.trim().isEmpty()) {
            return false;
        }
        try {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication == null || authentication.getAuthorities() == null) {
                return false;
            }
            for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
                if (grantedAuthority != null && authority.equals(grantedAuthority.getAuthority())) {
                    return true;
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return false;
    }
    public <T extends BaseParam> T buildParam(Map<String, Object> map, Class<T> clz) {
@@ -85,3 +106,4 @@
    }
}