We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package com.crane.framework.satoken;
import cn.dev33.satoken.stp.StpInterface; import cn.dev33.satoken.stp.StpUtil; import java.util.List;
import com.crane.framework.utils.SystemUtil; import org.springframework.stereotype.Component;
/** 注入权限组 */ @component public class StpInterfaceImpl implements StpInterface {
/**
import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.stp.StpUtil; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@configuration public class SaTokenConfigure implements WebMvcConfigurer {
private static final List excludePath = List.of( "/api/v1.0/user/login", "/doc.html", "/favicon.ico", "/webjars/", "/v3/api-docs/");
// 注册拦截器 @OverRide public void addInterceptors(InterceptorRegistry registry) { // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。 registry .addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) .addPathPatterns("/**") .excludePathPatterns(excludePath); } }
@SaCheckRole(value = {"admin", "root"}) @operation(summary = "获取用户列表") @PostMapping("/pageUserList") public Page pageUserList(@requestbody UserPageDTO userPageDTO) { return userService.getUserList(userPageDTO); }
private SaTokenInfo login(User user, Object id, List roleList) { // 登录获取token信息 StpUtil.login(id); SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
// 获取角色信息 List<String> roleStringList = new ArrayList<>(); if (CommonUtil.notNullOrEmpty(roleList)) { roleStringList = roleList.stream().map(Role::getRoleSign).collect(Collectors.toList()); } // 注入sa-token StpUtil.getSession().set("roleList", roleStringList); StpUtil.getSession().set("tenantId", user.getTenantId()); StpUtil.getSession().set("loginName", user.getUsername()); return tokenInfo;
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
package com.crane.framework.satoken;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import java.util.List;
import com.crane.framework.utils.SystemUtil;
import org.springframework.stereotype.Component;
/** 注入权限组 */
@component
public class StpInterfaceImpl implements StpInterface {
/**
*/
@OverRide
public List getPermissionList(Object loginId, String s) {
Object authList = StpUtil.getSession().get("authList");
return SystemUtil.object2List(authList, String.class);
}
/**
*/
@OverRide
public List getRoleList(Object loginId, String s) {
Object roleList = StpUtil.getSession().get("roleList");
return SystemUtil.object2List(roleList, String.class);
}
}
package com.crane.framework.satoken;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@configuration
public class SaTokenConfigure implements WebMvcConfigurer {
private static final List excludePath =
List.of(
"/api/v1.0/user/login", "/doc.html", "/favicon.ico", "/webjars/", "/v3/api-docs/");
// 注册拦截器
@OverRide
public void addInterceptors(InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
registry
.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
.addPathPatterns("/**")
.excludePathPatterns(excludePath);
}
}
@SaCheckRole(value = {"admin", "root"})
@operation(summary = "获取用户列表")
@PostMapping("/pageUserList")
public Page pageUserList(@requestbody UserPageDTO userPageDTO) {
return userService.getUserList(userPageDTO);
}
private SaTokenInfo login(User user, Object id, List roleList) {
// 登录获取token信息
StpUtil.login(id);
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
}
The text was updated successfully, but these errors were encountered: