2014-01-16 4 views
1

Я новичок в Spring. Я пытаюсь следовать образцам кода в книге Весна в действии. Глава о безопасности плохо написана, и я нашел многочисленные ошибки в примере кода. Большинство из них я выяснил с помощью этого awsome сайта, или rtfm. В этом случае, однако, я застрял.Spring Security 3.2 встроенный сервер ldap игнорирует тег ldap-server

Я использую Spring 4.0, Hibernate 4.0, Spring Security 3.2 и Tomcat 7.0.47. Мой пример Spring MVC отлично работает с репозиторием в памяти пользователя (тегом пользовательского сервиса), но когда я пытаюсь перейти к простой службе ldap, я получаю следующую ошибку (копирование и вставка с вывода консоли Tomcat), когда мое приложение загружается Tomcat:

1311 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.context.ApplicationContextException: No BaseLdapPathContextSource instances found. Have you added an <ldap-server /> element to your application context? If you have declared an explicit bean, do not use lazy-init 
    at org.springframework.security.config.ldap.ContextSourceSettingPostProcessor.postProcessBeanFactory(ContextSourceSettingPostProcessor.java:42) 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265) 
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:170) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:663) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1642) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 

Хороший результат, поскольку он говорит мне, что мне не хватает тега ldap-сервера. Ну, нет. Он находится в файле с именем Spitter-security.xml (начиная с линии 11):

<?xml version="1.0" encoding="UTF-8"?> 

<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns="http://www.springframework.org/schema/security" 
    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-4.0.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.2.xsd"> 

<ldap-server root="dc=habuma,dc=com" 
      ldif="classpath:users.ldif" /> 

<authentication-manager alias="authenticationManager"> 
    <ldap-authentication-provider 
        user-search-base="ou=people" 
        user-search-filter="(uid=0})" 
        group-search-base="ou=groups" 
        group-search-filter="member={0}" /> 
</authentication-manager> 
    <!-- 
    Automatically registers a login form, BASIC authentication, anonymous authentication, 
    logout services, remember-me and servlet-api-integration. 
    --> 
    <http request-matcher="regex" pattern="\A/spitters\?new\Z" 
     security="none" > 
    </http> 
    <http auto-config="true" use-expressions="true"> 
    <intercept-url pattern="/resources/css/**" 
        access="permitAll" /> 
    <intercept-url pattern="/resources/images/**" 
        access="permitAll" /> 
    <intercept-url pattern="/login" 
        access="isAnonymous()" /> 
    <intercept-url pattern="/home" 
        access="isAnonymous() or hasAnyRole('ROLE_USER','ROLE_ADMIN')" /> 
    <intercept-url pattern="/admin/**" 
        access="isAuthenticated() and hasRole('ROLE_ADMIN')"/> 
    <intercept-url pattern="/**" 
        access="hasRole('ROLE_USER')" /> 
    <form-login login-page="/login" 
       login-processing-url="/static/j_spring_security_check" 
       authentication-failure-url="/login?login_error=1" 
       default-target-url="/home" 
       always-use-default-target="true"/> 
    <logout logout-url="/static/j_spring_security_logout"/> 

    <!--remember-me key="spitterKey" 
     token-validity-seconds="2419200" /-->  

    </http> 

</beans:beans> 

Вот мой файл web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     version="2.5" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"> 

    <servlet> 
    <servlet-name>spitter</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>spitter</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <listener> 
    <listener-class> 
     org.springframework.web.util.Log4jConfigListener 
    </listener-class> 
    </listener> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
    </listener> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.request.RequestContextListener 
    </listener-class> 
    </listener> 
    <listener> 
    <listener-class> 
     org.springframework.security.web.session.HttpSessionEventPublisher 
    </listener-class> 
    </listener> 

    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/spitter-security.xml 
     classpath:dataSource-context.xml 
     classpath:persistence-context.xml 
     classpath:service-context.xml 
    </param-value> 
    </context-param> 

    <filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class> 
     org.springframework.web.filter.DelegatingFilterProxy 
    </filter-class> 
    </filter> 

    <filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <servlet-name>spitter</servlet-name> 
    </filter-mapping> 
</web-app> 

Вот мой Spitter-servlet.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:context="http://www.springframework.org/schema/context" 
xmlns:util="http://www.springframework.org/schema/util" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:p="http://www.springframework.org/schema/p" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> 

    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <mvc:annotation-driven/> 

    <context:component-scan base-package="com.habuma.spitter.mvc" /> 

    <bean class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"> 
    </bean> 


    <bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
    <property name="definitions"> 
     <list> 
     <value>/WEB-INF/views/**/views.xml</value> 
     </list> 
    </property> 
    </bean> 

    <bean id="multipartResolver" 
     class= 
"org.springframework.web.multipart.commons.CommonsMultipartResolver" 
     p:maxUploadSize="500000" /> 
    <bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
     <value>/resources/ui</value> 
     </list> 
    </property> 
    </bean> 

</beans> 

Вот банки я загружены в WEB-INF/Библиотека:

01/15/2014 10:04 AM   2,000,557 ant-1.9.2.jar 
01/15/2014 10:04 AM   18,333 ant-launcher-1.9.2.jar 
01/15/2014 10:04 AM   445,288 antlr-2.7.7.jar 
01/15/2014 10:04 AM    4,467 aopalliance-1.0.jar 
01/16/2014 04:20 PM   325,112 apacheds-core-1.5.7.jar 
01/16/2014 04:20 PM   186,034 apacheds-core-api-1.5.7.jar 
01/16/2014 04:20 PM   11,467 apacheds-core-constants-1.5.7.jar 
01/16/2014 04:20 PM   33,434 apacheds-core-entry-1.5.7.jar 
01/16/2014 04:20 PM   38,741 apacheds-i18n-1.5.7.jar 
01/16/2014 04:20 PM   12,406 apacheds-utils-1.5.7.jar 
01/15/2014 09:54 PM   60,282 classmate-1.0.0.jar 
01/15/2014 10:04 AM   231,320 commons-beanutils-1.8.0.jar 
01/15/2014 10:04 AM   175,426 commons-collections-2.1.1.jar 
01/16/2014 04:20 PM   575,389 commons-collections-3.2.1.jar 
01/15/2014 10:04 AM   148,783 commons-digester-2.0.jar 
01/15/2014 10:04 AM   68,622 commons-fileupload-1.3.jar 
01/15/2014 07:11 PM   185,140 commons-io-2.4.jar 
01/15/2014 10:04 AM   52,915 commons-logging-1.1.jar 
01/15/2014 10:04 AM   26,202 commons-logging-api-1.0.4.jar 
01/15/2014 10:04 AM   313,898 dom4j-1.6.1.jar 
01/15/2014 10:04 AM   15,649 geronimo-jta_1.1_spec-1.1.jar 
01/15/2014 10:04 AM   75,311 hibernate-commons-annotations-4.0.4.Final.jar 
01/15/2014 10:04 AM   5,208,917 hibernate-core-4.3.0.Final.jar 
01/15/2014 10:04 AM   645,015 hibernate-entitymanager-4.3.0.Final.jar 
01/15/2014 10:04 AM   113,371 hibernate-jpa-2.1-api-1.0.0.Final.jar 
01/15/2014 10:04 AM   377,562 hibernate-tools-4.0.0-CR1.jar 
01/15/2014 09:49 PM   574,341 hibernate-validator-5.0.2.Final.jar 
01/15/2014 09:04 PM   1,467,326 hsqldb-2.3.1.jar 
01/15/2014 10:04 AM   76,551 jandex-1.1.0.Final.jar 
01/15/2014 10:04 AM   714,194 javassist-3.18.1-GA.jar 
01/15/2014 10:04 AM    2,497 javax.inject-1.jar 
01/15/2014 10:04 AM   57,183 jboss-logging-3.1.3.GA.jar 
01/15/2014 10:04 AM   11,558 jboss-logging-annotations-1.2.0.Beta1.jar 
01/15/2014 10:04 AM   27,717 jboss-transaction-api_1.2_spec-1.0.0.Final.jar 
01/15/2014 10:04 AM   17,097 jcl-over-slf4j-1.5.8.jar 
01/15/2014 10:04 AM   414,240 jstl-1.2.jar 
01/15/2014 10:04 AM   15,071 jta-1.1.jar 
01/15/2014 10:04 AM   249,028 jtidy-r8-20060801.jar 
01/15/2014 01:10 PM   489,884 log4j-1.2.17.jar 
01/16/2014 04:20 PM   638,294 mina-core-2.0.0-RC1.jar 
01/15/2014 10:04 AM   52,150 persistence-api-1.0.jar 
01/16/2014 04:20 PM   96,747 shared-asn1-0.9.19.jar 
01/16/2014 04:20 PM   12,769 shared-asn1-codec-0.9.19.jar 
01/16/2014 04:20 PM   19,647 shared-cursor-0.9.19.jar 
01/16/2014 04:20 PM   183,195 shared-dsml-parser-0.9.19.jar 
01/16/2014 04:20 PM   26,078 shared-i18n-0.9.19.jar 
01/16/2014 04:20 PM   1,404,206 shared-ldap-0.9.19.jar 
01/16/2014 04:20 PM   23,568 shared-ldap-constants-0.9.19.jar 
01/16/2014 04:20 PM   32,976 shared-ldap-converter-0.9.19.jar 
01/16/2014 04:20 PM   13,196 shared-ldap-jndi-0.9.19.jar 
01/16/2014 04:20 PM   590,303 shared-ldap-schema-0.9.19.jar 
01/16/2014 04:20 PM    6,928 shared-ldap-schema-dao-0.9.19.jar 
01/16/2014 04:20 PM   27,319 shared-ldap-schema-loader-0.9.19.jar 
01/16/2014 04:20 PM   20,108 shared-ldap-schema-manager-0.9.19.jar 
01/16/2014 04:20 PM   44,343 shared-ldif-0.9.19.jar 
01/15/2014 10:04 AM   25,689 slf4j-api-1.6.2.jar 
01/15/2014 10:04 AM    7,668 slf4j-simple-1.6.2.jar 
01/15/2014 10:04 AM   351,240 spring-aop-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   669,267 spring-beans-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   148,444 spring-binding-2.3.2.RELEASE.jar 
01/15/2014 10:04 AM   950,606 spring-context-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   955,328 spring-core-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   206,507 spring-expression-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   419,872 spring-jdbc-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   17,381 spring-js-2.3.2.RELEASE.jar 
01/15/2014 10:04 AM   4,412,472 spring-js-resources-2.3.2.RELEASE.jar 
01/16/2014 01:51 PM   231,729 spring-ldap-core-1.3.1.RELEASE.jar 
01/15/2014 10:04 AM   316,834 spring-orm-4.0.0.RELEASE.jar 
01/15/2014 11:49 AM   81,373 spring-security-acl-3.2.0.RELEASE.jar 
01/15/2014 10:04 AM   399,068 spring-security-config-3.2.0.RELEASE.jar 
01/15/2014 10:04 AM   359,510 spring-security-core-3.2.0.RELEASE.jar 
01/15/2014 11:49 AM   20,992 spring-security-taglibs-3.2.0.RELEASE.jar 
01/15/2014 10:04 AM   342,227 spring-security-web-3.2.0.RELEASE.jar 
01/15/2014 10:04 AM   441,609 spring-test-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   248,001 spring-tx-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   661,567 spring-web-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   522,586 spring-webflow-2.3.2.RELEASE.jar 
01/15/2014 10:04 AM   660,682 spring-webmvc-4.0.0.RELEASE.jar 
01/15/2014 10:04 AM   30,143 tiles-api-3.0.3.jar 
01/15/2014 10:04 AM   11,773 tiles-autotag-core-runtime-1.1.0.jar 
01/15/2014 10:04 AM   81,289 tiles-core-3.0.3.jar 
01/15/2014 10:04 AM   35,366 tiles-jsp-3.0.3.jar 
01/15/2014 10:04 AM   71,616 tiles-request-api-1.0.3.jar 
01/15/2014 10:04 AM   17,026 tiles-request-jsp-1.0.3.jar 
01/15/2014 10:04 AM   20,035 tiles-request-servlet-1.0.3.jar 
01/15/2014 10:04 AM   25,059 tiles-servlet-3.0.3.jar 
01/15/2014 10:04 AM   31,772 tiles-template-3.0.3.jar 
01/15/2014 09:49 PM   63,777 validation-api-1.1.0.Final.jar 

Любая идея, почему получение простого примера (как указано в руководствах и этой книге), по-видимому, не так прост? Как мне узнать, что есть в файле (файл работал, пока я не попытался изменить его, чтобы использовать LDAP)?

ответ

0

После долгих поисков я обнаружил, что у меня есть две версии коллекций коллекций коллекций. Когда я удалил версию 2.1.1, так что у меня была версия 3.2.1, эта ошибка исчезла.

Затем я столкнулся с проблемой, что текущая версия Spring Security несовместима с текущей версией ApacheDS (в последней версии отсутствуют классы), поэтому вы действительно не можете использовать встроенный сервер LDAP для тестирования с последними и величайшими релизами всего. Так много для примеров в книге и в руководстве.

+0

Вы можете рассмотреть [подачу ошибки] (https://jira.springsource.org/). –

Смежные вопросы