求助,shiro报错org.apache.shiro.UnavailableSecurityManagerException,帮忙看一下

码旺 码旺 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- Shiro的核心安全接口,这个属性是必须的 -->
<property name="securityManager" ref="securityManager"/>
<!-- 要求登录时的链接(可根据项目的URL进行替换),非必须的属性,默认会自动寻找Web工程根目录下的"/login.jsp"页面 -->
<property name="loginUrl" value="/user/login.do"/>
<!-- 登录成功后要跳转的连接(本例中此属性用不到,因为登录成功后的处理逻辑在LoginController里硬编码了) -->
<property name="successUrl" value="/system/pay.do"/>
<!-- 用户访问未对其授权的资源时,所显示的连接 -->
<property name="unauthorizedUrl" value="/page/error/401.jsp"/>
<!-- Shiro连接约束配置,即过滤链的定义 -->
<!-- 下面value值的第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的 -->
<!-- anon:它对应的过滤器里面是空的,什么都没做,这里.do和.jsp后面的*表示参数,比方说login.jsp?main这种 -->
<!-- authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter -->
<property name="filters">
<util:map>
<entry key="authc" value-ref="loginAuthenticationFilter"/>
<entry key="examine" value-ref="loginExamineFilter"/>
<entry key="anyRoles" value-ref="anyRoles"/>
<!--<entry key="ssl" value-ref="sslFilter"/>-->
</util:map>
</property>


<property name="filterChainDefinitions">
<value>
<!-- 登陆拦截 -->
<!-- /**=ssl -->
/user/toLogin**=examine,authc

<!-- 退出拦截 -->
/user/logout**=logout

<!-- 登陆判断拦截,如果已经登陆跳转至主页面 -->
/page/jsp/login.jsp**=examine
/user/login**=examine

<!-- 无需拦截 -->
/jcaptcha**=anon
/host/toRegister.do=anon
/host/register.do=anon
/host/toChangePwd.do=anon
/host/checkInviteCode.do=anon
/host/checkHostName.do=anon
/host/consume.do=anon
/host/findAllAreasInfo.do=anon
/host/findAllAreasInfoPid/**=anon
/host/checkEmployeeBean.do=anon
/host/checkValidateCodecode.do=anon
/client/toUpdate.do=anon
/client/toUpdate2.do=anon
/client/changePassword.do=anon
/system/left.do=anon
/**/error/*.jsp=anon

<!-- 权限拦截 -->

/account/**=roles[communal]
/userRole/**=anyRoles[admin,isShopMan]

<!-- 页面拦截,给角色赋予了权限才能登陆此页面
而在LoginRealm中使用的是Permission而不是Role
-->
/order/index.do=roles[orderIn]
/product/select.do=roles[productManage]
/product/consume.do=roles[consume]
/product/member.do=roles[member]
/product/storage.do=roles[storage]
/system/pay.do=roles[localPay]
/account/index.do=roles[bllAccount]
/account/toMoneyMove.do=roles[moneyMove]
/client/tohuiyuan.do=roles[procurement]
/account/withdrawMoney.do=roles[withdrawMoney]
/userRole/toclerklist.do=roles[clerkManage]
/account/index.do=roles[bllBalance]
/invite/index.do=roles[registeRaudit]
/invite/showHostInfo.do=roles[hostInfoaudit]
/invite/showClientInfo.do=roles[bllNewsUpdate]
/role/tolist.do=roles[roleManage]
/userRole/tolist.do=roles[userManage]
/account/financeToMoney.do=roles[financeToMoney]
/invite/bllAllot.do=roles[bllAllot]

<!-- 域名访问,未登录跳转登陆页面,已登陆根据角色跳转对应主页面 -->
/=examine
</value>
</property>
</bean>



<bean id="sslFilter" class="org.apache.shiro.web.filter.authz.SslFilter">
<property name="port" value="8443"/>
</bean>

<bean id="loginAuthenticationFilter" class="com.ssxt.ycfxf.host.filter.LoginAuthenticationFilter">
<property name="loginUrl" value="/user/toLogin.do"/>
</bean>
<bean id="loginExamineFilter" class="com.ssxt.ycfxf.host.filter.LoginExamineFilter">
</bean>

<!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

<bean id="loginRealm" class="com.ssxt.ycfxf.host.realm.LoginRealm"></bean>

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="loginRealm"/>
</bean>

<!--自定义的Roles Filter-->
<bean id="anyRoles" class="com.ssxt.ycfxf.host.filter.CustomRolesAuthorizationFilter" />

</beans>


而在LoginRealm中页面拦截我使用的是Permission而不是Role,而且是通过从数据库里面取出动态获取的。
LoginRealm代码如下
public class LoginRealm extends AuthorizingRealm {

@Autowired
private UserService userService;

@Autowired
private RegisterInfoService registerInfoService;

@Autowired
private EmpRoleService empRoleService;

@Autowired
private RoleService roleService;

@Autowired
private MenuService menuService;

@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
HostEmployeeBean he = (HostEmployeeBean) principals.getPrimaryPrincipal();

if (he != null) {
EmployeeBean emp = registerInfoService.findEmployeeByUserName(he.getUserName());
EmpRole empRole = empRoleService.findEmpRoleByEmpId(emp.getId());
Role role = roleService.getRoleById(empRole.getRoleId());
// List<String> perms =menuService.getPermsByRoleid(empRole.getRoleId());
List<Map<String, Object>> menus =menuService.getPermsByRoleid(empRole.getRoleId());
if(role != null) {
int status = role.getRoleStatus();
if(status == 0 || status == 2) {
// 后台管理员登陆
info.addRole(Constant.SPECIAL_ROLE);
info.addRole("communal");
} else {
//店铺方登录
info.addRole(Constant.ORDINARY_ROLE);
info.addRole("communal");
/* info.addRole(Constant.MODEL_POWER);*/
if(role.getName().equals(PropertiesUtil.propertiesMessage("isShopMan"))) {
info.addRole(Constant.MODEL_POWER);
}
}
}
else {
//店铺方登录
info.addRole(Constant.ORDINARY_ROLE);
info.addRole("communal");

}
if (menus != null && menus.size() > 0) {
for (Map<String, Object> m : menus) {
if(m !=null && ((String)m.get("id")).length()==3){
info.addRole((String)m.get("perName"));
} else if(m !=null && ((String)m.get("id")).length()==5){
//这里使用的是Permission而不是Role
info.addStringPermission((String)m.get("perName"));
}
}
}

}
return info;
}

@Override
protected AuthenticationInfo doGetAuthenticationInfo(
AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
String password = new String((char[]) upToken.getPassword());
String username = upToken.getUsername();
if(StringUtils.isEmpty(password) && StringUtils.isEmpty(username)){
// 前期验证出错,直接抛出异常让Controller处理
throw new AuthenticationException();
}

// 查询数据库
HostEmployeeBean he = userService.login(username, password);
if (he != null && he.getEmpId() != null && !"".equals(he.getEmpId().trim())) {
// 登陆成功,保存用户信息到Shiro对象中
return new SimpleAuthenticationInfo(he, password, getName());
} else {
// 用户名或密码有误,登陆失败
throw new UnknownAccountException();
}
}

@Override
public void clearCachedAuthorizationInfo(PrincipalCollection principals) {
super.clearCachedAuthorizationInfo(principals);
}

@Override
public void clearCachedAuthenticationInfo(PrincipalCollection principals) {
super.clearCachedAuthenticationInfo(principals);
}

@Override
public void clearCache(PrincipalCollection principals) {
super.clearCache(principals);
}

public void clearAllCachedAuthorizationInfo() {
getAuthorizationCache().clear();
}

public void clearAllCachedAuthenticationInfo() {
getAuthenticationCache().clear();
}

public void clearAllCache() {
clearAllCachedAuthenticationInfo();
clearAllCachedAuthorizationInfo();
}
}


然后打开赋予权限的页面就会报错:
严重: Servlet.service() for servlet jsp threw exception
org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)

Caused by: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)

但是对项目运行无影响,我调试了半天也没弄好,大神们帮忙看看是哪里出问题了,在线等

...全文

相关推荐

build-bluez-static.sh

# BlueZ 5.77 交叉编译脚本 (动态链接, 可在 OpenHarmony 上运行) # 工具链: gcc-arm-10.3-2021.07 (arm-none-linux-gnueabihf, glibc 2.33) # # 背景: OpenHarmony 使用 musl libc, 与 glibc 静态二进制不兼容 (NSS 问题) # 方案: 编译为动态链接, 打包 glibc 运行时 .so, 用自定义 ld-linux 启动

春风亭老朝1

国央企在开展内部创新项目时,如何有效进行技术成果的价值评估与资源筛选?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

电力系统风储联合一次调频仿真模型(Simulink仿真实现)

内容概要:本文详细介绍了一个基于Simulink平台构建的电力系统风储联合一次调频仿真模型,重点实现了风电与储能系统协同参与电网频率调节的动态过程。模型核心技术涵盖三电平ANPC并网逆变器控制、DPWMA调制策略、正负序分离与电网前馈控制,并引入虚拟同步发电机(VSG)控制以增强系统惯性与频率响应能力。仿真体系包含双闭环控制、中点电位平衡、虚拟阻抗、统一有源阻尼、孤岛检测等功能模块,支持在不平衡电网、弱电网等复杂工况下进行系统稳定性分析与先进控制策略验证,特别适用于低惯量电力系统中的一次调频研究与SCI级论文成果复现。; 适合人群:面向具备电力电子、电力系统自动化或新能源并网控制背景的研究生、科研人员及工程技术开发者;要求熟悉Matlab/Simulink仿真环境,有逆变器控制或微网运行研究经验者更佳。; 使用场景及目标:①开展风电与储能协同参与电网一次调频的控制策略研究;②验证VSG、下垂控制、模型预测控制(MPC)等先进控制方法在构网型逆变器中的动态性能;③复现高水平期刊论文中的电磁暂态仿真案例,支撑科研立项、论文撰写与工程项目开发。; 阅读建议:建议结合提供的参考文献与配套仿真资料,逐步搭建并调试各功能模块,重点关注控制环路设计、参数整定与阻抗建模方法,通过对比不同扰动工况下的仿真结果,深入理解系统动态响应特性与稳定性机理。

欢多天天写代码

美股分钟级别历史行情数据涵盖1分钟、5分钟、15分钟、30分钟及60分钟等不同周期 每条记录包含日期时间、开盘价、最高价、最低价、收盘价、成交量,部分数据还提供调整后的收盘价及成交笔数 所有数据按股票

美股分钟级别历史行情数据涵盖1分钟、5分钟、15分钟、30分钟及60分钟等不同周期。每条记录包含日期时间、开盘价、最高价、最低价、收盘价、成交量,部分数据还提供调整后的收盘价及成交笔数。所有数据按股票代码和日期组织,便于查看日内走势和交易活跃度。 数据源:CMES金融数据库

c_hn_007

科技中介服务机构如何利用数智工具提升技术需求挖掘效率?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 8
收藏 已收藏
分享
返回顶部
码旺
Web 开发 81,108 成员 341,721 内容