mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 12:19:27 +08:00
⚡ 优化secure,增加skip-url配置
This commit is contained in:
parent
c9f1774fc7
commit
1e30d8b839
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)));
|
||||
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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<ClientSecure> client = new ArrayList<>();
|
||||
|
||||
}
|
@ -27,9 +27,11 @@ import java.util.List;
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties("blade.secure.url")
|
||||
@ConfigurationProperties("blade.secure")
|
||||
public class BladeSecureProperties {
|
||||
|
||||
private final List<String> excludePatterns = new ArrayList<>();
|
||||
private final List<ClientSecure> client = new ArrayList<>();
|
||||
|
||||
private final List<String> skipUrl = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user