Spring Bean应用程序上下文的XPath查询

时间:2015-07-09 06:54:42

标签: xml maven xpath

使用Xpath查询我想获得这两个元素

<security:http realm="Protected API" use-expressions="true" auto-config="false" create-session="always"
                       entry-point-ref="authenticationEntryPoint">
            <security:custom-filter ref="covAuthFilter" position="FORM_LOGIN_FILTER"/>

从这个春天的配置文件

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


<security:http pattern="/data/**" security="none"/>
<security:http pattern="/js/**" security="none"/>
<security:http pattern="/css/**" security="none"/>
<security:http pattern="/fonts/**" security="none"/>
<security:http pattern="/img/**" security="none"/>
<security:http pattern="/ckeditor/getImage**" security="none"/>

<beans profile="default">

    <!-- Windows login uses a different entry point -->
    <security:http use-expressions="true" pattern="/windows" auto-config="false"
                   entry-point-ref="negotiateSecurityFilterEntryPoint">
        <security:intercept-url pattern="/**" access="isAuthenticated()"/>
        <security:custom-filter ref="waffleNegotiateSecurityFilter" position="FORM_LOGIN_FILTER"/>
    </security:http>

    <security:http realm="Protected API" use-expressions="true" auto-config="false" create-session="always"
                   entry-point-ref="authenticationEntryPoint">
        <security:custom-filter ref="bAuthFilter" position="FORM_LOGIN_FILTER"/>
        <!--<security:custom-filter ref="csrfFilter" after="CSRF_FILTER"/>-->
        <!--<security:intercept-url pattern="/**" access="permitAll"/>-->
        <!-- Temporarily disable authentication until JSESSIONID/token management strategy can be determined -->

        <!-- public access -->
        <!-- apis -->
        <security:intercept-url pattern="/api/login**" access="permitAll"/>
        <security:intercept-url pattern="/api/appsettings/loginWarning" access="permitAll"/>
        <security:intercept-url pattern="/api/loginwarning/agree" access="permitAll"/>
        <security:intercept-url pattern="/api/about**" access="permitAll"/>

        <security:access-denied-handler error-page="/login/"/>
        <security:logout
                logout-url="/api/logout" success-handler-ref="logoutSuccessHandler"
                />
        <security:custom-filter ref="x509AuthenticationFilter" position="X509_FILTER"/>

        <!--<security:csrf token-repository-ref="csrfTokenRepository"/>-->
    </security:http>


    <!-- Configure Waffle entry point -->
    <beans:bean id="negotiateSecurityFilterEntryPoint" class="waffle.spring.NegotiateSecurityFilterEntryPoint">
        <beans:property name="provider" ref="waffleSecurityFilterProviderCollection"/>
    </beans:bean>

    <bean id="authenticationEntryPoint"
          class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <constructor-arg name="loginFormUrl" value="/login/"/>
    </bean>


    <bean id="logoutSuccessHandler" class="bherto.testsecurity.LogoutSuccessHandler">
    </bean>

    <security:authentication-manager erase-credentials="true" alias="authenticationManager">
        <security:authentication-provider ref="daoAuthenticationProvider"/>
        <security:authentication-provider ref="preAuthProvider"/>
    </security:authentication-manager>

    <!-- Class responsible for retrieving user from submitted user name -->
    <beans:bean id="abstractUserDetailsService" class="bherto.security.auth.AbstractUserDetailsService"
                abstract="true"/>
    <beans:bean id="usernameUserDetailsService" class="bherto.testsecurity.UserDetailsServiceImpl"
                parent="abstractUserDetailsService">
        <beans:property name="accountLookupService" ref="bherto.non.lookupByLoginId"/>
    </beans:bean>
    <beans:bean id="dnUserDetailsService" class="bherto.testsecurity.UserDetailsServiceImpl"
                parent="abstractUserDetailsService">
        <beans:property name="accountLookupService" ref="bherto.non.lookupByDNService"/>
    </beans:bean>

    <bean id="daoAuthenticationProvider"
          class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
        <beans:property name="userDetailsService" ref="usernameUserDetailsService"/>

        <property name="passwordEncoder" ref="shaPasswordEncoder"/>
        <property name="saltSource">
            <bean class="org.springframework.security.authentication.dao.ReflectionSaltSource">
                <property name="userPropertyToUse" value="username"/>
            </bean>
        </property>
        <beans:property name="postAuthenticationChecks" ref="bUserDetailsChecker"/>
    </bean>

    <beans:bean id="preAuthProvider"
                class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
        <beans:property name="preAuthenticatedUserDetailsService">
            <beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
                <beans:property name="userDetailsService" ref="dnUserDetailsService"/>
            </beans:bean>
        </beans:property>
        <beans:property name="userDetailsChecker" ref="bUserDetailsChecker"/>
    </beans:bean>


    <!-- Auth success handler returns HTTP 200 (ok) to alert user that login was successfull -->
    <bean id="bAuthSuccessHandler" class="bherto.testsecurity.bAuthenticationSuccessHandler"/>

    <bean id="bAuthFailureHandler" class="bherto.testsecurity.bAuthenticationFailureHandler"/>


    <beans:bean id="sas"
                class="org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy">
        <beans:constructor-arg>
            <beans:list>
                <beans:ref bean="concurrentSessionControlAuthenticationStrategy"/>
                <beans:bean
                        class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy"/>
                <beans:bean
                        class="org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy">
                    <beans:constructor-arg ref="sessionRegistry"/>
                </beans:bean>
            </beans:list>
        </beans:constructor-arg>

    </beans:bean>

    <beans:bean id="concurrentSessionControlAuthenticationStrategy"
                class="bherto.security.session.XConcurrentSessionControlAuthenticationStrategy">
        <beans:constructor-arg ref="sessionRegistry"/>
        <beans:property name="maximumSessions" value="-1"/>
        <beans:property name="exceptionIfMaximumExceeded" value="true"/>
    </beans:bean>

    <beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl"/>

    <beans:bean id="nullRequestCache" class="org.springframework.security.web.savedrequest.NullRequestCache"/>

    <bean id="bherto.non.lookupByDNService" class="bherto.security.auth.LookupByDNService"/>
    <bean id="bherto.non.lookupByLoginId" class="bherto.security.auth.LookupByLoginIdService"/>

</beans>

<beans profile="insecure">
    <bean id="springSecurityFilterChain"
          class="bherto.testsecurity.InsecureFilterChain"/>
</beans>

我尝试了以下内容:

//s:beans//security:http[1]

//security:http[1]

无济于事,tnx。我将在maven maven-config-processor-plugin上使用它,并在打包或安装过程中在弹簧配置上动态插入内容。

1 个答案:

答案 0 :(得分:1)

如果在xpath中使用名称空间,则必须在使用xapth的上下文中定义名称空间。

如果不可能,你可以像这样使用通配符:

//*:http[1]

- 编辑 -

我刚刚看到你正在使用allows to define命名空间上下文的maven插件。我想你可以使用它来定义你在xpath中使用的命名空间,而不是依赖通配符。