StpInterfaceImpl.java
1.21 KB
package vion.interceptor;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.lang.Opt;
import org.springframework.stereotype.Component;
import vion.model.Resource;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2023/11/28
*/
@Component
public class StpInterfaceImpl implements StpInterface {
@Override
public List<String> getPermissionList(Object loginId, String loginType) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
return Opt.ofEmptyAble(userVO.getResourceList())
.map(l -> l.stream().map(Resource::getPerm).collect(Collectors.toList()))
.orElse(ListUtil.empty());
}
@Override
public List<String> getRoleList(Object loginId, String loginType) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
List<RoleVO> roleVOList = userVO.getRoleVOList();
return Opt.ofEmptyAble(roleVOList).map(list -> list.stream().map(RoleVO::getCode).collect(Collectors.toList())).orElse(ListUtil.empty());
}
}