2012-12-28 7 views
10

Possible Duplicate:
Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘springSecurityFilterChain’ is definedNo fagiolo di nome AuthenticationManager

Nel mio Primavera Application, continuo a ricevere questo errore:

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. 

Nel mio file di contesto XML Primavera di sicurezza, ho definito il seguente:

<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> 

Qualche idea del perché lamentarsi, quando ho chiaramente definito il mio gestore di autenticazione e il provider di autenticazione?

Nota: questo potrebbe aiutare, è un errore più descrittivo:

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. 

risposta

13

L'AuthenticationManager viene cercato da nome, quindi basta cambiarlo al seguente:

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

questo non ha funzionato per me. – user1007895

+0

o anche iMysak

+0

basta rimuovere 'id =" clientAuthenticationManager "' dal secondo suggerimento e vedere se funziona - vedi modifica aggiornata. –

1

un'occhiata a questo 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

puoi mostrare un po 'di codice? – user1007895

2

È necessario modificare il file di contesto di sicurezza Spring per cercare clientAuthenticationManager. Puoi aggiungere questa linea alla tua configurazione http

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

Sì, sta tentando di ottenere il riferimento al gestore autenticazione con il nome di "authenticationManager", quindi riempi il riferimento ref. –

Problemi correlati