autowired - Spring Security AuthenticationProvider No Bean Defined -
i implementing own authenticator provider spring security 3.1.4.
but when running application on tomcat receive log error tomcat.
org.springframework.beans.factory.nosuchbeandefinitionexception: no bean named 'myappauthenticationprovider' defined
in web.xml y have others things.
<context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/applicationcontext.xml, /web-inf/myapp-datasource.xml, /web-inf/myapp-security.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> </filter-mapping>
in myapp-servlet.xml y have others things.
<!-- activa la configuracion de beans mediante anotaciones --> <mvc:annotation-driven /> <!-- activa la configuracion de los controladores mediante anotaciones --> <context:component-scan base-package="com.myapp.**" /> <!-- activa la configuracion de seguridad mediante anotaciones --> <security:global-method-security secured-annotations="enabled" pre-post-annotations="enabled" />
in myapp-security.xml y have others things.
<security:authentication-manager alias="myauthenticationmanager"> <security:authentication-provider ref="myappauthenticationprovider" /> </security:authentication-manager>
then, have authenticator provider this.
@component("myappauthenticationprovider") public class myappauthenticationprovider implements authenticationprovider { private static final logger log = loggerfactory.getlogger(authenticationprovider.class); @autowired private userservice userservice; @override public final authentication authenticate(authentication authentication) { final usernamepasswordwithtypeauthenticationtoken authenticationtoken = (usernamepasswordwithtypeauthenticationtoken) authentication; string name = authenticationtoken.getname(); string password = authenticationtoken.getcredentials().tostring(); string type = authenticationtoken.gettype(); if(isuservalid(authentication)){ list<grantedauthority> grantedauth = new arraylist<grantedauthority>(); grantedauth.add(new simplegrantedauthority("role_user")); authentication auth = new usernamepasswordauthenticationtoken(name, password, grantedauth); return auth; }else { throw new badcredentialsexception("bad authentication."); } } @override public final boolean supports(class<?> authentication) { return usernamepasswordwithtypeauthenticationtoken.class.isassignablefrom(authentication); } private boolean isuservalid(authentication authentication) { user user = this.userservice.getuserbyemailandpassword( authentication.getname(), authentication.getcredentials().tostring()); if (user != null) { return true; } return false; } }
somebody can me?, in advance.`enter code here
you have 2 spring contexts (first 1 application beans / ds / security , second 1 spring mvc). please make sure myappauthenticationprovider
picked in first 1 corresponding component-scan
element. pretty sure picked second context (spring mvc) , referenced first one, not exist.
Comments
Post a Comment