瀏覽代碼

Merge branch 'master' of https://gitee.com/zouxuan/mec

zouxuan 5 年之前
父節點
當前提交
96a324b3d3

+ 4 - 5
cms/src/main/java/com/ym/mec/cms/config/ResourceServerConfig.java

@@ -1,7 +1,5 @@
 package com.ym.mec.cms.config;
 
-import javax.servlet.http.HttpServletResponse;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -24,9 +22,10 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 
 	@Override
 	public void configure(HttpSecurity http) throws Exception {
-		http.csrf().disable().exceptionHandling()
-				.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and()
-				.authorizeRequests().antMatchers("/v2/api-docs", "/news/list", "/news/query/*").permitAll().anyRequest().authenticated().and().httpBasic();
+		http.authorizeRequests().antMatchers("/v2/api-docs", "/news/list", "/news/query/*").permitAll()// 任何人不登录都可以获取的资源
+				// .antMatchers("/ipController/**").hasIpAddress("127.0.0.1") //特定ip可以不登录获取资源
+				// .antMatchers("/ipControll/**").access("isAuthenticated() and hasIpAddress('127.0.0.1')")// 特定ip必须登录才能获取
+				.anyRequest().authenticated().and().csrf().disable();
 	}
 
 	@Override

+ 3 - 0
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/client/SysUserFeignService.java

@@ -12,4 +12,7 @@ public interface SysUserFeignService {
 
 	@GetMapping(value = "query/{username}")
 	public SysUserInfo getUser(@PathVariable("username") String username, @RequestHeader("from") String from);
+
+	@GetMapping(value = "task/test")
+	public Object test();
 }

+ 1 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/config/ResourceServerConfig.java

@@ -29,7 +29,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 	public void configure(HttpSecurity http) throws Exception {
 		http.csrf().disable().exceptionHandling()
 				.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and()
-				.authorizeRequests().anyRequest().authenticated().and().httpBasic();
+				.authorizeRequests().antMatchers("/task/**").hasIpAddress("0.0.0.0/0").anyRequest().authenticated().and().httpBasic();
 	}
 
 	@Override

+ 19 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/TaskController.java

@@ -0,0 +1,19 @@
+package com.ym.mec.auth.web.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.ym.mec.common.controller.BaseController;
+
+@RestController()
+@RequestMapping("task")
+public class TaskController extends BaseController {
+
+	@GetMapping("/test")
+	public Object test() {
+		System.out.println("测试第一个定时任务");
+		return succeed();
+	}
+
+}

+ 5 - 0
mec-task/pom.xml

@@ -59,6 +59,11 @@
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
         </dependency>
+        
+        <dependency>
+        	<groupId>com.ym</groupId>
+        	<artifactId>mec-auth-api</artifactId>
+        </dependency>
 		
 	</dependencies>
 	

+ 1 - 1
mec-task/src/main/java/com/ym/mec/task/TaskApplication.java

@@ -15,7 +15,7 @@ import com.spring4all.swagger.EnableSwagger2Doc;
 
 @SpringBootApplication
 @EnableDiscoveryClient
-@EnableFeignClients
+@EnableFeignClients("com.ym.mec")
 @MapperScan("com.ym.mec.task.dal.dao")
 @ComponentScan(basePackages="com.ym.mec")
 @Configuration

+ 1 - 5
mec-task/src/main/java/com/ym/mec/task/config/ResourceServerConfig.java

@@ -1,7 +1,5 @@
 package com.ym.mec.task.config;
 
-import javax.servlet.http.HttpServletResponse;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -24,9 +22,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 
 	@Override
 	public void configure(HttpSecurity http) throws Exception {
-		http.csrf().disable().exceptionHandling()
-				.authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and()
-				.authorizeRequests().antMatchers("/v2/api-docs").permitAll().anyRequest().authenticated().and().httpBasic();
+		http.authorizeRequests().antMatchers("/v2/api-docs").permitAll().anyRequest().authenticated().and().csrf().disable();
 	}
 
 	@Override

+ 0 - 20
mec-task/src/main/java/com/ym/mec/task/jobs/QueryPayStatusTask.java

@@ -1,20 +0,0 @@
-package com.ym.mec.task.jobs;
-
-import com.ym.mec.task.core.BaseTask;
-import com.ym.mec.task.core.TaskException;
-import org.springframework.stereotype.Service;
-
-/**
- * 手动查询订单支付状态
- */
-@Service
-public class QueryPayStatusTask extends BaseTask {
-
-	@Override
-	public void execute() throws TaskException {
-		// TODO Auto-generated method stub
-		System.out.println("打印一句话就可以了!");
-
-	}
-
-}

+ 9 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/TestTask.java

@@ -1,16 +1,25 @@
 package com.ym.mec.task.jobs;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.task.core.BaseTask;
 import com.ym.mec.task.core.TaskException;
 
+/**
+ * 手动查询订单支付状态
+ */
 @Service
 public class TestTask extends BaseTask {
+	
+	@Autowired
+	private SysUserFeignService sysUserFeignService;
 
 	@Override
 	public void execute() throws TaskException {
 		System.out.println("**************** Test  Task ****************");
+		sysUserFeignService.test();
 	}
 
 }