2012-12-28 1 views
10

Possible Duplicate:
Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘springSecurityFilterChain’ is definedKeine Bean mit dem Namen AuthenticationManager

In meinem Frühling Anwendung, halte ich diesen Fehler:

No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a gobal <authentication-manager> element to your configuration (with child <authentication-provider> elements)? Alternatively you can use the authentication-manager-ref attribute on your <http> and <global-method-security> elements. 

In meinem Spring Security Kontext XML-Datei, ich habe folgendes definiert:

<beans:bean id="myUserDetailsService" class="com.myProject.core.security.MyUserDetailsService" /> 

<beans:bean id="encoder" class="com.myProject.core.security.HmacPasswordEncoder" /> 

<authentication-manager id="clientAuthenticationManager" > 
    <authentication-provider user-service-ref="myUserDetailsService"> 
     <password-encoder ref="encoder" /> 
    </authentication-provider> 
</authentication-manager> 

Irgendwelche Ideen, warum es sich beschweren, wenn ich meinen Authentifizierungsmanager und Authentifizierungsanbieter klar definiert habe?

Hinweis: Dies könnte helfen, seine einen aussagekräftigeren Fehler:

org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'org.springframework.security.filterChains': Cannot resolve reference to bean 
'org.springframework.security.web.DefaultSecurityFilterChain#2' while setting bean 
property 'sourceList' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': 
Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' 
while setting constructor argument with key [1]; 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' 
while 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.NoSuchBeanDefinitionException: No bean named 
'org.springframework.security.authenticationManager' is defined: Did you forget to 
add a gobal <authentication-manager> element to your configuration (with child 
<authentication-provider> elements)? Alternatively you can use the authentication-manager-ref 
attribute on your <http> and <global-method-security> elements. 

Antwort

13

Die AuthenticationManager sah besteht durch Name, so ändern Sie es einfach zu dem folgenden:

<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="myUserDetailsService"> 
     <password-encoder ref="encoder" /> 
    </authentication-provider> 
</authentication-manager> 
+0

das hat nicht für mich funktioniert. – user1007895

+0

oder sogar iMysak

+0

entfernen Sie einfach den 'id =" clientAuthenticationManager "' aus dem zweiten Vorschlag und sehen Sie, ob das funktioniert - siehe aktualisierten Edit. –

1

Blick auf diesen Link:

Notice that the filter is actually a DelegatingFilterProxy, and not the class that will actually implement the logic of the filter. What DelegatingFilterProxy does is delegate the Filter's methods through to a bean which is obtained from the Spring application context.

...

You need to define a bean named springSecurityFilterChain that implements javax.servlet.Filter in your application context.

+0

Können Sie Code anzeigen? – user1007895

2

Sie müssen Ihre Spring Security Context-Datei ändern, um nach dem clientAuthenticationManager zu suchen. Sie können diese Zeile zu Ihrem HTTP-Setup hinzufügen.

<http use-expressions="true" authentication-manager-ref="clientAuthenticationManger"> 
+0

Ja, es versucht, die Authentifizierungsmanagerreferenz unter dem Namen "authenticationManager" zu erhalten, füllen Sie also Ihre Authentifizierungsmanagerref. –