Spring Security 3.1.4 用に独自のオーセンティケーター プロバイダーを実装しています。
しかし、Tomcat でアプリケーションを実行すると、Tomcat からこのログ エラーが表示されます。
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myAppAuthenticationProvider' is defined
web.xml では、他のものよりもこれがあります。
<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>
myapp-servlet.xmlには、他のものよりもこれがあります。
<!-- 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" />
myapp-security.xmlには、他のものよりもこれがあります。
<security:authentication-manager alias="myAuthenticationManager">
<security:authentication-provider ref="myAppAuthenticationProvider" />
</security:authentication-manager>
次に、このような認証プロバイダーを用意します。
@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;
}
}
誰か助けてくれませんか?, よろしくお願いします.`ここにコードを入力してください