12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package com.huaxu.security.config;
- import com.huaxu.security.mobile.MobileSecurityConfig;
- import com.huaxu.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;
- import org.springframework.security.web.authentication.AuthenticationFailureHandler;
- import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
- @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("/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);
- }*/
- }
|