Spring Security 3.1和正确的罐子

时间:2012-03-15 21:06:31

标签: spring-security

我正在使用Spring 3.1,而且我是第一次使用LDAP。

这是我的* -security.xml:

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

  <http auto-config="true">
    <intercept-url pattern="/welcome*" access="ROLE_USER" />
    <form-login login-page="/login" default-target-url="/welcome"
      authentication-failure-url="/loginfailed" />
    <logout logout-success-url="/logout" />
  </http>

  <ldap-server url = "ldap://ldap-east.abc.acme.org:636/o=acme.org" />

    <authentication-manager>
      <ldap-authentication-provider user-dn-pattern="uid={0},ou=people"/>
    </authentication-manager>

</beans:beans>

我从我的lib开始使用这些与安全相关的jar:

spring-security-ldap-3.1.0.RELEASE.jar
spring-security-config-3.1.0.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-taglibs-3.1.0.RELEASE.jar
spring-security-web-3.1.0.RELEASE.jar

我收到此错误消息:

  

org.springframework.context.ApplicationContextException:       找不到:org.springframework.ldap.core.support.BaseLdapPathContextSource。
      如果您在Spring Security中使用LDAP,       请确保在您的应用程序中包含spring-ldap jar文件;       嵌套异常是java.lang.ClassNotFoundException:       org.springframework.ldap.core.support.BaseLdapPathContextSource

所以,我在lib中添加了更多jar作为这组安全文件:

spring-ldap-core-1.3.1.RELEASE.jar
spring-ldap-core-tiger-1.3.1.RELEASE.jar
spring-security-ldap-3.1.0.RELEASE.jar
spring-security-config-3.1.0.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-taglibs-3.1.0.RELEASE.jar
spring-security-web-3.1.0.RELEASE.jar

这让我更深入了解更多错误消息:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.filterChains': 
Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' 
while setting bean property 'sourceList' with key [0]; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': 
Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' 
while setting constructor argument with key [2]; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0':
Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' w
hile setting bean property 'authenticationManager'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': 
Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' 
while setting constructor argument; nested exception is 
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': 
FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.authenticationManager': 
Cannot resolve reference to bean 'org.springframework.security.ldap.authentication.LdapAuthenticationProvider#0' 
while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.ldap.authentication.LdapAuthenticationProvider#0': 
Cannot create inner bean '(inner bean)' of type [org.springframework.security.ldap.authentication.BindAuthenticator] 
while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name '(inner bean)#17': Cannot resolve reference to bean 'org.springframework.security.securityContextSource' 
while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.securityContextSource': 
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Could not instantiate bean class [org.springframework.security.ldap.DefaultSpringSecurityContextSource]: 
Constructor threw exception; nested exception is java.lang.NoClassDefFoundE

我正在追赶很多事情,学习Maven就在我的名单上,但我还没有。有关使用Spring 3.1进行基本LDAP身份验证的正确混合罐的任何提示吗?

我尝试加载整个Spring 3.1.1 dist,整个Spring LDAP 1.3.1 dist和整个Spring Security 3.1.0 dist。我有一切。所以我很遗憾看到这是一个依赖性问题,FWIW。

2 个答案:

答案 0 :(得分:7)

spring-security-config
spring-security-taglibs
spring-security-ldap

这3个应该足够了,如果你使用maven或类似的工具,他们将拉他们的dependendies。

如果没有,您需要遍历所有3个库并在类路径中复制所有依赖项。

Dependency graph

答案 1 :(得分:2)

检查此帖子Moved to Spring 3.1.1 from Spring 3.0.5 now my App does not work

正如ryan-stewart所说:

  

Blockquote spring-ldap不包含在基础弹簧3.1发行版中。实际上,它的版本控制是完全独立的,目前版本为1.3.1。

您需要从here

下载额外的罐子

所有功劳归于ryan-stewart