Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e9f2e4ac1 | ||
|
|
7d2b618d6b | ||
| e5babd4e85 | |||
| 74e93ff72f |
@@ -1,18 +0,0 @@
|
||||
package com.ag.secp.platform.jwt;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description: JWT中的信息
|
||||
* Author: songwp
|
||||
* Version: 1.0
|
||||
* Create Date: 2021/12/24
|
||||
*/
|
||||
@Data
|
||||
public class JWTInfo {
|
||||
private String alg;
|
||||
private String typ;
|
||||
private long expireTime;
|
||||
private String uid;
|
||||
private String name;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.ag.secp.platform.jwt;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.jwt.JWTException;
|
||||
import cn.hutool.jwt.JWTUtil;
|
||||
import cn.hutool.jwt.JWTValidator;
|
||||
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Description: JWT拦截类
|
||||
* Author: songwp
|
||||
* Version: 1.0
|
||||
* Create Date: 2021/12/24
|
||||
*/
|
||||
public class JWTInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//获取请求头里的令牌
|
||||
String token = request.getHeader(ResultCode.TOKEN_KEY);
|
||||
//ResultCode.TOKEN_KEY_HEADER_AUTHORIZATION
|
||||
//ResultCode.TOKEN_KEY_HEADER_AUTHORIZATION_BEARER
|
||||
boolean isSuccess;
|
||||
try {
|
||||
//验证签名
|
||||
isSuccess = JWTUtil.verify(token, JWTTokenForHS256.getTokenSecretByte());
|
||||
//验证算法
|
||||
JWTValidator.of(token).validateAlgorithm(JWTSignerUtil.hs256(JWTTokenForHS256.getTokenSecretByte()))
|
||||
.validateDate(DateUtil.date());
|
||||
}catch (ValidateException exception){
|
||||
isSuccess = false;
|
||||
}catch(JWTException e){
|
||||
isSuccess = false;
|
||||
}
|
||||
if(isSuccess){
|
||||
return true;
|
||||
}else {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().println(JSONUtil.parseObj(R.failedToken()));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.ag.secp.platform.jwt;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.jwt.*;
|
||||
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* Description: JWT HS256 对称加密
|
||||
* Author: songwp
|
||||
* Version: 1.0
|
||||
* Create Date: 2021/7/13
|
||||
*/
|
||||
public class JWTTokenForHS256 {
|
||||
|
||||
//token密钥
|
||||
private static final String TOKEN_SECRET = "SDFSFEGEIFNEWERETSDFSD";
|
||||
//间隔时间
|
||||
public static final long EXPIRE_DATE = 1000*1000;
|
||||
|
||||
public static byte[] getTokenSecretByte(){
|
||||
return TOKEN_SECRET.getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:生成token
|
||||
* @param payload
|
||||
* @param expireDate 过期间隔毫秒数
|
||||
* @return: java.lang.String
|
||||
* @Author songwp
|
||||
* Create Date 2021/12/24
|
||||
*/
|
||||
public static String createToken(Map<String,Object> payload,long expireDate) {
|
||||
|
||||
//设置头部信息
|
||||
Map<String,Object> header = new HashMap<>();
|
||||
header.put("typ","JWT");
|
||||
header.put("alg","HS256");
|
||||
//设置payload内容
|
||||
// //签发时间
|
||||
// payload.put(JWTPayload.ISSUED_AT, System.currentTimeMillis());
|
||||
// //生效时间
|
||||
// payload.put(JWTPayload.NOT_BEFORE, System.currentTimeMillis());
|
||||
//过期时间
|
||||
payload.put(JWTPayload.EXPIRES_AT, DateUtil.date(System.currentTimeMillis() + expireDate));
|
||||
return JWTUtil.createToken(header,payload,getTokenSecretByte());
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:验证token
|
||||
* @param token
|
||||
* @return: boolean
|
||||
* @Author songwp
|
||||
* Create Date 2021/12/24
|
||||
*/
|
||||
public static boolean verifyToken(String token) {
|
||||
boolean isSuccess;
|
||||
|
||||
try {
|
||||
//验证签名
|
||||
isSuccess = JWTUtil.verify(token, getTokenSecretByte());
|
||||
//验证算法
|
||||
JWTValidator.of(token).validateAlgorithm(JWTSignerUtil.hs256(getTokenSecretByte())).validateDate(DateUtil.date());
|
||||
}catch (ValidateException exception){
|
||||
isSuccess = false;
|
||||
}
|
||||
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:解释数据
|
||||
* @param token
|
||||
* @return: JWTInfo
|
||||
* @Author songwp
|
||||
* Create Date 2021/12/24
|
||||
*/
|
||||
public static JWTInfo parseToken(String token) {
|
||||
JWTInfo jwtInfo = new JWTInfo();
|
||||
final JWT jwt = JWTUtil.parseToken(token);
|
||||
jwtInfo.setTyp(jwt.getHeader(JWTHeader.TYPE).toString());
|
||||
jwtInfo.setAlg(jwt.getHeader(JWTHeader.ALGORITHM).toString());
|
||||
jwtInfo.setExpireTime(Long.parseLong(jwt.getPayload(JWTPayload.EXPIRES_AT).toString()));;
|
||||
jwtInfo.setName(jwt.getPayload("name").toString());
|
||||
jwtInfo.setUid(jwt.getPayload("uid").toString());
|
||||
return jwtInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package com.ag.secp.platform.jwt;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description: 统一返回结果的类
|
||||
* Author: songwp
|
||||
* Version: 1.0
|
||||
* Create Date: 2021/9/3
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)//可以进行链式操作
|
||||
public class R {
|
||||
|
||||
private int respCode;
|
||||
|
||||
private String respMsg;
|
||||
|
||||
private Map<String,Object> data = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Description:私有构造方法
|
||||
* @param
|
||||
* @return: com.ag.secp.mobile.common.R
|
||||
* @Author songwp
|
||||
* Create Date 2021/9/3
|
||||
*/
|
||||
private R(){}
|
||||
|
||||
/**
|
||||
* Description:请求成功静态方法
|
||||
* @param
|
||||
* @return: com.ag.secp.mobile.common.R
|
||||
* @Author songwp
|
||||
* Create Date 2021/9/3
|
||||
*/
|
||||
public static R success() {
|
||||
R r = new R();
|
||||
r.setRespCode(ResultCode.SUCCESS);
|
||||
r.setRespMsg(ResultCode.SUCCESS_MSG);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:请求失败静态方法
|
||||
* @param
|
||||
* @return: com.ag.secp.mobile.common.R
|
||||
* @Author songwp
|
||||
* Create Date 2021/9/3
|
||||
*/
|
||||
public static R failed(String failedMsg) {
|
||||
R r = new R();
|
||||
r.setRespCode(ResultCode.FAILED);
|
||||
r.setRespMsg(failedMsg);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:TOKEN验证失败
|
||||
* @param
|
||||
* @return: com.ag.secp.mobile.common.R
|
||||
* @Author songwp
|
||||
* Create Date 2021/9/3
|
||||
*/
|
||||
public static R failedToken() {
|
||||
R r = new R();
|
||||
r.setRespCode(ResultCode.LOGIN_REQUIRED);
|
||||
r.setRespMsg(ResultCode.TOKEN_VERIFY_ERROR);
|
||||
return r;
|
||||
}
|
||||
|
||||
public R setRData(String key,Object value) {
|
||||
this.data.put(key,value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public R setRData(Map<String,Object> map) {
|
||||
this.setData(map);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.ag.secp.platform.jwt;
|
||||
|
||||
/**
|
||||
* Description: 数据返回状态码
|
||||
* Author: songwp
|
||||
* Version: 1.0
|
||||
* Create Date: 2021/9/3
|
||||
*/
|
||||
public interface ResultCode {
|
||||
|
||||
//请求成功
|
||||
int SUCCESS = 1;
|
||||
String SUCCESS_MSG = "请求成功";
|
||||
//请求失败
|
||||
int FAILED = 0;
|
||||
|
||||
String FAILED_MSG = "请求失败";
|
||||
|
||||
String FAILED_MSG_img = "图片不存在";
|
||||
|
||||
//登录--用户名或密码错误
|
||||
String USERNAME_OR_PASSWORD_ERROR_MSG = "用户名或密码错误";
|
||||
String USER_FROZEN = "账号已冻结";
|
||||
String USER_IS_NULL = "无此用户";
|
||||
String USER_IS_EXISTS = "用户名已存在";
|
||||
|
||||
String TOKEN_VERIFY_ERROR = "token验证失败";
|
||||
String TOKEN_KEY = "token";
|
||||
String TOKEN_KEY_HEADER_AUTHORIZATION = "Authorization";
|
||||
String TOKEN_KEY_HEADER_AUTHORIZATION_BEARER = "Bearer";
|
||||
|
||||
//系统繁忙,请稍候再试
|
||||
Integer SYSTEM_BUSY = -1;
|
||||
//请求参数不合法
|
||||
Integer ILLEGAL_PARAMETER = 40000;
|
||||
//需要 GET 请求
|
||||
Integer GET_REQUEST = 43001;
|
||||
//需要 POST 请求
|
||||
Integer POST_REQUEST = 43002;
|
||||
//需要 HTTPS 请求
|
||||
Integer HTTPS_REQUEST = 43003;
|
||||
//API 调用太频繁,请稍候再试
|
||||
Integer API_BUSY = 45011;
|
||||
//系统错误 (system error)
|
||||
Integer SERVE_ERROR = 61450;
|
||||
|
||||
//(Illegal token)
|
||||
Integer ILLEGAL_TOKEN = 50008;
|
||||
//Other clients logged in
|
||||
Integer OTHERCLIENTS_LOGININ = 50012;
|
||||
//Token expired
|
||||
Integer TOKEN_EXPIRED = 50014;
|
||||
//会话过期,请重新登录
|
||||
Integer LOGIN_REQUIRED = 70500;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.ag.web.api;
|
||||
|
||||
import com.ag.secp.platform.jwt.JWTInfo;
|
||||
import com.ag.secp.platform.jwt.JWTTokenForHS256;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: fengjun
|
||||
* @time: 2022/9/1 16:21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/jwt")
|
||||
public class JwtController {
|
||||
@RequestMapping(value = "/getJwt")
|
||||
public String getJwt(@NotNull String username, @NotNull String password) {
|
||||
Assert.isTrue("admin".equals(username) && "ps".equals(password),"登录密码错误");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("uid", "000010000");
|
||||
return JWTTokenForHS256.createToken(map, 30000000);
|
||||
}
|
||||
@RequestMapping(value = "/getWater")
|
||||
public String getWater(){
|
||||
return "give you water";
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,5 @@
|
||||
|
||||
|
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
<mvc:interceptors>
|
||||
<mvc:interceptor>
|
||||
<mvc:mapping path="/jwt/**"/>
|
||||
<mvc:exclude-mapping path="/jwt/getJwt"/>
|
||||
<bean class="com.ag.secp.platform.jwt.JWTInterceptor"/>
|
||||
</mvc:interceptor>
|
||||
</mvc:interceptors>
|
||||
|
||||
</beans>
|
||||
|
||||
0
IlogDynamicModule/src/main/resources/mapper/i.ini
Normal file
0
IlogDynamicModule/src/main/resources/mapper/i.ini
Normal file
@@ -1,3 +1,6 @@
|
||||
# 知识库
|
||||
https://fengjunnn.gitlab.io/ag-k-vuepress/
|
||||
|
||||
# 快速开始(项目部署采用tomcat9)
|
||||
## 修改项目名称
|
||||
|
||||
|
||||
@@ -18,15 +18,20 @@ public class GeneratorMain {
|
||||
private static final JdbcParams jdbc = new JdbcParams();
|
||||
static {
|
||||
jdbc.setDriveClass("com.mysql.cj.jdbc.Driver");
|
||||
jdbc.setUrl("jdbc:mysql://122.5.19.222:3909/ag_devmysql");
|
||||
jdbc.setUrl("jdbc:mysql://192.168.1.188:3306/ag_one_test");
|
||||
jdbc.setUsername("root");
|
||||
jdbc.setPassword("agmysqlroot");
|
||||
}
|
||||
|
||||
public static String getProjectPath() {
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
|
||||
//不考虑用户
|
||||
static class Generator{
|
||||
public static void main(String[] args) throws XMLParserException, SQLException, IOException, InterruptedException, InvalidConfigurationException {
|
||||
String tableNames = "teacher";
|
||||
String tableNames = "student";
|
||||
String[] tableNameArray = tableNames.split(",");
|
||||
for (String tableName : tableNameArray) {
|
||||
GeneratorStarter.generate(tableName,jdbc);
|
||||
@@ -36,8 +41,8 @@ public class GeneratorMain {
|
||||
//考虑用户 ,同一个用户
|
||||
static class GeneratorMultiple{
|
||||
public static void main(String[] args) throws XMLParserException, SQLException, IOException, InterruptedException, InvalidConfigurationException {
|
||||
String tableNames = "FA_VBILL_TRUCK,FA_VBILL_CUSTOM";
|
||||
String tableSchema = "AG_SECP_SHHH";
|
||||
String tableNames = "student";
|
||||
String tableSchema = "";
|
||||
String[] tableNameArray = tableNames.split(",");
|
||||
for (String tableName : tableNameArray) {
|
||||
GeneratorStarter.generate(tableName,tableSchema,jdbc);
|
||||
@@ -55,9 +60,8 @@ public class GeneratorMain {
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//基础路径
|
||||
public static final String BASE_PATH = "E:\\IdeaProject\\AG_MYSQL_PLATFORM3.0\\IlogDynamicModule\\src\\main\\";
|
||||
public static final String BASE_PATH = getProjectPath()+"\\IlogDynamicModule\\src\\main\\";
|
||||
//domain包路径
|
||||
public static final String DOMAIN_PACKAGE = "com.ag.example.domain";
|
||||
//pojo包路径
|
||||
|
||||
Reference in New Issue
Block a user