SpringCloud、SpringBoot2.0 整合Oauth2 (四) 配置文件快速配置url过滤

SpringBoot2.0 整合Oauth2 (四) 配置文件快速配置url过滤

1、添加url过滤配置
ignore:
  urls:
  - /oauth/token
  - /notify/**
  #- /**
  clients:
    - singleApp
2、添加配置类
/**
 * ===================================
 * 描 述 : 配置过滤
 * 包 名 : top.qinxq.single.common.auth
 * 创建人 : qinxq
 * ===================================
 */
@Data
@Configuration
@ConditionalOnExpression("!'${ignore}'.isEmpty()")
@ConfigurationProperties(prefix = "ignore")
public class FilterIgnorePropertiesConfig {
    private List<String> urls = new ArrayList<>();
    private List<String> clients = new ArrayList<>();
}
3、配置资源服务器
/**
 * ===================================
 * 描 述 : 资源服务器
 * 包 名 : top.qinxq.single.common.auth
 * 创建人 : qinxq
 * ===================================
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
    @Autowired
    private FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
    @Autowired
    private AuthExceptionHandler authExceptionHandler;
    @Override
    public void configure(HttpSecurity http) throws Exception {

//        //表单登录 方式
//        http.formLogin()
//                .loginPage("/authentication/require")
//                //登录需要经过的url请求
//                .loginProcessingUrl("/authentication/form");

//        http
//                .authorizeRequests()
//                .antMatchers("/oauth/token").permitAll()
//                .anyRequest()
//                .authenticated()
//                .and()
//                //关闭跨站请求防护
//                .csrf().disable();

        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry =
                http.authorizeRequests();
        //加载配置文件中ignore过滤列表
        filterIgnorePropertiesConfig.getUrls().forEach(url -> registry.antMatchers(url).permitAll());
        registry.anyRequest().authenticated()
                .and()
                .csrf().disable();
        http.csrf().disable();//关闭 csrf 允许跨域
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.accessDeniedHandler(authExceptionHandler)
                .authenticationEntryPoint(authExceptionHandler);
    }
}
相关链接
SpringCloud、SpringBoot2.0 整合Oauth2 (一) 基本配置

SpringCloud、SpringBoot2.0 整合Oauth2 (一) 基本配置

SpringCloud、SpringBoot2.0 整合Oauth2 (二) 自定义返回格式及用户基本信息

SpringCloud、SpringBoot2.0 整合Oauth2 (二) 自定义返回格式及用户基本信息

SpringCloud、SpringBoot2.0 整合Oauth2 (三) token改为redis存储方式

SpringBoot2.0 整合Oauth2 (三) token改为redis存储方式

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值