package com.zcxk.security.config;


import com.zcxk.security.mobile.MobileSecurityConfig;
import com.zcxk.security.smsCode.SmsCodeSecurityConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
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;

@Configuration
@EnableResourceServer
@Order(3)
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {


    @Autowired
    private MobileSecurityConfig mobileSecurityConfig;
    @Autowired
    private SmsCodeSecurityConfig smsCodeSecurityConfig;



    @Override
    public void configure(HttpSecurity http) throws Exception {

        http    .apply(mobileSecurityConfig)
                .and()
                .apply(smsCodeSecurityConfig)
                .and()
                .csrf().disable()
                //.exceptionHandling()
                //.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
                //.and()
                .requestMatchers().antMatchers("/**")
                .and()
                .authorizeRequests()
                .antMatchers("/user/getUniqId","/user/getUserStatus","/sms/**","/statics/**","/validateCode/image","/user/**").permitAll()
                .antMatchers("/swagger-ui.html","/webjars/**", "/webjars/**", "/swagger-resources/**",
                        "/v2/**"
                        )
                .permitAll() //配置不需要身份认证的请求路径
                .anyRequest().authenticated(); //其他所有访问路径都需要身份认证
    }

    /*@Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources
                .authenticationEntryPoint(authExceptionEntryPoint)
                .accessDeniedHandler(customAccessDeniedHandler);
    }*/

}
