我的 Spring XML Beans 配置文件有什么问题?

What's wrong with my Spring XML Beans config file?

security.xml 我收到以下错误:

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
     xmlns:sec="http://www.springframework.org/schema/security"
     xsi:schemaLocation=" 
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
            http://www.springframework.org./schema/security
            http://www.springframework.org./schema/security/spring-security-4.1.xsd
            http://www.springframework.org/schema/security/oauth2
            http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-4.0.xsd 
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

    <!-- Definition of authentication service -->
    <http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager"
          xmlns="http://www.springframework.org/schema/security">
          <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY"/>
          <anonymous enabled="false"/>
          <http-basic entry-point-ref="clientAuthenticationEntryPoint"/>
          <!--  Include this only if you need to authenticate clients via request parameters-->
          <custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIX_AUTH_FILTER"/>
          <access-denied-handler ref="oauthAccessDeniedHandler"/>      
    </http>

    <!--  Protected resources-->
    <http pattern="/country/**"
          create-session="never"
          entry-point-ref="oauthAuthenticationEntryPoint"
          access-decision-manager-ref="accessDecisionManager"
          xmlns="http://www.springframework.org/schema/security">
         <anonymous enabled="false"/>
         <intercept-url pattern="/country/**" access="ROLE_USER"/>
         <custom-filter ref="resourceServerFilter"
                        before="PRE_AUTH_FILTER"/>
         <access-denied-handler 
                    ref="oauthAccessDeniedHandler"/> 
    </http>

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

    <bean id="clienthAuthenticationEntryPoint"
            class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
            <property name="realmName" value="dstest/client"/>
            <property name="typeName" value="Basic"/>
    </bean>

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

    <bean id="clientCredentialsTokenEndpointFilter"
            class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
          <property name="authenticationManager" ref="clientAuthenticationManager"/>
    </bean>

    <bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
          xmlns="http://www.springframework.org/schema/beans">
        <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>

    <!--  Authentication in config file -->
    <authentication-manager id="clientAuthenticationManager"
                            xmlns="http://www.springframework.org/schema/security">
          <authentication-provider user-service-ref="clientDetailsUserService"/>                    
    </authentication-manager>

    <authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security">
       <authentication-provider>
            <user-service id="userDetailsService">
               <user name="admin" password="password" authorities="ROLE_USER"/> 
            </user-service>
       </authentication-provider>
    </authentication-manager>

    <bean id="clientDetailsUserService"
            class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
            <constructor-arg ref="clientDetails"/>
    </bean>        

    <!--  Token Store -->
    <bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore"/>

    <bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
          <property name="tokenStore" ref="tokenStore"/>
          <property name="supportRefreshToken" value="true"/>
          <property name="clientDetailsService" ref="clientDetails"/>
          <!--  VIV -->
          <property name="accessTokenValiditySeconds" value="10"/>
    </bean>

    <bean id="userApprovalHandler"
            class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
        <property name="tokenService" ref="tokenServices"/>
    </bean>

    <!--  Token Management -->
    <oauth:authrization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices"
                                        user-approval-handler-ref="userApprovalHandler">
            <oauth:authrization-code/>
            <oauth:implicit/>
            <oauth:refresh-token/>
            <oauth:client-credentials/>
            <oauth:password/>                                   
    </oauth:authrization-server>

    <!--  Client Definition -->
    <oauth:client-details-service id="clientDetails">

            <oauth:client client-id="my-trusted-client"
            authorized-grant-types="password,authorization_code,refresh_token,implicit,redirect"
            authorities="ROLE_CLIENT, ROLE_TRUSTED_CLIENT"
            redirect-uri="/web"
            scope="read,write,trust"
            access-token-validity="60"
            refresh-token-validity="600"/>
    </oauth:client-details-service>

    <sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
            <sec:expression-handler ref="oauthExpressionHandler"/>
    </sec:global-method-security>

    <oauth:expression-handler id="oauthExpressionHandler"/>
    <oauth:web-expression-handler id="oauthWebExpressionHandler"/>

    </beans>

我收到以下错误:

cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'authentication-manager'.

cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'http'.

cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'oauth:authrization-server'.

cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'sec:global-method-security'.

我已经引用了几个链接我已经添加了所有需要的依赖项我仍然无法弄清楚这些错误是什么。这是我第一次从事 spring-security

XSD 验证会提供信息性错误,但你必须注意拼写错误,尤其是在名称空间声明中,否则右下属 XSD 甚至无法读取。

要获得有效文档,您有四个问题需要解决:

  1. 改变

        http://www.springframework.org./schema/security
        http://www.springframework.org./schema/security/spring-security-4.1.xsd
    

        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-4.1.xsd
    
  2. oauth:authrization-server更改为oauth:authorization-server

  3. oauth:authrization-code更改为oauth:authrization-code

  4. BASIX_AUTH_FILTER改为BASIC_AUTH_FILTER