提交 c6c838d7 authored 作者: YunaiV's avatar YunaiV

优化 user 认证 starter,支持忽略部分 url

上级 da826a21
...@@ -7,7 +7,7 @@ public class AdminSecurityProperties { ...@@ -7,7 +7,7 @@ public class AdminSecurityProperties {
private static final String[] DEFAULT_IGNORE_PATHS = new String[]{ private static final String[] DEFAULT_IGNORE_PATHS = new String[]{
// Swagger 相关 // Swagger 相关
"/doc.html", "/swagger-resources", "/swagger-resources/**", "/doc.html", "/swagger-resources", "/swagger-resources/**", "/webjars/**",
// Actuator 相关 // Actuator 相关
}; };
......
...@@ -5,7 +5,9 @@ import cn.iocoder.mall.web.config.CommonWebAutoConfiguration; ...@@ -5,7 +5,9 @@ import cn.iocoder.mall.web.config.CommonWebAutoConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
...@@ -14,10 +16,17 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; ...@@ -14,10 +16,17 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
@AutoConfigureAfter(CommonWebAutoConfiguration.class) // 在 CommonWebAutoConfiguration 之后自动配置,保证过滤器的顺序 @AutoConfigureAfter(CommonWebAutoConfiguration.class) // 在 CommonWebAutoConfiguration 之后自动配置,保证过滤器的顺序
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@EnableConfigurationProperties(UserSecurityProperties.class)
public class UserSecurityAutoConfiguration implements WebMvcConfigurer { public class UserSecurityAutoConfiguration implements WebMvcConfigurer {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
@Bean
@ConditionalOnMissingBean
public UserSecurityProperties userSecurityProperties() {
return new UserSecurityProperties();
}
// ========== 拦截器相关 ========== // ========== 拦截器相关 ==========
@Bean @Bean
...@@ -27,8 +36,11 @@ public class UserSecurityAutoConfiguration implements WebMvcConfigurer { ...@@ -27,8 +36,11 @@ public class UserSecurityAutoConfiguration implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
UserSecurityProperties properties = this.userSecurityProperties();
// UserSecurityInterceptor 拦截器 // UserSecurityInterceptor 拦截器
registry.addInterceptor(this.userSecurityInterceptor()); registry.addInterceptor(this.userSecurityInterceptor())
.excludePathPatterns(properties.getIgnorePaths())
.excludePathPatterns(properties.getDefaultIgnorePaths());;
logger.info("[addInterceptors][加载 UserSecurityInterceptor 拦截器完成]"); logger.info("[addInterceptors][加载 UserSecurityInterceptor 拦截器完成]");
} }
......
package cn.iocoder.mall.security.user.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("mall.security.user")
public class UserSecurityProperties {
private static final String[] DEFAULT_IGNORE_PATHS = new String[]{
// Swagger 相关
"/doc.html", "/swagger-resources", "/swagger-resources/**", "/webjars/**",
// Actuator 相关
};
/**
* 自定义忽略 Path
*/
private String[] ignorePaths = new String[0];
/**
* 默认忽略 Path
*/
private String[] defaultIgnorePaths = DEFAULT_IGNORE_PATHS;
public String[] getIgnorePaths() {
return ignorePaths;
}
public UserSecurityProperties setIgnorePaths(String[] ignorePaths) {
this.ignorePaths = ignorePaths;
return this;
}
public String[] getDefaultIgnorePaths() {
return defaultIgnorePaths;
}
public UserSecurityProperties setDefaultIgnorePaths(String[] defaultIgnorePaths) {
this.defaultIgnorePaths = defaultIgnorePaths;
return this;
}
}
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for product_spu
-- ----------------------------
CREATE TABLE `product_spu` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'SPU 编号',
`name` varchar(50) NOT NULL DEFAULT '' COMMENT 'SPU 名字',
`sell_point` varchar(50) NOT NULL DEFAULT '' COMMENT '卖点',
`description` text NOT NULL COMMENT '描述',
`cid` int(11) NOT NULL DEFAULT '-1' COMMENT '分类编号',
`pic_urls` varchar(1024) NOT NULL DEFAULT '' COMMENT '商品主图地址\n *\n * 数组,以逗号分隔\n *\n * 建议尺寸:800*800像素,你可以拖拽图片调整顺序,最多上传15张',
`visible` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否上架商品(是否可见)。\n *\n * true 为已上架\n * false 为已下架',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序字段',
`price` int(11) NOT NULL COMMENT '价格',
`quantity` int(11) NOT NULL COMMENT '库存数量',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8mb4 COMMENT='商品 SPU';
-- ----------------------------
-- Table structure for product_sku
-- ----------------------------
CREATE TABLE `product_sku` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'sku 编号',
`spu_id` int(11) NOT NULL DEFAULT '-1' COMMENT '商品编号',
`status` int(11) NOT NULL DEFAULT '-1' COMMENT '状态\n *\n * 1-正常\n * 2-禁用',
`pic_url` varchar(50) DEFAULT '' COMMENT '图片地址',
`attrs` varchar(50) NOT NULL DEFAULT '' COMMENT '规格值({@link ProductAttrDO})数组\n *\n * 数组,以逗号分隔',
`price` int(11) NOT NULL DEFAULT '-1' COMMENT '价格,单位:分',
`quantity` int(11) NOT NULL DEFAULT '-1' COMMENT '库存数量',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb4 COMMENT='商品 SKU';
-- ----------------------------
-- Table structure for product_attr_key
-- ----------------------------
CREATE TABLE `product_attr_key` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '规格键编号',
`name` varchar(50) NOT NULL DEFAULT '' COMMENT '规格键名称',
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态\n *\n * 1-开启\n * 2-禁用',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COMMENT='商品规格键';
-- ----------------------------
-- Table structure for product_attr_value
-- ----------------------------
CREATE TABLE `product_attr_value` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '规格值编号',
`attr_key_id` int(11) NOT NULL COMMENT '规格键编号',
`name` varchar(50) NOT NULL DEFAULT '' COMMENT '规格值名字',
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态\n *\n * 1-开启\n * 2-禁用',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8mb4 COMMENT='商品规格值';
-- ----------------------------
-- Table structure for product_category
-- ----------------------------
CREATE TABLE `product_category` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '分类编号',
`pid` int(11) NOT NULL COMMENT '父分类编号',
`name` varchar(16) NOT NULL COMMENT '分类名称',
`description` varchar(255) DEFAULT NULL COMMENT '分类描述',
`pic_url` varchar(255) DEFAULT NULL COMMENT '分类图片',
`sort` int(11) NOT NULL COMMENT '分类排序',
`status` tinyint(4) NOT NULL COMMENT '状态',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=801 DEFAULT CHARSET=utf8mb4 COMMENT='商品分类表';
-- ----------------------------
-- Table structure for product_brand
-- ----------------------------
CREATE TABLE `product_brand` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '品牌编号',
`name` varchar(50) NOT NULL COMMENT '品牌名称',
`description` varchar(255) DEFAULT NULL COMMENT '品牌描述',
`pic_url` varchar(1024) DEFAULT NULL COMMENT '品牌名图片',
`status` tinyint(4) NOT NULL COMMENT '状态 1开启 2禁用',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COMMENT='商品品牌';
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论