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

问题描述 投票:-1回答:1

我正在尝试为我的应用程序设置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时出错:在使用key [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'(内部bean)#5ee62c84' .security.web.servletapi.SecurityContextHolderAwareRequestFilter]用key [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上部署它,但一直得到同样的错误

spring spring-security spring-security-oauth2
1个回答
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>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.