补充贴一些代码
登录页面的js函数:
$(function() {
$("#login").click(function() {
$.ajax({
url : "${contextPath}/user/login",
type: "POST",
data:$('#loginForm').serialize(),
error: function(request) {
alert("Connection error");
},
dataType:"json",
success: function(data) {
if (data && data.ok) {
alert("登陆成功");
location.reload();
} else {
alert(data.msg);
}
}
});
return false;
});
});
shiro.ini的配置
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
nutzdao_realm = com.chiefdom.authority.shiro.realm.NutDaoRealm
nutzdao_realm.credentialsMatcher = $sha256Matcher
authc = com.chiefdom.authority.shiro.CaptchaFormAuthenticationFilter
authc.loginUrl = /user/login
logout.redirectUrl= /user/login
[urls]
/rs/* = anon
/user/logout = logout
/user/error = anon
/user/** = authc
第一次登录成功时的日志:
2016-05-13 07:54:40,151 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/user/login : UserModule.loginPage(UserModule.java:64)
2016-05-13 07:54:40,153 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'userModule'<class com.chiefdom.authority.action.UserModule>
2016-05-13 07:54:40,153 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:173) DEBUG - >> Load definition name=userModule
2016-05-13 07:54:40,154 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:149) DEBUG - Found IocObject(userModule) in IocLoader(AnnotationIocLoader@1502057819)
2016-05-13 07:54:40,154 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:203) DEBUG - >> Make...'userModule'<class com.chiefdom.authority.action.UserModule>
2016-05-13 07:54:40,157 org.nutz.aop.asm.AsmClassAgent.(AsmClassAgent.java:29) DEBUG - AsmClassAgent will define class in Version 50
2016-05-13 07:54:40,166 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'userModule' to [app]
2016-05-13 07:54:40,168 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'userService'<class com.chiefdom.authority.service.UserService>
2016-05-13 07:54:40,168 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:173) DEBUG - >> Load definition name=userService
2016-05-13 07:54:40,168 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:149) DEBUG - Found IocObject(userService) in IocLoader(AnnotationIocLoader@1502057819)
2016-05-13 07:54:40,169 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:203) DEBUG - >> Make...'userService'<class com.chiefdom.authority.service.UserService>
2016-05-13 07:54:40,169 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:84) DEBUG - Load class com.chiefdom.authority.service.UserService without AOP
2016-05-13 07:54:40,169 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'userService' to [app]
2016-05-13 07:54:40,170 org.nutz.service.EntityService.(EntityService.java:36) DEBUG - Get TypeParams for self : com.chiefdom.authority.vo.UserVO
2016-05-13 07:54:40,170 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'dao'<>
2016-05-13 07:54:40,170 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2016-05-13 07:54:40,492 com.chiefdom.system.LogTimeProcessor.process(LogTimeProcessor.java:33) DEBUG - [ GET]URI=/easyTransfer/user/login 339ms
2016-05-13 07:54:40,583 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/captcha/next : CaptchaModule.next(CaptchaModule.java:29)
2016-05-13 07:54:40,584 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'captchaModule'<class com.chiefdom.authority.action.CaptchaModule>
2016-05-13 07:54:40,584 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:173) DEBUG - >> Load definition name=captchaModule
2016-05-13 07:54:40,584 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:149) DEBUG - Found IocObject(captchaModule) in IocLoader(AnnotationIocLoader@1502057819)
2016-05-13 07:54:40,584 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:203) DEBUG - >> Make...'captchaModule'<class com.chiefdom.authority.action.CaptchaModule>
2016-05-13 07:54:40,585 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:84) DEBUG - Load class com.chiefdom.authority.action.CaptchaModule without AOP
2016-05-13 07:54:40,585 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'captchaModule' to [app]
2016-05-13 07:54:41,488 com.chiefdom.system.LogTimeProcessor.process(LogTimeProcessor.java:33) DEBUG - [ GET]URI=/easyTransfer/captcha/next 904ms
2016-05-13 07:54:47,581 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2016-05-13 07:54:47,604 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:211) DEBUG - SELECT * FROM cd_auth_user WHERE loginAcount=? LIMIT 0, 1
| 1 |
|-------|
| admin |
For example:> "SELECT * FROM cd_auth_user WHERE loginAcount='admin' LIMIT 0, 1 "
2016-05-13 07:54:47,618 org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:569) DEBUG - Looked up AuthenticationInfo [admin] from doGetAuthenticationInfo
2016-05-13 07:54:47,618 org.apache.shiro.realm.AuthenticatingRealm.cacheAuthenticationInfoIfPossible(AuthenticatingRealm.java:507) DEBUG - AuthenticationInfo caching is disabled for info [admin]. Submitted token: [com.chiefdom.authority.shiro.CaptchaUsernamePasswordToken - admin, rememberMe=false (0:0:0:0:0:0:0:1)].
2016-05-13 07:54:47,620 org.apache.shiro.authc.credential.SimpleCredentialsMatcher.equals(SimpleCredentialsMatcher.java:95) DEBUG - Performing credentials equality check for tokenCredentials of type [org.apache.shiro.crypto.hash.SimpleHash and accountCredentials of type [org.apache.shiro.crypto.hash.SimpleHash]
2016-05-13 07:54:47,621 org.apache.shiro.authc.credential.SimpleCredentialsMatcher.equals(SimpleCredentialsMatcher.java:101) DEBUG - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison
2016-05-13 07:54:47,621 org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:231) DEBUG - Authentication successful for token [com.chiefdom.authority.shiro.CaptchaUsernamePasswordToken - admin, rememberMe=false (0:0:0:0:0:0:0:1)]. Returned account [admin]
2016-05-13 07:54:47,621 org.apache.shiro.subject.support.DefaultSubjectContext.resolveSecurityManager(DefaultSubjectContext.java:102) DEBUG - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup.
2016-05-13 07:54:47,621 org.apache.shiro.mgt.DefaultSecurityManager.resolveSession(DefaultSecurityManager.java:436) DEBUG - Context already contains a session. Returning.
2016-05-13 07:54:47,622 org.apache.shiro.subject.support.DefaultSubjectContext.resolveSecurityManager(DefaultSubjectContext.java:102) DEBUG - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup.
2016-05-13 07:54:47,622 org.apache.shiro.web.servlet.SimpleCookie.addCookieHeader(SimpleCookie.java:226) DEBUG - Added HttpServletResponse Cookie [rememberMe=deleteMe; Path=/easyTransfer; Max-Age=0; Expires=Wed, 11-May-2016 23:54:47 GMT]
2016-05-13 07:54:47,622 org.apache.shiro.mgt.AbstractRememberMeManager.onSuccessfulLogin(AbstractRememberMeManager.java:300) DEBUG - AuthenticationToken did not indicate RememberMe is requested. RememberMe functionality will not be executed for corresponding account.
这时候被跳回到登录页面,尝试过执行 location.reload()和window.location.url重定向到其他页面都无法正常进入。
2016-05-13 07:57:20,840 org.nutz.mvc.impl.ActionInvoker.getActionChain(ActionInvoker.java:84) DEBUG - Path=[/user/login] available methods[GET] but request [POST], using the wrong http method?
2016-05-13 07:57:20,840 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Search mapping for path=/user/login : NOT Action match
```
求大神帮忙分析一下问题所在