当我项目启动后,去访问登录页面就会直接报这个错误,登录成功或者失败也会报同样的错误。并且登录的页面也炸掉了,jquery失效了,报 $ is not defined的错误
拜托大神帮忙看看是什么原因,很急很急,拜托
报错信息:
org.apache.shiro.authc.UnknownAccountException: Realm [com.rn.Filter.UserRealm@55c2fb78] was unable to find account data for the submitted AuthenticationToken [org.apache.shiro.authc.UsernamePasswordToken - null, rememberMe=false].
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:184)
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
at com.rn.service.impl.UserServiceImpl.doLogin(UserServiceImpl.java:57)
at com.rn.service.impl.UserServiceImpl$$FastClassBySpringCGLIB$$30adad5a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at com.rn.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$90515f43.doLogin(<generated>)
at com.rn.controller.ManagerController.loginback(ManagerController.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:745)
UserRealm.java
public class UserRealm extends AuthorizingRealm {
@Autowired
private UserService userSer;
/**
* 每次验证权限执行
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principal) {
System.out.println("权限验证");
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
User user = (User) session.getAttribute(Constants.SESSION_USER);
List<String> roleIds = userSer.getUserRoleIds(user.getUser_Code());
if (roleIds != null && roleIds.size() > 0) {
SimpleAuthorizationInfo info= new SimpleAuthorizationInfo();
for (String roleId : roleIds) {
info.addRole(roleId);
}
return info;
}
return null;
}
/**
* 每次登陆验证
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
AuthenticationToken authenticationToken)
throws AuthenticationException {
String user_Name = (String) authenticationToken.getPrincipal();
User user = userSer.getpassword(user_Name);
if (user != null) {
return new SimpleAuthenticationInfo(user_Name, user.getPassword(),
null, getName());
}
return null;
}
}
UserServiceImpl.java
@Override
public User doLogin(String user_Name, String password) {
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(user_Name,
password);
try {
subject.login(token);
Session session=subject.getSession();
User user=getpassword(user_Name);
session.setAttribute(Constants.SESSION_USER,user);
return user;
} catch (AuthenticationException e) {
e.printStackTrace();
return null;
}
}
Controller
@RequestMapping("login")
public String loginback(
@RequestParam(value = "user_Name", required = false) String user_Name,
@RequestParam(value = "password", required = false) String password,
HttpServletRequest request) {
User user = userService.doLogin(user_Name, password);
if (user == null) {
request.setAttribute("error", "用户名或密码错误");
return "back/login";
}
return "back/index";
}
按理说就是有错误不是也应该点击登录才报这样的错吗,为什么页面一加载就报错。
我第一次使用shiro,拜托大神帮忙看看,拜托
<p>doGetAuthorizationInfo()</p>
的逻辑有点问题?用户角色没有的时候返回null,也许是这个问题造成的(建议不要返回null, 没有角色授权的用户可以正常登录没有问题)。
您好,一开始我的<property name="loginUrl" value="/test/login"></property>登录的路径写错了,修改后进不去controller了,麻烦您看下楼下的回复,请问是什么问题呢,断点都进不去...
回复 <a class="referer" target="_blank">@求知a</a> : 应当返回 SimpleAuthorizationInfo 的实例(instance)
您好,那应该返回什么呢?
<pre>SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//将角色加入AuthorizationInfo认证对象 info.setRoles(user.getRoles()); //权限加入AuthorizationInfo认证对象 info.setStringPermissions(user.getMenus()); return info;
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user,password,getName()); return info;
应该是始终返回SimpleAuthorizationInfo和SimpleAuthenticationInfo吧?最近也在学习shiro
不是太懂,您看我这个该怎么改
<p>一开始我的<property name="loginUrl" value="/test/login"></property>登录的路径写错了,写成了controller的地址,所以他在页面一加载就执行了登录的方法,修改成登录页面后,发现会连续访问5次这个页面。而且登录也登录不了了,进不去controller了。请问这是怎么回事</p>
<p>一楼那个大哥已经说了的,感觉按照他的思路没有问题。我的demo是这样写的。你可以参考下。</p>
/** * 授权 * * @param principalCollection * @return */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { SysUser user = new SysUser(); BeanUtil.copyProperties(SecurityUtils.getSubject().getPrincipal(), user); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); //将角色加入AuthorizationInfo认证对象 info.setRoles(user.getRoles()); //权限加入AuthorizationInfo认证对象 info.setStringPermissions(user.getMenus()); return info; } /** * 登录认证 * * @param authenticationToken * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken){ UserInfoToken userInfoToken = (UserInfoToken) authenticationToken; String mobile = userInfoToken.getMobile(); String password = String.valueOf(userInfoToken.getPassword()); SysUser user = null; try { user = userService.login(mobile,password); user.setRoles(roleMapper.selectUserRoles(user.getId())); user.setMenus(menuMapper.selectUserMenus(user.getId())); }catch (AuthenticationException e){ throw new AuthenticationException(e.getMessage(), e); }catch (Exception e){ throw new RuntimeException("服务器内部错误"); } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user,password,getName()); return info; }
回复 <a class="referer" target="_blank">@白菜粉条炖猪蹄儿</a> : 麻烦您看下楼下
一开始我的<property name="loginUrl" value="/test/login"></property>登录的路径写错了,写成了controller的地址,所以他在页面一加载就执行了登录的方法,修改成登录页面后登录不了了,根本进不去进不去controller了。请问这是怎么回事
不要在意我把权限直接放到user里面这个。。。
<pre><code> <bean id="shiroFilter" class="com.rn.Filter.MyShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"></property>
<property name="loginUrl" value="/test/login"></property>
<property name="successUrl" value="/test/index"></property>
<property name="unauthorizedUrl" value="/test/error"></property>
<property name="filterChainDefinitions">
<value>
/test/login=anon
/manager/login=anon
/test/index=authc
<!-- /test/*=authc -->
</value>
</property>
<property name="filters">
<map>
<entry key="roles">
<bean class="com.rn.Filter.MyShiroFilter"/>
</entry>
</map>
</property>
</bean>
</code></pre>
这是我现在修改后的,/test/login是登录页面的路径,/test/index是首页的路径,/manager/login是controller里登录方法的路径。
麻烦您帮我看一下有问题吗
<pre><bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 装配 securityManager -->
<property name="securityManager" ref="securityManager"/>
<!-- 配置登陆页面 -->
<property name="loginUrl" value="/login"/>
<!-- 登陆成功后的页面 -->
<property name="successUrl" value="/main"/>
<!-- 用户访问未授权的资源时显示的链接 -->
<property name="unauthorizedUrl" value="/unauth"/>
<!-- 具体配置需要拦截哪些 URL, 以及访问对应的 URL 时使用 Shiro 的什么 Filter 进行拦截 . 这里不配置拦截方式,所有的拦截方式通过代码来控制 -->
<property name="filterChainDefinitions">
<value>
/** = anon
</value>
</property>
</bean>
没有很大的区别。。。。
快哭了,现在进不去登录的controller了,找不到问题所在。您方便加个QQ吗,帮我看一下
<p>可以先把 filterChainDefinitions里面所有的权限放开,然后再方法上注解了去试试。<img height="109" src="https://oscimg.oschina.net/oscnet/73181f72582d24c592fbad78c1baf9cf9c6.jpg" width="134"></p>
回复 <a class="referer" target="_blank">@求知a</a> : 断点打在Realm的doGetAuthorizationInfo和doGetAuthenticationInfo里面试试
回复 <a class="referer" target="_blank">@白菜粉条炖猪蹄儿</a> : 进不去controller,根本就进不去断点。我的QQ是3357270861,您方便加一下帮我看看吗
断点打着跟着走一圈就知道哪里有问题了。。。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。