【问题标题】:Spring Security - showing logout messageSpring Security - 显示注销消息
【发布时间】:2016-03-10 23:24:55
【问题描述】:

基于Spring security java的配置是(不是spring mvc,只是servlet webapp)

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login.jsp")
                .permitAll();
    }

登录页面是

<form name='loginForm' action="" method='POST'>

            <c:if test="${param.logout != null}">
                <p>You have been logged out.</p>
            </c:if>

            <table>
                <tr>
                    <td>User:</td>
                    <td><input type='text' name='username'></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><input type='password' name='password' /></td>
                </tr>
                <tr>
                    <td colspan='2'><input name="submit" type="submit"
                        value="submit" /></td>
                </tr>
            </table>

            <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />

        </form>

还有其他页面有注销链接,所以注销操作是logout(第2页)

<form action="logout" method="post">
      <input type="submit" value="Logout" />
      <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
    </form>

在我成功登录然后按下注销按钮(从第 2 页开始)后,它返回到登录页面,但登录页面没有显示注销消息 &lt;c:if test="${param.logout != null}"&gt;。之后我尝试再次登录但它没有工作(它只是在注销后登录)并向我显示了一条注销消息。为什么它会这样工作以及如何修复它以在按下注销后立即显示注销消息。

【问题讨论】:

标签: spring spring-security


【解决方案1】:

希望它会有所帮助。

Java 配置

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().anyRequest().authenticated().and()
    .formLogin()
    .loginPage("/loginPage")
    .loginProcessingUrl("/authenticateUser")
    .permitAll()
    .and()
    .logout()
    .permitAll();
}

在退出页面

    <form:form action="${pageContext.request.contextPath}/logout" 
                               method="POST" >                     
        <input type="submit" value="logout">                                       
   </form:form>

【讨论】:

    【解决方案2】:

    尝试配置注销

    http
            .logout()                                                                
                .logoutUrl("/logout")                                                 
                .logoutSuccessUrl("/login")  
    

    【讨论】:

      猜你喜欢
      • 2011-06-08
      • 2016-07-14
      • 1970-01-01
      • 2014-01-01
      • 2020-04-02
      • 2014-09-17
      • 2017-04-22
      • 2012-10-09
      • 2018-09-02
      相关资源
      最近更新 更多