首先,我有两个项目:核心,其中我有DTO,服务和DAO,以及 admin ,仅适用于Web服务。 Web服务完全可以抵御数据库,但现在我尝试将Spring Security与自定义身份验证提供程序一起用于数据库,但在部署时得到了
mouseMove
这是我的代码。 WebSecurityConfig
Unable to start embedded container; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'authenticationProvider'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'ctsAuthenticationProvider': Unsatisfied dependency expressed through field 'usuarioServicio'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'usuarioServicio': Unsatisfied dependency expressed through field 'usuarioGestor'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'usuarioGestor': Unsatisfied dependency expressed through field 'usuarioDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'usuarioDAO': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'sessionFactory' defined in class path resource [ec/com/app/core/CoreApplication.class]: Unsatisfied dependency expressed through method 'sessionFactory' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'org.hibernate.jpa.HibernateEntityManagerFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
我的自定义身份验证提供程序CtsAuthenticationProvider
@Configuration
@EnableWebSecurity
@ComponentScan(basePackages = { "ec.com.app.core", "ec.com.app.admin" })
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CtsAuthenticationProvider authenticationProvider;
@Override
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/login").access("permitAll").anyRequest().authenticated().and()
.formLogin().loginPage("/login").and()
.logout().logoutUrl("/logout").deleteCookies("remove")
.and()
.addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class).exceptionHandling()
.authenticationEntryPoint(new UnauthorizedEntryPoint()).and().csrf().disable();
}
@Bean
public AuthenticationFilter authenticationFilter() throws Exception {
AuthenticationFilter authFilter = new AuthenticationFilter();
try {
authFilter.setAuthenticationManager(authenticationManager());
} catch (Exception e) {
throw new Exception(e);
}
authFilter.setRequiresAuthenticationRequestMatcher(new CtsRequestMatcher());
authFilter.setAuthenticationSuccessHandler(new RestAuthenticationSuccessHandler());
authFilter.setAuthenticationFailureHandler(new RestAuthenticationFailureHandler());
return authFilter;
}
}
我的身份验证过滤器
@Component
public class CtsAuthenticationProvider implements AuthenticationProvider {
@Autowired
private IUsuarioServicio usuarioServicio;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
// some authentication code
}
@Override
public boolean supports(Class<?> authentication) {
return ProviderAuthenticationToken.class.equals(authentication);
}
}
我的服务UsuarioServicio
@Component
public class AuthenticationFilter extends UsernamePasswordAuthenticationFilter {
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
// some validation code
}
}
我一直在使用此服务而在某些Web服务中没有任何问题,但现在我尝试实现安全性并获得此错误