配置Spring-security.xml会引发错误

时间:2019-04-29 09:59:49

标签: spring spring-security spring-security-oauth2

我正在尝试为我的应用程序设置spring-security。但是当我尝试使用oauth对其进行配置时会抛出错误

这是我的spring security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:sec="http://www.springframework.org/schema/security"
   xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
   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.xsd
    http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd">

<sec:http create-session="never" entry-point-ref="oauthAuthenticationEntryPoint">

    <sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <sec:intercept-url pattern="/phone-number-verification/token" access="ROLE_USER" />
    <sec:intercept-url pattern="/phone-number-verification/verify-token" access="ROLE_USER" />

    <sec:anonymous enabled="true"/>
    <sec:access-denied-handler ref="oauthAccessDeniedHandler" />
</sec:http>

<bean id="oauthAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
    <property name="realmName" value="blibli-api/user" />
</bean>

<bean id="clientAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
    <property name="realmName" value="blibli-api/client" />
    <property name="typeName" value="Basic" />
</bean>

<bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased">
    <constructor-arg>
        <list>
            <bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
            <bean class="org.springframework.security.access.vote.RoleVoter" />
            <bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
        </list>
    </constructor-arg>
</bean>
</beans>

我得到的错误是

创建名称为'org.springframework.security.filterChains'的bean时出错:在使用键[0]设置bean属性'sourceList'时无法解析对bean'org.springframework.security.web.DefaultSecurityFilterChain#0'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为org.springframework.security.web.DefaultSecurityFilterChain#0的bean时出错:无法创建类型为[org.springframework的内部bean'(inner bean)#5ee62c84' .security.web.servletapi.SecurityContextHolderAwareRequestFilter],同时使用键[5]设置构造函数参数时;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“((内部bean)#5ee62c84”的bean时出错:设置bean属性“'时无法解析对bean'org.springframework.security.authentication.ProviderManager#0'的引用) authenticationManager';嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为org.springframework.security.authentication.ProviderManager#0的bean时出错:无法解析对bean org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#的引用设置构造函数参数时为0';嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0的bean时出错:FactoryBean在对象创建时抛出了异常;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为org.springframework.security.authenticationManager的bean:您是否忘记在配置中添加gobal元素(带有子元素)?另外,您可以在和元素上使用authentication-manager-ref属性。

我尝试添加用于身份验证管理器的标签,但这没用。

我想将其部署在tomcat上,但始终出现相同的错误

1 个答案:

答案 0 :(得分:0)

  

没有名为'org.springframework.security.authenticationManager'的bean是   定义:您是否忘记向配置中添加gobal元素   (带有子元素)?或者,您可以使用   和元素上的authentication-manager-ref属性。

这是日志必须说的。您需要添加身份验证管理器配置。

<sec:authentication-manager id="authenticationManager">
    <sec:authentication-provider user-service-ref="userDetailsService"/>
</sec:authentication-manager>