【问题标题】:Spring security does'nt work.Error is org.springframework.beans.factory.BeanCreationExceptionSpring 安全不起作用。错误是 org.springframework.beans.factory.BeanCreationException
【发布时间】:2016-04-16 21:40:35
【问题描述】:

这是我的安全 xml 文件。

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.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.2.xsd"> 
    <http auto-config="true">
            <intercept-url pattern="/user**" access="ROLE_USER" />  
            <intercept-url pattern="/admin**" access="ROLE_ADMIN" />  
        <form-login 
            always-use-default-target="true" 
            login-page="/login" 
            default-target-url="/welcome" 
            login-processing-url="/checkUser"
            authentication-failure-url="/login?error"
            username-parameter="username" 
            authentication-success-handler-ref="authenticationSuccessHandler"  
            password-parameter="password" />
        <logout logout-url="/login?logout" /> 
        <csrf/>
    </http> 
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user" password="123456" authorities="ROLE_USER" /> 
                <user name="admin" password="123456" authorities="ROLE_ADMIN" /> 
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

这是我的 CustomAuthenticationSuccessHandler 类,这个类从 AuthenticationSuccessHandler 接口实现。

CustomAuthenticationSuccessHandler

package com.mehman.puyment.security; 
import java.io.IOException; 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication) throws IOException, ServletException { 
        System.out.println("!***********************************************!");
    }
}

【问题讨论】:

  • 发布堆栈跟踪...

标签: java spring spring-mvc spring-security


【解决方案1】:

您应该在 spring-security.xml 中定义具有 id authenticationSuccessHandler 和类 CustomAuthenticationSuccessHandler 的 bean

【讨论】:

  • 我在 servlet-dispatcher.xml 文件中创建了 bean。
  • 对不起..你是对的。问题已解决。感谢您的帮助。
猜你喜欢
  • 2013-04-29
  • 2015-06-20
  • 2011-07-03
  • 1970-01-01
  • 1970-01-01
  • 2014-06-14
  • 2019-08-12
  • 2019-08-25
  • 2013-05-08
相关资源
最近更新 更多