From c24697fd1b73f11f7d0cb4e1cfc9eacb86c9f865 Mon Sep 17 00:00:00 2001
From: sin <2943460818@qq.com>
Date: Wed, 10 Apr 2019 20:48:35 +0800
Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8B=A6=E6=88=AA=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
order/order-application/pom.xml | 5 +++
.../application/config/MVCConfiguration.java | 33 ++++++++++++++++++-
.../src/main/resources/application.yaml | 2 +-
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/order/order-application/pom.xml b/order/order-application/pom.xml
index 1c07a316c..2f5f25b5c 100644
--- a/order/order-application/pom.xml
+++ b/order/order-application/pom.xml
@@ -27,6 +27,11 @@
admin-sdk
1.0-SNAPSHOT
+
+ cn.iocoder.mall
+ user-sdk
+ 1.0-SNAPSHOT
+
cn.iocoder.mall
common-framework
diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/config/MVCConfiguration.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/config/MVCConfiguration.java
index ff78f0adb..c7c372217 100644
--- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/config/MVCConfiguration.java
+++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/config/MVCConfiguration.java
@@ -1,10 +1,22 @@
package cn.iocoder.mall.order.application.config;
+import cn.iocoder.common.framework.config.GlobalExceptionHandler;
+import cn.iocoder.common.framework.servlet.CorsFilter;
+import cn.iocoder.mall.admin.sdk.interceptor.AdminSecurityInterceptor;
+import cn.iocoder.mall.user.sdk.interceptor.UserAccessLogInterceptor;
+import cn.iocoder.mall.user.sdk.interceptor.UserSecurityInterceptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.*;
@EnableWebMvc
@Configuration
+@Import(value = {GlobalExceptionHandler.class, // 统一全局返回
+ UserSecurityInterceptor.class, AdminSecurityInterceptor.class,
+ UserAccessLogInterceptor.class}) // 安全拦截器,实现认证和授权功能。
public class MVCConfiguration implements WebMvcConfigurer {
// @Autowired
@@ -13,9 +25,28 @@ public class MVCConfiguration implements WebMvcConfigurer {
// @Reference
// private OAuth2Service oauth2Service;
+ @Autowired
+ private UserSecurityInterceptor userSecurityInterceptor;
+ @Autowired
+ private UserAccessLogInterceptor userAccessLogInterceptor;
+ @Autowired
+ private AdminSecurityInterceptor adminSecurityInterceptor;
+
@Override
public void addInterceptors(InterceptorRegistry registry) {
-// registry.addInterceptor(securityInterceptor);
+ // 用户
+ registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
+ registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
+ // 管理员
+ registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**"); // 只拦截我们定义的接口
+ }
+
+ @Bean
+ public FilterRegistrationBean corsFilter() {
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
+ registrationBean.setFilter(new CorsFilter());
+ registrationBean.addUrlPatterns("/*");
+ return registrationBean;
}
// @Override
diff --git a/order/order-application/src/main/resources/application.yaml b/order/order-application/src/main/resources/application.yaml
index 54e9eb09b..1180b36f3 100644
--- a/order/order-application/src/main/resources/application.yaml
+++ b/order/order-application/src/main/resources/application.yaml
@@ -4,6 +4,6 @@ spring:
# server
server:
- port: 18084
+ port: 18088
servlet:
context-path: /order-api/