|
@@ -2,14 +2,25 @@ package com.ym.mec.task.config;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
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.EnableResourceServer;
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
|
|
|
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
|
|
|
+
|
|
|
|
+import com.ym.mec.common.security.BaseAccessDeniedHandler;
|
|
|
|
+import com.ym.mec.common.security.BaseAuthenticationEntryPoint;
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
@EnableResourceServer
|
|
@EnableResourceServer
|
|
-public class ResourceConfig extends ResourceServerConfigurerAdapter {
|
|
|
|
|
|
+public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseAccessDeniedHandler baseAccessDeniedHandler;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseAuthenticationEntryPoint baseAuthenticationEntryPoint;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void configure(HttpSecurity http) throws Exception {
|
|
public void configure(HttpSecurity http) throws Exception {
|
|
@@ -17,4 +28,9 @@ public class ResourceConfig extends ResourceServerConfigurerAdapter {
|
|
.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and()
|
|
.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and()
|
|
.authorizeRequests().antMatchers("/v2/api-docs").permitAll().anyRequest().authenticated().and().httpBasic();
|
|
.authorizeRequests().antMatchers("/v2/api-docs").permitAll().anyRequest().authenticated().and().httpBasic();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
|
|
|
|
+ resources.authenticationEntryPoint(baseAuthenticationEntryPoint).accessDeniedHandler(baseAccessDeniedHandler);
|
|
|
|
+ }
|
|
}
|
|
}
|