2
回答
Apache Shiro不能RememberMe
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   

我shiro和spring集成,在浏览器也看不到有RememberMe cookie

配置是

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
        <property name="arguments" ref="securityManager"/>
    </bean>


    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
<property name="filterChainDefinitions">
            <value>
                /admin/**/*=user
                /*=anon
            </value>
        </property>
    </bean>

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

    <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
        <constructor-arg value="rememberMe"/>
        <property name="httpOnly" value="true"/>
        <property name="maxAge" value="31536000"/>
    </bean>

    <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
        <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode('4AvVhmFLUs0KTA3Kprsdag==')}"/>
        <property name="cookie" ref="rememberMeCookie"/>
    </bean>



@Action("onlogin")
    public void onLogin() {
        UsernamePasswordToken token = new UsernamePasswordToken(name, password);
        token.setRememberMe(true);
        try {
            SecurityUtils.getSubject().login(token);
            ServletUtils.printJSON(true);
        }catch (UnknownAccountException | IncorrectCredentialsException e){
            e.printStackTrace();
            ServletUtils.printJSON(false);
        }
    }



举报
NestleCaau
发帖于4年前 2回/499阅
顶部