From 1e30d8b839768587bac1a70e4011b8c6999b0295 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 17 Apr 2020 21:46:45 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96secure=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0skip-url=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../secure/config/SecureConfiguration.java | 9 ++--- .../secure/interceptor/ClientInterceptor.java | 2 +- .../secure/interceptor/SecureInterceptor.java | 2 +- .../secure/props/BladeClientProperties.java | 35 ------------------- .../secure/props/BladeSecureProperties.java | 6 ++-- 5 files changed, 9 insertions(+), 45 deletions(-) delete mode 100644 blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeClientProperties.java diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java b/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java index f9e4ab6..a77de31 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java @@ -20,7 +20,6 @@ import lombok.AllArgsConstructor; import org.springblade.core.secure.aspect.AuthAspect; import org.springblade.core.secure.interceptor.ClientInterceptor; import org.springblade.core.secure.interceptor.SecureInterceptor; -import org.springblade.core.secure.props.BladeClientProperties; import org.springblade.core.secure.props.BladeSecureProperties; import org.springblade.core.secure.provider.ClientDetailsServiceImpl; import org.springblade.core.secure.provider.IClientDetailsService; @@ -42,26 +41,24 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Order @Configuration @AllArgsConstructor -@EnableConfigurationProperties({BladeSecureProperties.class, BladeClientProperties.class}) +@EnableConfigurationProperties({BladeSecureProperties.class}) public class SecureConfiguration implements WebMvcConfigurer { private final SecureRegistry secureRegistry; private final BladeSecureProperties secureProperties; - private final BladeClientProperties clientProperties; - private final JdbcTemplate jdbcTemplate; @Override public void addInterceptors(InterceptorRegistry registry) { - clientProperties.getClient().forEach(cs -> registry.addInterceptor(new ClientInterceptor(cs.getClientId())).addPathPatterns(cs.getPathPatterns())); + secureProperties.getClient().forEach(cs -> registry.addInterceptor(new ClientInterceptor(cs.getClientId())).addPathPatterns(cs.getPathPatterns())); if (secureRegistry.isEnabled()) { registry.addInterceptor(new SecureInterceptor()) .excludePathPatterns(secureRegistry.getExcludePatterns()) .excludePathPatterns(secureRegistry.getDefaultExcludePatterns()) - .excludePathPatterns(secureProperties.getExcludePatterns()); + .excludePathPatterns(secureProperties.getSkipUrl()); } } diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java index a39c925..5626bf1 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java @@ -52,7 +52,7 @@ public class ClientInterceptor extends HandlerInterceptorAdapter { } else { log.warn("客户端认证失败,请求接口:{},请求IP:{},请求参数:{}", request.getRequestURI(), WebUtil.getIP(request), JsonUtil.toJson(request.getParameterMap())); R result = R.fail(ResultCode.UN_AUTHORIZED); - response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_UTF8_VALUE); + response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding(BladeConstant.UTF_8); response.setStatus(HttpServletResponse.SC_OK); try { diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java index 37f0d9c..8588a13 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java @@ -48,7 +48,7 @@ public class SecureInterceptor extends HandlerInterceptorAdapter { log.warn("签名认证失败,请求接口:{},请求IP:{},请求参数:{}", request.getRequestURI(), WebUtil.getIP(request), JsonUtil.toJson(request.getParameterMap())); R result = R.fail(ResultCode.UN_AUTHORIZED); response.setCharacterEncoding(BladeConstant.UTF_8); - response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_UTF8_VALUE); + response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_VALUE); response.setStatus(HttpServletResponse.SC_OK); try { response.getWriter().write(Objects.requireNonNull(JsonUtil.toJson(result))); diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeClientProperties.java b/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeClientProperties.java deleted file mode 100644 index 668f92a..0000000 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeClientProperties.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springblade.core.secure.props; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.ArrayList; -import java.util.List; - -/** - * 客户端校验配置 - * - * @author Chill - */ -@Data -@ConfigurationProperties("blade.secure") -public class BladeClientProperties { - - private final List client = new ArrayList<>(); - -} diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeSecureProperties.java b/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeSecureProperties.java index 7ee3766..f76b994 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeSecureProperties.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/props/BladeSecureProperties.java @@ -27,9 +27,11 @@ import java.util.List; * @author Chill */ @Data -@ConfigurationProperties("blade.secure.url") +@ConfigurationProperties("blade.secure") public class BladeSecureProperties { - private final List excludePatterns = new ArrayList<>(); + private final List client = new ArrayList<>(); + + private final List skipUrl = new ArrayList<>(); }