Browse Source

解决不调用授权服务的问题

weifanli 3 years ago
parent
commit
f4417fe24c

+ 0 - 6
cooleshow-common/pom.xml

@@ -60,12 +60,6 @@
 		</dependency>
 
 		<dependency>
-			<groupId>org.springframework.security.oauth</groupId>
-			<artifactId>spring-security-oauth2</artifactId>
-			<version>2.2.1.RELEASE</version>
-		</dependency>
-
-		<dependency>
 			<groupId>com.vdurmont</groupId>
 			<artifactId>emoji-java</artifactId>
 		</dependency>

+ 0 - 4
cooleshow-user/user-admin/pom.xml

@@ -72,10 +72,6 @@
 				<groupId>org.springframework.boot</groupId>
 				<artifactId>spring-boot-maven-plugin</artifactId>
 			</plugin>
-			<plugin>
-				<groupId>com.spotify</groupId>
-				<artifactId>docker-maven-plugin</artifactId>
-			</plugin>
 		</plugins>
 	</build>
 </project>

+ 41 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/config/ResourceServerConfig.java

@@ -0,0 +1,41 @@
+package com.yonge.cooleshow.admin.config;
+
+import com.yonge.cooleshow.common.security.BaseAccessDeniedHandler;
+import com.yonge.cooleshow.common.security.BaseAuthenticationEntryPoint;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+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;
+
+@Configuration
+@EnableResourceServer
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
+
+	@Autowired
+	private BaseAccessDeniedHandler baseAccessDeniedHandler;
+
+	@Autowired
+	private BaseAuthenticationEntryPoint baseAuthenticationEntryPoint;
+
+	@Override
+	public void configure(HttpSecurity http) throws Exception {
+		http.csrf()
+				.disable()
+				.exceptionHandling()
+				.accessDeniedHandler(baseAccessDeniedHandler)
+				.authenticationEntryPoint(baseAuthenticationEntryPoint)
+				.and()
+				.authorizeRequests()
+				.antMatchers("/v2/api-docs", "/code/*").permitAll().anyRequest().authenticated().and().httpBasic();
+	}
+
+	@Override
+	public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+		resources.authenticationEntryPoint(baseAuthenticationEntryPoint).accessDeniedHandler(baseAccessDeniedHandler);
+	}
+
+}

+ 2 - 1
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/MusicSheetController.java

@@ -8,6 +8,7 @@ import com.yonge.cooleshow.common.controller.BaseController;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -23,7 +24,7 @@ public class MusicSheetController extends BaseController {
     private MusicSheetService musicSheetService;
 
     @ApiOperation(value = "新增曲谱")
-    @RequestMapping("/sheet/create")
+    @PostMapping("/create")
     public Object create(@RequestBody MusicSheet musicSheet) {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if (sysUser == null) {