package cn.reghao.tnb.auth.app.security;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * @author reghao
 * @date 2023-07-26 10:12:34
 */
//@Configuration
//@EnableResourceServer
public class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter {
    private static final String resourceId = "account_info";

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        // 如果关闭 stateless，则 accessToken 使用时的 session id 会被记录，后续请求不携带 accessToken 也可以正常响应
        resources.resourceId(resourceId).stateless(true);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
/*        http
                .requestMatchers()
                // 保险起见，防止被主过滤器链路拦截
                .antMatchers("/api/account/resource/**")
                .and()
                .authorizeRequests()
                .antMatchers("/api/account/resource/my/**").access("#oauth2.hasScope('get_my_info')")
                .antMatchers("/api/account/resource/user/**").access("#oauth2.hasScope('get_user_info')");

        http.exceptionHandling()
                .authenticationEntryPoint(new MyAuthenticationEntryPoint());*/
    }
}
