【问题标题】:Spring-Security migration from 2.0.4 to 4.2.0Spring-Security 从 2.0.4 迁移到 4.2.0
【发布时间】:2017-04-18 16:58:42
【问题描述】:

我有一个运行 spring-security 版本 2.0.4 的应用程序,现在我需要将其更改为版本 4.2.0...

我使用此示例创建登录页面:

http://facestutorials.icefaces.org/tutorial/spring-security-basic.html

springSecurityLogin.jspx

<?xml version="1.0" encoding="ISO-8859-1" ?>
<f:view xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ice="http://www.icesoft.com/icefaces/component">
    <ice:outputDeclaration doctypeRoot="HTML"
                           doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
                           doctypeSystem="http://www.w3.org/TR/html4/loose.dtd"/>
    <html>
    <head>
        <title>Spring Security Login</title>
    </head>
    <body>
    <ice:form partialSubmit="false">
        <ice:panelGrid columns="2">
            <ice:outputLabel value="User Name" for="j_username"/>
            <ice:inputText id="j_username"
                           value="#{loginBean.userId}" size="40"
                           maxlength="80"/>
            <ice:outputLabel value="Password" for="j_password"/>
            <ice:inputSecret id="j_password"
                             value="#{loginBean.password}" size="40"
                             maxlength="80"/>
        </ice:panelGrid>
        <ice:commandButton actionListener="#{loginBean.login}" value="Login"/>
        <ice:messages style="color: red;"/>
    </ice:form>
    </body>
    </html>
</f:view>

我的登录方法:

public void login(ActionEvent e) throws java.io.IOException {
    FacesContext.getCurrentInstance().getExternalContext().redirect("/spring-authentication/j_spring_security_check?j_username=" + userId + "&j_password=" + password);
}

这是有效的...但是当我将 spring 安全版本更改为 4.2.0 尝试登录时出现 http 错误 404。

有人知道发生了什么吗?

【问题讨论】:

  • 那里有迁移指南。
  • 迁移指南不适用于 icefaces...
  • 你这是什么意思?

标签: java spring spring-security icefaces-1.8


【解决方案1】:

问题如下...

spring-security 允许使用 GET 或 POST 进行身份验证 http 调用,迁移后默认只允许 POST 调用。

要解决它,只需在您的 AuthenticationFilter 上插入以下行:

UsernamePasswordAuthenticationFilter.setPostOnly(false);

这样就解决了问题。

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 2012-11-14
    • 2017-05-30
    • 2013-10-21
    • 1970-01-01
    • 2019-01-14
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多