Printemps de Sécurité gestionnaire d'authentification ne sera pas obtenir ramassé sur filtre personnalisé

Je suis en train de créer un filtre personnalisé pour prendre soin de l'authentification, depuis, je suis obligé d'utiliser une combinaison d'une ANNONCE et de la base de données locale (arg!) pour déterminer les droits d'accès. Je suis en utilisant les docs officielles, pour ce problème particulier pour la plupart cette partie.

Cependant, lorsque je lance mon serveur, il se plaint du AuthenticationManager nul, même si je crois que je suis en train d'en XML comme couvert dans cette SORTE de question. Ce qui me manque ici?

L'exception:

SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myUsernamePasswordAuthenticationFilter' defined in file [*snip*]:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: authenticationManager must be specified
...
Caused by: java.lang.IllegalArgumentException: authenticationManager must be specified
at org.springframework.util.Assert.notNull(Assert.java:112)

XML: (avec un peu simplifié les noms de classe)

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<context:spring-configured />
<context:component-scan base-package="myapp" />
<!-- Spring Security Configuration. -->
<sec:http auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint"
access-denied-page="/denied.jsp">
<sec:custom-filter position="FORM_LOGIN_FILTER" ref="myAuthenticationFilter" />
<sec:intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/404.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/index.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/**" access="ROLE_USER" />
<sec:logout logout-url="/logout" logout-success-url="/login" />
</sec:http>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="myAuthenticationProvider" />
</sec:authentication-manager>
<bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<property name="loginFormUrl" value="/login" />
</bean>
<bean id="myAuthenticationFilter" class="myapp.MyUsernamePasswordAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="myAuthenticationProvider" class="myapp.MyAuthenticationProvider" />

Le Filtre:

@Component
public class MyUsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
public AdminUsernamePasswordAuthenticationFilter() {
super("/login");
}
@Override
public Authentication attemptAuthentication(final HttpServletRequest request,
final HttpServletResponse response) throws AuthenticationException {
//stuff and:
return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(
login, request.getParameter("password")));
}
}

La AuthenticationProvider:

@Component
public class MyAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
//all the funky AD+DB code
return null;
}
@Override
public boolean supports(final Class<?> clazz) {
return true;
}
}

Je suis en cours d'exécution Java 6, le dernier Printemps de Sécurité (3.1.4.De presse) et de Printemps (3.2.3.De presse) les versions, en cours d'exécution sur un Tomcat v6 server. Différentes Printemps versions ne semblent pas être un problème (SI la question). Et si ce serait un problème, d'avoir à exécuter Printemps 3.1.4 si vous souhaitez utiliser de la Sécurité Printemps est juste meh...

Certaines choses, j'ai essayé en vain:

  1. J'ai essayé d'entourer les <sec:authentication-manager /> en faveur d'un haricot, comme mentionné ici (en bas de répondre).
  2. J'ai essayé d'ajouter bean id, noms, l'authentification, le manager de références dans toutes sortes de combinaisons.

OriginalL'auteur basvanstratum | 2013-06-15