NutzCN Logo
问答 nutzwk未拦截的请求地址cookie无法得到
发布于 2293天前 作者 qq_64f81159 1481 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

RT,写了一个方法在shiro.ini中配置了拦截的方法能设置cookie和得到设置的cookie,而在未被拦截的方法中,除了JESSIONID和rememberMe这两个cookie外其他设置的人任何cookie都没办法得到

shiro.ini配置如下

[main]

jedisAgent = org.nutz.integration.jedis.JedisAgent
cacheManager_ehcache = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager_ehcache.cacheManagerConfigFile=classpath:ehcache.xml
cacheManager_redis = org.nutz.plugins.cache.impl.redis.RedisCacheManager
cacheManager_redis.mode=kv
cacheManager_redis.debug=true
cacheManager = org.nutz.plugins.cache.impl.lcache.LCacheManager
cacheManager.jedisAgent = $jedisAgent
cacheManager.level1 = $cacheManager_ehcache
cacheManager.level2 = $cacheManager_redis

# Session
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionValidationSchedulerEnabled = false

# Session Cache
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionDAO.cacheManager = $cacheManager
sessionDAO.activeSessionsCacheName = shiro-activeSessionCache
sessionManager.sessionDAO = $sessionDAO
securityManager.sessionManager = $sessionManager

# Cookie
sessionIdCookie = org.apache.shiro.web.servlet.SimpleCookie
sessionIdCookie.name = JSESSIONID
sessionIdCookie.maxAge = -1
sessionIdCookie.httpOnly = true
sessionManager.sessionIdCookie = $sessionIdCookie
sessionManager.sessionIdCookieEnabled = true
sessionManager.globalSessionTimeout = 25200000

rememberMeCookie = org.apache.shiro.web.servlet.SimpleCookie
rememberMeCookie.name = rememberMe
rememberMeCookie.maxAge = 604800
rememberMeCookie.httpOnly = true
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
rememberMeManager.cookie = $rememberMeCookie

sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
sha256Matcher.storedCredentialsHexEncoded = false
sha256Matcher.hashIterations = 1024
sha256Matcher.hashSalted = true

shiroDbRealm = com.kanq.shiro.realm.NutzDaoRealm
shiroDbRealm.credentialsMatcher = $sha256Matcher

securityManager.realms = $shiroDbRealm
authcStrategy = com.kanq.shiro.pam.AnySuccessfulStrategy
securityManager.authenticator.authenticationStrategy = $authcStrategy
securityManager.cacheManager = $cacheManager
securityManager.rememberMeManager = $rememberMeManager

[filters]
rememberAuthFilter = com.kanq.shiro.filter.RememberAuthenticationFilter
rememberAuthFilter.loginUrl = /platform/login
logout.redirectUrl = /platform/login

[urls]
/platform/login = anon
/platform/doLogin = anon
/platform/login/* = anon
/platform/sys/upload/* = anon
/platform/cms/statistics/* = anon
/statics/** = anon
/platform/** = rememberAuthFilter
/** = anon

4 回复

设置cookie没写对咯

是对的把 ,在拦截的方法中获取是正确的。

   @At
    public void aaa(HttpServletRequest req, HttpServletResponse resp){
    	resp.addCookie(new Cookie("aaa", "123"));
    }

    @At
    public String bbb(HttpServletRequest req, HttpServletResponse resp){
    	Cookie[] cookies = req.getCookies();
    	for(Cookie cookie: cookies){
    		System.out.println(cookie.getValue()+"--------"+cookie.getName());
    	}
    	return cookies.length+"";
    }

代码是这样的 bbb方法被拦截的了 cookie值是3 如果是在未拦截的方法中就是2 得不到aaa这个cookie

你的cookie没加路径没加有效期

嗯 是的 要设置路径。。不然路径不是application这一层

添加回复
请先登陆
回到顶部