我定义了三个类
@Configuration
@EnableWebSecurity
public class BCSecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private DataSource dataSource;
@Override
public void configure(HttpSecurity http) throws Exception {
super.configure(http);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource);
}
}
另外两个是认证服务器
@Configuration
@EnableAuthorizationServer
public class BCAuthorizationServerConfig {
}
和资源服务器
@Configuration
@EnableResourceServer
public class BCResourceServerConfig extends ResourceServerConfigurerAdapter{
@Override
public void configure(HttpSecurity http) throws Exception {
//表单登录 方式
http.formLogin().and()
.authorizeRequests()
.antMatchers("/api/**")
.authenticated()
.antMatchers("/oauth/token").permitAll()
.and()
.csrf().disable();
}
}
有一个问题就是,当你配置了资源服务器的时候访问需要认证的链接返回的是
这是没有问题的,但是我想实现的是当你在没有认证的情况下访问其他的链接的时候自动跳转到登录页,也就是我想让BCResourceServerConfig资源服务器不处理的链接交给我配置的BCSecurityConfig这个类处理?请问怎么实现呢,请不吝赐教不胜感激!!!
我的最终目的是它既能提供安全的网页服务(登陆验证)!又能够通过oauth提供token