为什么我的OAuth2资源服务器不生效呢?api/**的请求不登录也能访问.虽然security放行了,但是资源服务器为什么不拦截呢
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/**").hasRole("admin")
.anyRequest().authenticated()
// .and()
// .requestMatchers()
// /api/**请求需要OAuth鉴权
;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http // 配置登录页并允许访问
//.formLogin().permitAll()
// 配置Basic登录
//.and().httpBasic()
// 配置登出页面
.logout().logoutUrl("/logout").logoutSuccessUrl("/")
// 配置允许访问的链接
.and().authorizeRequests().antMatchers("/**").permitAll()
// 其余所有请求全部需要鉴权认证
.anyRequest().authenticated()
// 关闭跨域保护;
.and().csrf().disable();
}