【问题标题】:Spring Security not working after migrating from version 3 to 4从版本 3 迁移到 4 后 Spring Security 无法正常工作
【发布时间】:2017-02-01 02:09:15
【问题描述】:

最近我从 Spring Security 3 迁移到版本 4。以前一切正常,但现在没有任何作用。

这是我的spring-security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-4.0.xsd">

    <http auto-config="true" use-expressions="true"> 
        <intercept-url pattern="/home.MRCMPU" access="permitAll"/>
        <intercept-url pattern="/loginFailure.MRCMPU" access="permitAll"/>
        <intercept-url pattern="/*.MRCMPU"  access="permitAll"/>
        <intercept-url pattern="/con" access="permitAll"/>

        <form-login 
            login-page="/home.MRCMPU"
            login-processing-url="/login"  authentication-success-handler-ref="AuthenticationSuccess" 
            authentication-failure-handler-ref="AuthenticationFailure" username-parameter="username" password-parameter="password" />
        <logout logout-url="/logout.MRCMPU" success-handler-ref="Logout" invalidate-session="true" delete-cookies="true"/>
    </http>

    <authentication-manager>
        <authentication-provider user-service-ref="Authentication"/>
    </authentication-manager>
</beans:beans>

谁能从这段代码中找出冲突?

【问题讨论】:

  • 分享你得到的异常
  • 404 错误表单操作 url 不起作用
  • 启动服务器时会出现异常,如果配置不正确......正如我在回答中提到的那样

标签: java xml spring spring-mvc spring-security


【解决方案1】:

最后我自己清除了。 通过使用 xml 禁用 csrf

 <csrf disabled="true"/>

但是如何在不禁用 csrf 令牌的情况下做到这一点

【讨论】:

    【解决方案2】:

    您在这里缺少许多引用的 bean。

    1. user-service-ref="Authentication"
    2. success-handler-ref="Logout"
    3. authentication-success-handler-ref="AuthenticationSuccess"
    4. authentication-failure-handler-ref="AuthenticationFailure"

    对于上述参考,你应该有豆类,否则,像

    没有定义名为“注销”的 bean

    会抛出异常。

    添加类似的bean类

    <bean id="Authentication"
         class="class which you need to refer">
     </bean>
    

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多