-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
22 changed files
with
213 additions
and
350 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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
#基础镜像 | ||
# 基础镜像 | ||
FROM bubaiwantong/openjdk:21-jdk-alpine | ||
|
||
#安装字体 | ||
# 安装字体 | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add --update ttf-dejavu fontconfig && rm -rf /var/cache/apk/* && mkfontscale && mkfontdir && fc-cache | ||
RUN apk add --update ttf-dejavu fontconfig && rm -rf /var/cache/apk/* | ||
|
||
#添加文件 | ||
# 添加文件 | ||
ADD education-back/target/back-0.0.1-SNAPSHOT.jar /usr/local | ||
RUN chmod u+x /usr/local/back-0.0.1-SNAPSHOT.jar | ||
|
||
#设置时区 | ||
# 设置时区 | ||
RUN rm -f /etc/localtime \ | ||
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ | ||
&& echo "Asia/Shanghai" > /etc/timezone | ||
|
||
#挂载目录到容器 | ||
#VOLUME ["/data"] | ||
#环境变量设置 | ||
#ENV #开放端口 | ||
# 挂载目录到容器 | ||
# VOLUME ["/data"] | ||
# 环境变量设置 | ||
# ENV #开放端口 | ||
EXPOSE 8088 | ||
#启动时执行的命令 | ||
# 启动时执行的命令 | ||
CMD ["/bin/bash"] | ||
#启动时执行的命令 | ||
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-jar","/usr/local/back-0.0.1-SNAPSHOT.jar"] | ||
# 启动时执行的命令 | ||
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-jar","/usr/local/back-0.0.1-SNAPSHOT.jar"] |
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
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
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
domain/src/main/java/com/javagpt/dict/repository/AccountReactiveMongoRepository.java
This file was deleted.
Oops, something went wrong.
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
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
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
30 changes: 0 additions & 30 deletions
30
education-back/src/main/java/com/javagpt/back/config/InitDatabase.java
This file was deleted.
Oops, something went wrong.
154 changes: 75 additions & 79 deletions
154
...ck/src/main/java/com/javagpt/back/config/springsecurity/JwtAuthenticationTokenFilter.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 |
---|---|---|
@@ -1,79 +1,75 @@ | ||
//package com.javagpt.back.config.springsecurity; | ||
// | ||
//import cn.hutool.jwt.JWTUtil; | ||
//import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||
//import com.fasterxml.jackson.databind.ObjectMapper; | ||
//import com.javagpt.common.resp.ResultBody; | ||
//import com.javagpt.common.constant.ResultStatus; | ||
//import io.jsonwebtoken.*; | ||
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
//import org.springframework.security.core.context.SecurityContextHolder; | ||
//import org.springframework.stereotype.Component; | ||
//import org.springframework.web.filter.OncePerRequestFilter; | ||
// | ||
//import jakarta.servlet.FilterChain; | ||
//import jakarta.servlet.ServletException; | ||
//import jakarta.servlet.http.HttpServletRequest; | ||
//import jakarta.servlet.http.HttpServletResponse; | ||
//import java.io.IOException; | ||
//import java.io.PrintWriter; | ||
// | ||
//@Component | ||
//public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | ||
// | ||
// | ||
// @Override | ||
// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
// //获取token | ||
// String token = request.getHeader(EPConstant.TOKEN); | ||
// System.out.println(token); | ||
// if (!StringUtils.isBlank(token)) { | ||
// try { | ||
// JwtParser parser = Jwts.parser(); | ||
// // 解析token的SigningKey必须和生成token时设置密码一致 | ||
// parser.setSigningKey("JavaGPT"); | ||
// /** | ||
// * 如果token检验通过(密码正确,有效期内)则正常执行,否则抛出异常 | ||
// * 前端浏览器携带的 token 可能是上次登陆时存储下来的,因此需要捕获到异常,并抛出 | ||
// */ | ||
// Jws<Claims> claimsJws = parser.parseClaimsJws(token); | ||
// Integer userId = (Integer) claimsJws.getBody().get("userId"); | ||
// if (userId == null) { | ||
// filterChain.doFilter(request, response); | ||
// } | ||
// UsernamePasswordAuthenticationToken authenticationToken = | ||
// new UsernamePasswordAuthenticationToken(userId,null,null); | ||
// SecurityContextHolder.getContext().setAuthentication(authenticationToken); | ||
// } catch (ExpiredJwtException e) { | ||
// ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_OVERDUE, "登录过期,请重新登录!", null); | ||
// doResponse(response, resultVO); | ||
// } catch (UnsupportedJwtException e) { | ||
// ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_NOT, "Token不合法,请自重!", null); | ||
// doResponse(response, resultVO); | ||
// } catch (Exception e) { | ||
// ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_NOT, "请先登录!", null); | ||
// doResponse(response, resultVO); | ||
// } | ||
// | ||
// } | ||
// //放行 | ||
// filterChain.doFilter(request, response); | ||
// } | ||
// | ||
// /** | ||
// * 没带token或者检验失败响应给前端 | ||
// * | ||
// * @param response | ||
// * @param resultVO | ||
// * @throws IOException | ||
// */ | ||
// private void doResponse(HttpServletResponse response, ResultBody resultVO) throws IOException { | ||
// response.setContentType("application/json"); | ||
// response.setCharacterEncoding("utf-8"); | ||
// PrintWriter out = response.getWriter(); | ||
// String s = new ObjectMapper().writeValueAsString(resultVO); | ||
// out.print(s); | ||
// out.flush(); | ||
// out.close(); | ||
// } | ||
//} | ||
package com.javagpt.back.config.springsecurity; | ||
|
||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.javagpt.common.constant.EPConstant; | ||
import com.javagpt.common.resp.ResultBody; | ||
import com.javagpt.common.constant.ResultStatus; | ||
import groovy.util.logging.Slf4j; | ||
import io.jsonwebtoken.*; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
@Component | ||
@Slf4j | ||
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
//获取token | ||
String token = request.getHeader(EPConstant.TOKEN); | ||
if (!StringUtils.isBlank(token)) { | ||
try { | ||
JwtParser parser = Jwts.parser(); | ||
// 解析token的SigningKey必须和生成token时设置密码一致 | ||
parser.setSigningKey("JavaGPT"); | ||
/** | ||
* 如果token检验通过(密码正确,有效期内)则正常执行,否则抛出异常 | ||
* 前端浏览器携带的 token 可能是上次登陆时存储下来的,因此需要捕获到异常,并抛出 | ||
*/ | ||
Jws<Claims> claimsJws = parser.parseClaimsJws(token); | ||
Integer userId = (Integer) claimsJws.getBody().get("userId"); | ||
if (userId == null) { | ||
filterChain.doFilter(request, response); | ||
} | ||
UsernamePasswordAuthenticationToken authenticationToken = | ||
new UsernamePasswordAuthenticationToken(userId,null,null); | ||
SecurityContextHolder.getContext().setAuthentication(authenticationToken); | ||
} catch (ExpiredJwtException e) { | ||
ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_OVERDUE, "登录过期,请重新登录!", null); | ||
doResponse(response, resultVO); | ||
} catch (UnsupportedJwtException e) { | ||
ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_NOT, "Token不合法,请自重!", null); | ||
doResponse(response, resultVO); | ||
} catch (Exception e) { | ||
ResultBody resultVO = new ResultBody(ResultStatus.LOGIN_FAIL_NOT, "请先登录!", null); | ||
doResponse(response, resultVO); | ||
} | ||
|
||
} | ||
//放行 | ||
filterChain.doFilter(request, response); | ||
} | ||
|
||
/** | ||
* 没带token或者检验失败响应给前端 | ||
*/ | ||
private void doResponse(HttpServletResponse response, ResultBody resultVO) throws IOException { | ||
response.setContentType("application/json"); | ||
response.setCharacterEncoding("utf-8"); | ||
PrintWriter out = response.getWriter(); | ||
String s = new ObjectMapper().writeValueAsString(resultVO); | ||
out.print(s); | ||
out.flush(); | ||
out.close(); | ||
} | ||
} |
Oops, something went wrong.