求助,shiro报错org.apache.shiro.UnavailableSecurityManagerException,帮忙看一下
<?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)
但是对项目运行无影响,我调试了半天也没弄好,大神们帮忙看看是哪里出问题了,在线等
相关推荐
MATLABSimulink模拟及会议论文,关于具备自动温度控制和能耗分析的智能太阳能热水系统。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
完美复现基于自适应虚拟谐波阬的光储VSG并网电流谐波抑制模型(Simulink仿真实现)
内容概要:本文围绕基于自适应虚拟谐波阬的光储VSG并网电流谐波抑制模型展开研究,提出了一种结合虚拟同步发电机(VSG)控制与自适应虚拟谐波阬技术的谐波治理方案,旨在有效应对光伏发电与储能系统并网过程中产生的特定次谐波问题。通过在Simulink中构建完整的系统仿真模型,详细实现了VSG的惯量阻尼控制、功率环调控以及自适应谐波阬的频率识别与阻抗重塑机制,能够动态跟踪并抑制并网电流中的谐波成分,从而提升电能质量和系统并网稳定性。文章深入剖析了控制器结构设计、关键参数整定方法及谐波抑制效果的仿真验证过程,充分验证了该方法在复杂工况下的有效性、鲁棒性与工程应用潜力。; 适合人群:具备电力电子、新能源并网、电力系统分析等相关专业知识背景的科研人员与工程技术人员,尤其适用于熟悉Simulink仿真环境、掌握基本控制理论与信号处理技术的研究生、高校教师及企业研发人员。; 使用场景及目标:①应用于光伏-储能联合系统的并网逆变器控制设计;②用于提升VSG并网系统的电能质量与抗扰动能力;③为高比例新能源接入场景下的谐波分析与主动抑制策略提供仿真验证平台与技术支撑;④辅助开展新型电力系统中电能质量治理相关的教学与科研工作。; 阅读建议:建议读者结合提供的Simulink模型文件进行同步仿真操作,重点理解VSG控制架构与自适应虚拟谐波阬模块的耦合关系,关注谐波检测、频率自适应调整与复矢量控制的实现细节,并可通过改变负载条件或电网阻抗参数进行多工况测试,以深入掌握系统的动态响应特性与控制性能边界。
机械三维3D设计图-食品皮带机输送除尘消毒设备.zip
机械三维3D设计图-食品皮带机输送除尘消毒设备.zip
机械三维3D设计图-膜厚测定自动搬送设备.zip
机械三维3D设计图-膜厚测定自动搬送设备.zip
负荷预测基于LSTM-Attention、蜣螂优化DBO-LSTM-Attention的负荷预测研究(Python代码实现)
内容概要:本文围绕基于LSTM-Attention与蜣螂优化算法(DBO)改进的LSTM-Attention模型在电力负荷预测中的应用展开研究,采用Python代码实现。研究结合长短期记忆网络(LSTM)对时间序列长期依赖关系的建模能力与注意力机制(Attention)对关键时间步特征的加权聚焦能力,构建基础预测模型,并引入新型群智能优化算法——蜣螂优化算法(DBO),用于自动寻优模型超参数,有效提升模型收敛速度与预测精度。文中详述了模型架构设计、优化流程集成及实验验证过程,通过对比实验证明该混合模型在负荷预测任务中相较传统方法具有更强的非线性拟合能力和更高的预测准确性。; 适合人群:具备一定Python编程基础和机器学习背景,从事电力系统分析、能源管理或相关领域研究的科研人员及工程技术人员。; 使用场景及目标:①应用于短期或中期电力负荷预测任务,提高电网调度的科学性与经济性;②为深度学习与智能优化算法在能源领域的融合应用提供实践案例,促进模型性能优化与实际部署。; 阅读建议:建议读者结合提供的Python代码,深入理解LSTM-Attention模型的构建细节与DBO优化流程,建议在实际数据集上复现实验,进一步掌握参数调优技巧与模型评估方法。


Web 开发
