patch: 注释内容修改,代码规范化
This commit is contained in:
parent
34c6ea1a8b
commit
78da5c90c4
|
@ -4,9 +4,22 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主类
|
||||||
|
*
|
||||||
|
* @since v1.0.0-SNAPSHOT
|
||||||
|
* @version 1.0.0-SNAPSHOT
|
||||||
|
* @author xiao_lfeng
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class JslOrganizeInternalOaApplication {
|
public class JslOrganizeInternalOaApplication {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入口
|
||||||
|
*
|
||||||
|
* @param args 参数
|
||||||
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(JslOrganizeInternalOaApplication.class, args);
|
SpringApplication.run(JslOrganizeInternalOaApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.sql.Timestamp;
|
||||||
* @see org.springframework.boot.SpringApplication
|
* @see org.springframework.boot.SpringApplication
|
||||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
|
* @author xiaofeng
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -28,6 +29,12 @@ public class JslOrganizeInternalOaRunnerApplication implements SmartInitializing
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
private final InfoMapper infoMapper;
|
private final InfoMapper infoMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>获取安全密钥</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 从数据库中获取安全密钥
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void afterSingletonsInstantiated() {
|
public void afterSingletonsInstantiated() {
|
||||||
// 获取数据库中的 SecurityKey
|
// 获取数据库中的 SecurityKey
|
||||||
|
|
|
@ -7,9 +7,9 @@ import lombok.Getter;
|
||||||
* <hr/>
|
* <hr/>
|
||||||
* 业务常量
|
* 业务常量
|
||||||
*
|
*
|
||||||
* @since v1.1.0
|
|
||||||
* @version v1.1.0
|
|
||||||
* @author xiao_lfeng
|
* @author xiao_lfeng
|
||||||
|
* @version v1.1.0
|
||||||
|
* @since v1.1.0
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public enum BusinessConstants {
|
public enum BusinessConstants {
|
||||||
|
@ -21,6 +21,12 @@ public enum BusinessConstants {
|
||||||
private final String value;
|
private final String value;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个具有指定值和描述的实例 {@code BusinessConstants}。
|
||||||
|
*
|
||||||
|
* @param value 常量的value
|
||||||
|
* @param description 常量的描述
|
||||||
|
*/
|
||||||
BusinessConstants(String value, String description) {
|
BusinessConstants(String value, String description) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
|
@ -27,12 +27,21 @@ public class MailConfiguration {
|
||||||
@Value("${spring.mail.password}")
|
@Value("${spring.mail.password}")
|
||||||
private String emailPassword;
|
private String emailPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置并返回一个用于发送邮件的JavaMailSender实例。
|
||||||
|
* <p>
|
||||||
|
* 此方法使用SMTP协议设置邮件发送器,启用SMTP认证和STARTTLS。同时,为了便于故障排除,
|
||||||
|
* 开启了邮件调试功能,以记录邮件发送过程。配置细节如主机、端口、用户名和密码根据应用程序的属性进行设置。
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return 配置好的JavaMailSender实例,可用于发送邮件。
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public JavaMailSender javaMailSender() {
|
public JavaMailSender javaMailSender() {
|
||||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||||
mailSender.setDefaultEncoding("UTF-8");
|
mailSender.setDefaultEncoding("UTF-8");
|
||||||
mailSender.setHost(emailHost);
|
mailSender.setHost(emailHost);
|
||||||
mailSender.setPort(25); // 你的邮件服务器端口
|
mailSender.setPort(25);
|
||||||
mailSender.setUsername(emailUsername);
|
mailSender.setUsername(emailUsername);
|
||||||
mailSender.setPassword(emailPassword);
|
mailSender.setPassword(emailPassword);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import javax.servlet.*;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>CORS过滤器</h1>
|
* <h1>CORS过滤器</h1>
|
||||||
* <hr/>
|
* <hr/>
|
||||||
|
@ -21,6 +22,14 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class CorsFilter implements Filter {
|
public class CorsFilter implements Filter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于处理跨域请求
|
||||||
|
*
|
||||||
|
* @param req servlet请求
|
||||||
|
* @param res servlet响应
|
||||||
|
* @param chain 过滤器链
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(@NotNull ServletRequest req, ServletResponse res, FilterChain chain) {
|
public void doFilter(@NotNull ServletRequest req, ServletResponse res, FilterChain chain) {
|
||||||
// 请求头处理
|
// 请求头处理
|
||||||
|
@ -36,15 +45,27 @@ public class CorsFilter implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*
|
||||||
|
* @param filterConfig 过滤器配置
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init(FilterConfig filterConfig) {
|
public void init(FilterConfig filterConfig) {}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 销毁
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
Filter.super.destroy();
|
Filter.super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置请求头
|
||||||
|
*
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
protected static void setHeader(@NotNull HttpServletResponse response) {
|
protected static void setHeader(@NotNull HttpServletResponse response) {
|
||||||
// 允许跨域请求
|
// 允许跨域请求
|
||||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
|
|
@ -29,6 +29,11 @@ public class RedisConfiguration {
|
||||||
@Value("${spring.redis.password}")
|
@Value("${spring.redis.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>JedisConnectionFactory</h2>
|
||||||
|
* <hr/>
|
||||||
|
* 用于连接Redis
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public JedisConnectionFactory jedisConnectionFactory() {
|
public JedisConnectionFactory jedisConnectionFactory() {
|
||||||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
|
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
|
||||||
|
@ -36,6 +41,11 @@ public class RedisConfiguration {
|
||||||
return new JedisConnectionFactory(config);
|
return new JedisConnectionFactory(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>RedisTemplate</h2>
|
||||||
|
* <hr/>
|
||||||
|
* 用于配置RedisTemplate
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
|
|
|
@ -1,35 +1,53 @@
|
||||||
package com.jsl.oa.config.shiro;
|
package com.jsl.oa.config.shiro;
|
||||||
|
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
|
||||||
import org.apache.shiro.authc.AuthenticationInfo;
|
import org.apache.shiro.authc.AuthenticationInfo;
|
||||||
import org.apache.shiro.authc.AuthenticationToken;
|
import org.apache.shiro.authc.AuthenticationToken;
|
||||||
import org.apache.shiro.authz.AuthorizationInfo;
|
import org.apache.shiro.authz.AuthorizationInfo;
|
||||||
import org.apache.shiro.realm.AuthorizingRealm;
|
import org.apache.shiro.realm.AuthorizingRealm;
|
||||||
import org.apache.shiro.subject.PrincipalCollection;
|
import org.apache.shiro.subject.PrincipalCollection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这是一个Shiro的Realm,它负责身份验证和授权。
|
||||||
|
* 它扩展了AuthorizingRealm类,该类提供了默认的授权和身份验证实现。
|
||||||
|
* <p>
|
||||||
|
* doGetAuthenticationInfo()方法负责验证用户,
|
||||||
|
* doGetAuthorizationInfo()方法负责检索用户的授权信息。
|
||||||
|
*
|
||||||
|
* @author jsl
|
||||||
|
*/
|
||||||
public class MyRealm extends AuthorizingRealm {
|
public class MyRealm extends AuthorizingRealm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 授权
|
* 这将负责验证用户。
|
||||||
|
* 它接受一个AuthenticationToken作为参数,该参数表示用户的<EFBFBD><EFBFBD>据,
|
||||||
|
* 并返回一个AuthenticationInfo对象,该对象包含用户的身份验证详细信息。
|
||||||
|
* <p>
|
||||||
|
* 在这种实现中,该方法总是返回null,表示身份验证不受支持。
|
||||||
|
* 这可以在子类中被重写以支持身份验证。
|
||||||
*
|
*
|
||||||
* @return 授权信息
|
* @param authenticationToken 用户的<EFBFBD><EFBFBD>据
|
||||||
*/
|
* @return null,表示身份验证不受支持
|
||||||
@Override
|
|
||||||
protected AuthorizationInfo doGetAuthorizationInfo(@NotNull PrincipalCollection principals) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 认证
|
|
||||||
*
|
|
||||||
* @param authenticationToken 令牌
|
|
||||||
* @return 认证信息
|
|
||||||
* @throws AuthenticationException 认证异常
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这将负责检索用户的授权信息。
|
||||||
|
* 它接受一个PrincipalCollection作为参数,该参数表示用户的主体,
|
||||||
|
* 并返回一个AuthorizationInfo对象,该对象包含用户的授权详细信息。
|
||||||
|
* <p>
|
||||||
|
* 在这种实现中,该方法总是返回null,表示授权不受支持。
|
||||||
|
* 这可以在子类中被重写以支持授权。
|
||||||
|
*
|
||||||
|
* @param principals 用户的主体
|
||||||
|
* @return null,表示授权不受支持
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.jsl.oa.config.shiro;
|
||||||
|
|
||||||
import com.jsl.oa.config.filter.CorsFilter;
|
import com.jsl.oa.config.filter.CorsFilter;
|
||||||
import com.jsl.oa.config.filter.JwtFilter;
|
import com.jsl.oa.config.filter.JwtFilter;
|
||||||
import com.jsl.oa.services.UserService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||||
|
@ -14,12 +13,25 @@ import javax.servlet.Filter;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这是一个Shiro的Realm,它负责身份验证和授权。
|
||||||
|
* 它扩展了AuthorizingRealm类,该类提供了默认的授权和身份验证实现。
|
||||||
|
*
|
||||||
|
* @since v1.0.0-SNAPSHOT
|
||||||
|
* @version v1.0.0-SNAPSHOT
|
||||||
|
* @author xiao_lfeng
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ShiroConfiguration {
|
public class ShiroConfiguration {
|
||||||
|
|
||||||
private final UserService userService;
|
/**
|
||||||
|
* 配置Shiro过滤器工厂Bean,设置安全管理器、过滤器规则以及自定义过滤器。
|
||||||
|
* 此方法用于配置Shiro的安全管理器,定义URL模式的过滤器链,并添加自定义的JWT和CORS过滤器来处理认证和跨域请求。
|
||||||
|
*
|
||||||
|
* @param securityManager 安全管理器,由Shiro过滤器工厂Bean使用。
|
||||||
|
* @return 配置好的ShiroFilterFactoryBean实例。
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
|
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
|
||||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||||
|
@ -27,10 +39,9 @@ public class ShiroConfiguration {
|
||||||
|
|
||||||
// 配置过滤器规则
|
// 配置过滤器规则
|
||||||
Map<String, String> filterChainDefinitionMap = setFilterChain();
|
Map<String, String> filterChainDefinitionMap = setFilterChain();
|
||||||
|
|
||||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||||
|
|
||||||
// 设置未登陆响应接口
|
// 设置未登录响应接口
|
||||||
shiroFilterFactoryBean.setUnauthorizedUrl("/unauthorized");
|
shiroFilterFactoryBean.setUnauthorizedUrl("/unauthorized");
|
||||||
|
|
||||||
// 添加JWT过滤器
|
// 添加JWT过滤器
|
||||||
|
@ -41,6 +52,13 @@ public class ShiroConfiguration {
|
||||||
return shiroFilterFactoryBean;
|
return shiroFilterFactoryBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建并配置安全管理器,使用自定义领域。
|
||||||
|
* 此方法设置安全管理器使用自定义领域进行认证和授权。
|
||||||
|
*
|
||||||
|
* @param realm 自定义领域,由安全管理器使用。
|
||||||
|
* @return 配置好的DefaultWebSecurityManager实例。
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DefaultWebSecurityManager securityManager(MyRealm realm) {
|
public DefaultWebSecurityManager securityManager(MyRealm realm) {
|
||||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||||
|
@ -48,28 +66,39 @@ public class ShiroConfiguration {
|
||||||
return securityManager;
|
return securityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用于认证和授权的自定义领域实例。
|
||||||
|
* 此方法为应用提供一个包含用户认证和授权逻辑的自定义领域。
|
||||||
|
*
|
||||||
|
* @return MyRealm的一个实例。
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MyRealm myRealm() {
|
public MyRealm myRealm() {
|
||||||
return new MyRealm();
|
return new MyRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义URL模式和相应过滤器的过滤器链。
|
||||||
|
* 此静态方法将URL模式映射到过滤器名称,指定哪些URL可以匿名访问,哪些需要认证。它允许对应用程序不同部分的访问进行细粒度控制。
|
||||||
|
*
|
||||||
|
* @return URL模式到过滤器名称的映射。
|
||||||
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Map<String, String> setFilterChain() {
|
private static Map<String, String> setFilterChain() {
|
||||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||||
filterChainDefinitionMap.put("/auth/**/**", "anon"); // 登录接口允许匿名访问
|
filterChainDefinitionMap.put("/auth/**/**", "anon");
|
||||||
filterChainDefinitionMap.put("/unauthorized", "anon"); // 未授权接口允许匿名访问
|
filterChainDefinitionMap.put("/unauthorized", "anon");
|
||||||
filterChainDefinitionMap.put("/", "anon"); // 首页允许匿名访问
|
filterChainDefinitionMap.put("/", "anon");
|
||||||
filterChainDefinitionMap.put("/info/header-image/get", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/info/header-image/get", "anon");
|
||||||
filterChainDefinitionMap.put("/info/header-user/get", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/info/header-user/get", "anon");
|
||||||
filterChainDefinitionMap.put("/project/header/get", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/project/header/get", "anon");
|
||||||
filterChainDefinitionMap.put("/project/get", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/project/get", "anon");
|
||||||
filterChainDefinitionMap.put("/project/get/custom", "anon"); // 游客获取项目允许匿名访问
|
filterChainDefinitionMap.put("/project/get/custom", "anon");
|
||||||
filterChainDefinitionMap.put("/project/add", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/project/add", "anon");
|
||||||
filterChainDefinitionMap.put("/project/work/add", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/project/work/add", "anon");
|
||||||
filterChainDefinitionMap.put("/tags/project/list", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/tags/project/list", "anon");
|
||||||
filterChainDefinitionMap.put("/module/add", "anon"); // 信息接口允许匿名访问
|
filterChainDefinitionMap.put("/module/add", "anon");
|
||||||
filterChainDefinitionMap.put("/**/**", "authc"); // 其他接口一律拦截(需要Token)
|
filterChainDefinitionMap.put("/**/**", "authc");
|
||||||
|
|
||||||
|
|
||||||
return filterChainDefinitionMap;
|
return filterChainDefinitionMap;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user