-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuyudong
committed
May 6, 2023
1 parent
489a426
commit 213c3f7
Showing
226 changed files
with
11,891 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
### Java template | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
SpringBoot-Labs.ipr | ||
SpringBoot-Labs.iws | ||
target/** | ||
*.lst | ||
*.iml | ||
*ipr | ||
*.iws | ||
|
||
### IntelliJ IDEA | ||
.idea | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>keen-parent</artifactId> | ||
<groupId>com.simple</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>keen-auth</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.simple</groupId> | ||
<artifactId>keen-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.simple</groupId> | ||
<artifactId>keen-system</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.simple</groupId> | ||
<artifactId>keen-message</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.simple</groupId> | ||
<artifactId>keen-monitor</artifactId> | ||
</dependency> | ||
<!-- Sa-Token 整合 jwt --> | ||
<dependency> | ||
<groupId>cn.dev33</groupId> | ||
<artifactId>sa-token-jwt</artifactId> | ||
</dependency> | ||
<!-- <dependency>--> | ||
<!-- <groupId>cn.dev33</groupId>--> | ||
<!-- <artifactId>sa-token-dao-redis</artifactId>--> | ||
<!-- </dependency>--> | ||
<!-- <!– 提供Redis连接池 –>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.apache.commons</groupId>--> | ||
<!-- <artifactId>commons-pool2</artifactId>--> | ||
<!-- </dependency>--> | ||
</dependencies> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
keen-auth/src/main/java/com/simple/keen/auth/config/SaTokenConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.simple.keen.auth.config; | ||
|
||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple; | ||
import cn.dev33.satoken.stp.StpLogic; | ||
import cn.dev33.satoken.stp.StpUtil; | ||
import com.simple.keen.auth.interceptor.PermissionVerifyInterceptor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
/** | ||
* . | ||
* | ||
* @author SinceNovember | ||
* @date 2023/1/31 | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
public class SaTokenConfig implements WebMvcConfigurer { | ||
|
||
@Bean | ||
public StpLogic getStpLogicJwt() { | ||
return new StpLogicJwtForSimple(); | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。 | ||
registry.addInterceptor(new PermissionVerifyInterceptor(handle -> StpUtil.checkLogin())) | ||
.addPathPatterns("/**") | ||
.excludePathPatterns("/api/auth/login"); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
keen-auth/src/main/java/com/simple/keen/auth/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.simple.keen.auth.controller; | ||
|
||
import com.simple.keen.auth.model.query.AuthQuery; | ||
import com.simple.keen.auth.service.IAuthService; | ||
import com.simple.keen.common.base.Response; | ||
import com.simple.keen.monitor.model.query.LoginLogQuery; | ||
import com.simple.keen.monitor.model.query.OperateLogQuery; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* . | ||
* | ||
* @author SinceNovember | ||
* @date 2023/1/18 | ||
*/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/auth") | ||
public class AuthController { | ||
|
||
private final IAuthService authService; | ||
|
||
@GetMapping("userInfo") | ||
public Response getUserInfo() { | ||
return Response.ok(authService.getLoginUserInfo()); | ||
} | ||
|
||
@GetMapping("/loginLog") | ||
public Response pageUserLoginLog(LoginLogQuery loginLogQuery) { | ||
return Response.ok(authService.pageUserLoginLog(loginLogQuery)); | ||
} | ||
|
||
@GetMapping("/operateLog") | ||
public Response pageUserOperateLog(OperateLogQuery operateLogQuery) { | ||
return Response.ok(authService.pageUserOperateLog(operateLogQuery)); | ||
} | ||
|
||
@PostMapping("login") | ||
public Response login(@RequestBody AuthQuery query) { | ||
return Response.ok(authService.login(query)); | ||
} | ||
|
||
@PostMapping("logout") | ||
public Response logout(@RequestBody AuthQuery query) { | ||
authService.logout(query.getTokenValue()); | ||
return Response.ok(); | ||
} | ||
|
||
@PutMapping("username") | ||
public Response updateUsername(@RequestBody AuthQuery query) { | ||
authService.updateUsername(query); | ||
return Response.ok(); | ||
} | ||
|
||
@PutMapping("password") | ||
public Response updatePassword(@RequestBody AuthQuery query) { | ||
authService.updatePassword(query); | ||
return Response.ok(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
keen-auth/src/main/java/com/simple/keen/auth/interceptor/PermissionVerifyInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.simple.keen.auth.interceptor; | ||
|
||
import cn.dev33.satoken.error.SaErrorCode; | ||
import cn.dev33.satoken.exception.SaTokenException; | ||
import cn.dev33.satoken.fun.SaParamFunction; | ||
import cn.dev33.satoken.interceptor.SaInterceptor; | ||
import cn.hutool.extra.spring.SpringUtil; | ||
import com.simple.keen.common.consts.MsgConsts; | ||
import com.simple.keen.system.model.enums.RequestMethod; | ||
import com.simple.keen.system.service.IUserService; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* 权限验证拦截器 | ||
* | ||
* @author SinceNovember | ||
* @date 2023/2/3 | ||
*/ | ||
public class PermissionVerifyInterceptor extends SaInterceptor { | ||
|
||
private final IUserService userService; | ||
|
||
public PermissionVerifyInterceptor(SaParamFunction<Object> auth) { | ||
super(auth); | ||
userService = SpringUtil.getBean(IUserService.class); | ||
} | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, | ||
Object handler) throws Exception { | ||
//登录认证通过 | ||
if (super.preHandle(request, response, handler)) { | ||
//检查当前用户是否可以访问当前路径 | ||
boolean hasApiPermission = userService.checkCurrentUserApiPermission( | ||
request.getRequestURI(), | ||
RequestMethod.valueOf(request.getMethod())); | ||
if (!hasApiPermission) { | ||
throw new SaTokenException(SaErrorCode.CODE_11051, | ||
MsgConsts.USER_NO_API_PERMISSION); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
keen-auth/src/main/java/com/simple/keen/auth/mapper/AuthMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.simple.keen.auth.mapper; | ||
|
||
import com.simple.keen.auth.model.query.AuthQuery; | ||
import com.simple.keen.system.model.vo.UserVO; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
@Mapper | ||
public interface AuthMapper { | ||
|
||
@Select("select * from t_user where deleted != 1 " + | ||
"and username =#{username} and password =#{password} ") | ||
UserVO selectUserIdByUsernameAndPassword(AuthQuery query); | ||
} |
26 changes: 26 additions & 0 deletions
26
keen-auth/src/main/java/com/simple/keen/auth/model/query/AuthQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.simple.keen.auth.model.query; | ||
|
||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
/** | ||
* . | ||
* | ||
* @author SinceNovember | ||
* @date 2023/1/18 | ||
*/ | ||
@Data | ||
@ToString | ||
public class AuthQuery { | ||
|
||
private String username; | ||
|
||
private String password; | ||
|
||
private String newPassword; | ||
|
||
private boolean rememberMe; | ||
|
||
private String tokenValue; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
keen-auth/src/main/java/com/simple/keen/auth/model/vo/LoginUserInfoVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.simple.keen.auth.model.vo; | ||
|
||
import com.simple.keen.system.model.vo.UserInfoVO; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
/** | ||
* . | ||
* | ||
* @author SinceNovember | ||
* @date 2023/3/30 | ||
*/ | ||
@Data | ||
@ToString | ||
public class LoginUserInfoVO extends UserInfoVO { | ||
|
||
private long unreadMessageCount; | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
keen-auth/src/main/java/com/simple/keen/auth/service/IAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.simple.keen.auth.service; | ||
|
||
import cn.dev33.satoken.stp.SaTokenInfo; | ||
import com.github.pagehelper.PageSerializable; | ||
import com.simple.keen.auth.model.query.AuthQuery; | ||
import com.simple.keen.auth.model.vo.LoginUserInfoVO; | ||
import com.simple.keen.monitor.model.query.LoginLogQuery; | ||
import com.simple.keen.monitor.model.query.OperateLogQuery; | ||
import com.simple.keen.monitor.model.vo.LoginLogVO; | ||
|
||
public interface IAuthService { | ||
|
||
/** | ||
* 获取登录用户信息 | ||
* | ||
* @return 用户信息VO | ||
*/ | ||
LoginUserInfoVO getLoginUserInfo(); | ||
|
||
/** | ||
* 当前用户的登录日志 | ||
* | ||
* @param loginLogQuery 登录日志查询 | ||
*/ | ||
PageSerializable<LoginLogVO> pageUserLoginLog(LoginLogQuery loginLogQuery); | ||
|
||
/** | ||
* 当前用户的操作日志 | ||
* | ||
* @param operateLogQuery 操作日志查询 | ||
*/ | ||
Object pageUserOperateLog(OperateLogQuery operateLogQuery); | ||
|
||
|
||
/** | ||
* 登录 | ||
* | ||
* @param query 查询 | ||
* @return | ||
*/ | ||
SaTokenInfo login(AuthQuery query); | ||
|
||
/** | ||
* 注销 | ||
* | ||
* @param token 令牌 | ||
* @return | ||
*/ | ||
void logout(String token); | ||
|
||
/** | ||
* 修改用户名 | ||
* | ||
* @param authQuery 身份验证查询 | ||
*/ | ||
void updateUsername(AuthQuery authQuery); | ||
|
||
/** | ||
* 修改密码 | ||
* | ||
* @param authQuery 身份验证查询 | ||
*/ | ||
void updatePassword(AuthQuery authQuery); | ||
|
||
} |
Oops, something went wrong.