【发布时间】:2016-07-19 10:47:08
【问题描述】:
我想为 spring 安全性提供一个自定义身份验证提供程序,并且我已经像这样实现了它
@Component
public class ApiCustomAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
System.out.println("ahsgdvjasdhgjasjdh");
return new UsernamePasswordAuthenticationToken("aman", "12345");
}
@Override
public boolean supports(Class<?> authentication) {
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
}
}
现在我没有任何逻辑,因为我只想看看 spring security 是否真的在使用这个身份验证提供程序。
我的安全配置文件为
@Configuration
@EnableWebSecurity
//@ImportResource("classpath:/security/spring_saml_sso_security.xml")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/*@Autowired
MetadataGeneratorFilter metadataGeneratorFilter;
@Autowired
FilterChainProxy samlFilter;
@Autowired
SAMLEntryPoint samlEntryPoint;
*/
@Autowired
private CustomUserDetailsService customUserDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
try {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/static/**").permitAll()
.antMatchers("/settings/api/**").permitAll()
.antMatchers("/api/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.loginProcessingUrl("/login")
// .usernameParameter("username").passwordParameter("password")
.defaultSuccessUrl("/index",true)
.and()
.httpBasic();
// .defaultSuccessUrl("/", true);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("sadhiasdniaaaaaaaaaaaaaaaa:");
e.printStackTrace();
}
}
@Bean
public ApiCustomAuthenticationProvider apiCustomAuthenticationProvider() {
return new ApiCustomAuthenticationProvider();
}
}
我想知道这个
@Bean
public ApiCustomAuthenticationProvider apiCustomAuthenticationProvider() {
return new ApiCustomAuthenticationProvider();
是告诉 spring security 使用自定义身份验证管理器的正确方法。
【问题讨论】:
标签: java spring security spring-mvc spring-security