【问题标题】:Do I need some special setting to use "Automatic Session Alias Inclusion"?我是否需要一些特殊设置才能使用“自动会话别名包含”?
【发布时间】:2016-02-25 10:46:30
【问题描述】:

目前我正在尝试制作使用 Spring 会话的简单应用程序(在 Spring Boot 上使用 Spring Security)

它几乎可以正常工作。 但我被困在某一点上

春季会议指南说 "Spring Session will automatically include the session alias in any URL"

但在我的 jsp 中,它不起作用。

所以我必须手动编写包括别名代码

<c:url value="/index" var="indexUrl" >
    <c:if test="${param._s != null }">
        <c:param name="_s" value="${param._s}" />
    </c:if> 
</c:url>
<a id="indexLink" href="${indexUrl}">To Index</a>

在我的 IDE(spring 工具套件)中,multi users sample code 与指南一样工作良好,我在我的应用程序中使用相同版本的 jstl

嗯......也许我必须写更多关于我的问题的信息

抱歉,我猜不出哪个组件会影响这个问题 可能是 spring session 或 boot 功能的一部分

谁能告诉我哪个组件阻止了“自动会话别名包含”或需要一些设置才能使用?

【问题讨论】:

    标签: spring-security spring-boot spring-session


    【解决方案1】:

    这是 Spring Security 和 Spring Session 之间的冲突。 Spring Security 正在防止 URL 被编码以防止 JSESSIONID 意外暴露。要允许编码,您可以使用:

    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .sessionManagement()
                    .enableSessionUrlRewriting(true)
                    .and()
                // ...
        }
    }
    

    【讨论】:

    • 在我添加“enableSessionUrlRewriting(true)”之后它起作用了!我真的很感激你回答了我这么模糊的问题!
    猜你喜欢
    • 2014-07-05
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多