Browse Source

修改security 不拦截api/**接口

肖玮 5 years ago
parent
commit
5e0e30ba51

+ 10 - 0
mec-education/pom.xml

@@ -91,6 +91,16 @@
 			<groupId>javax.persistence</groupId>
 			<artifactId>javax.persistence-api</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.ym</groupId>
+			<artifactId>common-core</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>org.mybatis.spring.boot</groupId>
+					<artifactId>mybatis-spring-boot-starter</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
 
 	</dependencies>
 	<build>

+ 3 - 1
mec-education/src/main/java/com/ym/mec/education/EducationApplication.java

@@ -7,12 +7,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.client.RestTemplate;
 
-@MapperScan("com.ym.mec.education.mapper*")
+@MapperScan("com.ym.mec.education.mapper")
 @SpringBootApplication
 @EnableDiscoveryClient
+@ComponentScan(basePackages = "com.ym.mec")
 @Configuration
 @EnableSwagger2Doc
 public class EducationApplication {

+ 14 - 15
mec-education/src/main/java/com/ym/mec/education/config/ResourceServerConfig.java

@@ -1,4 +1,3 @@
-/*
 package com.ym.mec.education.config;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,7 +6,6 @@ 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;
-
 import com.ym.mec.common.security.BaseAccessDeniedHandler;
 import com.ym.mec.common.security.BaseAuthenticationEntryPoint;
 
@@ -15,21 +13,22 @@ import com.ym.mec.common.security.BaseAuthenticationEntryPoint;
 @EnableResourceServer
 public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 
-	@Autowired
-	private BaseAccessDeniedHandler baseAccessDeniedHandler;
+    @Autowired
+    private BaseAccessDeniedHandler baseAccessDeniedHandler;
 
-	@Autowired
-	private BaseAuthenticationEntryPoint baseAuthenticationEntryPoint;
+    @Autowired
+    private BaseAuthenticationEntryPoint baseAuthenticationEntryPoint;
 
-	@Override
-	public void configure(HttpSecurity http) throws Exception {
-		http.csrf().disable().authorizeRequests().antMatchers("/v2/api-docs").permitAll().anyRequest().authenticated().and().httpBasic();
-	}
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        http.csrf().disable().authorizeRequests().antMatchers("/v2/api-docs").permitAll()
+                .antMatchers("/api/**").permitAll()
+                .anyRequest().authenticated().and().httpBasic();
+    }
 
-	@Override
-	public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
-		resources.authenticationEntryPoint(baseAuthenticationEntryPoint).accessDeniedHandler(baseAccessDeniedHandler);
-	}
+    @Override
+    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+        resources.authenticationEntryPoint(baseAuthenticationEntryPoint).accessDeniedHandler(baseAccessDeniedHandler);
+    }
 
 }
-*/

+ 2 - 5
mec-education/src/main/java/com/ym/mec/education/config/WebMvcConfig.java

@@ -1,4 +1,3 @@
-/*
 package com.ym.mec.education.config;
 
 import java.io.IOException;
@@ -39,10 +38,9 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 @Configuration
 public class WebMvcConfig implements WebMvcConfigurer {
 
-	*/
-/**
+	/**
 	 * 枚举类的转换器 addConverterFactory
-	 *//*
+	 */
 
 	@Override
 	public void addFormatters(FormatterRegistry registry) {
@@ -107,4 +105,3 @@ public class WebMvcConfig implements WebMvcConfigurer {
 	}
 
 }
-*/

+ 3 - 1
mec-education/src/main/java/com/ym/mec/education/controller/MusicGroupController.java

@@ -4,6 +4,7 @@ import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
 import com.ym.mec.education.base.BaseResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.persistence.GenerationType;
@@ -14,7 +15,8 @@ import javax.persistence.GenerationType;
  * @Description: TODO
  * @date Date : 2019年09月25日 17:39
  */
-@RestController(value = "musicGroup")
+@RestController
+@RequestMapping("/api/musicGroup")
 @DefaultProperties(defaultFallback = "defaultFallback")
 @Slf4j
 public class MusicGroupController {