自动生成配置文件和mapper xml

newBigdata
xiaoCJ 11 months ago
parent ef403efc68
commit 76c7e1ee24

@ -102,6 +102,10 @@ public class TokenProvider {
.compact(); .compact();
} }
public static void main(String[] args) {
JwtUser jwtUser = getJWTUserByZhiYun("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb2xsZWdlIjoi5ryU56S65a2m6ZmiIiwiaWNpYnRTY2hvb2xJZCI6NCwibWQ1UHdkIjoiNDYtRjktNEMtOEQtRTEtNEYtQjMtNjYtODAtODUtMDctNjgtRkYtMUItN0YtMkEiLCJyb2xlaWQiOiI0Iiwic2V4Ijoi55S3IiwidXNlcklkIjoiNDg3Iiwic3R1ZGVudElkIjoiNDA0OCIsInBhc3N3b3JkIjoiMTIzcXdlIiwiY2xhc3NJZCI6IjIxMSIsImljaWJ0Q2xhc3NJZCI6MjA0LCJtYWpvciI6IuS6p-WTgea8lOekuuS4k-S4miIsInNjaG9vbCI6IuWkqeaLqeWkp-WtpiIsInNjaG9vbElkIjoiMjMyIiwibmFtZSI6InR6czAwMSIsInN0dWRlbnRObyI6InR6czAwMSIsImFwcGxpY2F0aW9uSWQiOiIxMTkiLCJjbGFzcyI6IuWkqeaLqea8lOekujHnj60iLCJ1c2VybmFtZSI6InR6czAwMSJ9.p6Uu15B1zNzuuCMOkDTkMksvjU6EOvGWprMWuJB0OII");
System.out.println(jwtUser);
}
/** /**
* token * token
*/ */
@ -124,6 +128,8 @@ public class TokenProvider {
jwtUser.setClassId(Integer.valueOf(claims.get("classId")==null?"0":claims.get("classId").toString())); jwtUser.setClassId(Integer.valueOf(claims.get("classId")==null?"0":claims.get("classId").toString()));
jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId")==null?"0":claims.get("schoolId").toString())); jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId")==null?"0":claims.get("schoolId").toString()));
jwtUser.setUsername(claims.get("username").toString()); jwtUser.setUsername(claims.get("username").toString());
jwtUser.setPassword(claims.get("password").toString());
jwtUser.setStudentId(claims.get("studentNo").toString());
return jwtUser; return jwtUser;
} catch (Exception e) { } catch (Exception e) {
throw new UnAuthorizedException("token解析失败"); throw new UnAuthorizedException("token解析失败");
@ -132,41 +138,41 @@ public class TokenProvider {
//生成智云平台32字节密钥 //生成智云平台32字节密钥
public static void main(String[] args) { // public static void main(String[] args) {
// String prefix = "zy_wh_mnjy_"; //// String prefix = "zy_wh_mnjy_";
// String generatedKey = generateKey(prefix); //// String generatedKey = generateKey(prefix);
// System.out.println("Generated Key: " + generatedKey); //// System.out.println("Generated Key: " + generatedKey);
// getJWTUserByZhiYun(null); //// getJWTUserByZhiYun(null);
//生成一个新的长度为512字节的随机密钥供智云平台解析token
// int keyLength = 512; // 根据您的要求进行调整
// KeyGenerator keyGenerator;
// try {
// keyGenerator = KeyGenerator.getInstance("HmacSHA512");
// keyGenerator.init(keyLength);
// SecretKey secretKey = keyGenerator.generateKey();
// byte[] secretBytes = secretKey.getEncoded();
// String secret = Base64.getUrlEncoder().withoutPadding().encodeToString(secretBytes);
// //
// System.out.println("Generated Secret: " + secret); //
// } catch (NoSuchAlgorithmException e) { ////生成一个新的长度为512字节的随机密钥供智云平台解析token
// e.printStackTrace(); //// int keyLength = 512; // 根据您的要求进行调整
// } //// KeyGenerator keyGenerator;
//// try {
JwtUser user = new JwtUser(); //// keyGenerator = KeyGenerator.getInstance("HmacSHA512");
user.setUserId("486"); //// keyGenerator.init(keyLength);
user.setRoleId(3); //// SecretKey secretKey = keyGenerator.generateKey();
user.setUsername("tzt006"); //// byte[] secretBytes = secretKey.getEncoded();
user.setSchoolId(1); //// String secret = Base64.getUrlEncoder().withoutPadding().encodeToString(secretBytes);
user.setSchoolName("天择大学"); ////
user.setCollegeId(1); //// System.out.println("Generated Secret: " + secret);
user.setCollegeName("演示学院"); //// } catch (NoSuchAlgorithmException e) {
user.setMajorId(1); //// e.printStackTrace();
user.setMajorName("产品演示专业"); //// }
String token = createZHIYUNToken(user); //
System.out.println(token); // JwtUser user = new JwtUser();
} // user.setUserId("486");
// user.setRoleId(3);
// user.setUsername("tzt006");
// user.setSchoolId(1);
// user.setSchoolName("天择大学");
// user.setCollegeId(1);
// user.setCollegeName("演示学院");
// user.setMajorId(1);
// user.setMajorName("产品演示专业");
// String token = createZHIYUNToken(user);
// System.out.println(token);
// }
public static String generateKey(String prefix) { public static String generateKey(String prefix) {
String characters = "0123456789abcdefghijklmnopqrstuvwxyz"; String characters = "0123456789abcdefghijklmnopqrstuvwxyz";

@ -178,9 +178,9 @@ public class TeaGradeManageController {
} }
@AnonymousAccess // @AnonymousAccess
@GetMapping("/test") // @GetMapping("/test")
@ApiOperation("测试导出") // @ApiOperation("测试导出")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("Content-Disposition", "attachment; filename=exam_result.docx"); response.setHeader("Content-Disposition", "attachment; filename=exam_result.docx");

@ -63,8 +63,6 @@ public class UserController {
private static LocalDateTime loginTime; private static LocalDateTime loginTime;
private static String loginIp; private static String loginIp;
private final static String SECRET_ZHIYUN = "zy_qkl_c1fqkcgekg1icu7ddp8qiho0u";
@PostMapping("/login") @PostMapping("/login")
@ApiOperation("登录接口") @ApiOperation("登录接口")
@ -72,16 +70,16 @@ public class UserController {
public ResultEntity login(@RequestParam String passwordEncode, public ResultEntity login(@RequestParam String passwordEncode,
@RequestParam String userName, @RequestParam String userName,
HttpServletRequest request, HttpServletRequest request,
@RequestParam int roleId, @RequestParam(required = false) int roleId,
@RequestParam(required = false) String TOKEN) { @RequestParam(required = false) String TOKEN) {
JwtUser jwtUser; JwtUser jwtUser;
String passWord; String passWord;
try {
passWord = RsaUtil.decryptByPrivateKey(passwordEncode);
} catch (Exception e) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误");
}
if (StringUtils.isBlank(TOKEN)) { if (StringUtils.isBlank(TOKEN)) {
try {
passWord = RsaUtil.decryptByPrivateKey(passwordEncode);
} catch (Exception e) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误");
}
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, passWord); UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, passWord);
System.out.println(userName); System.out.println(userName);
System.out.println(passWord); System.out.println(passWord);
@ -120,18 +118,11 @@ public class UserController {
} else { // 2、智云单点登录 } else { // 2、智云单点登录
jwtUser = TokenProvider.getJWTUserByZhiYun(TOKEN); jwtUser = TokenProvider.getJWTUserByZhiYun(TOKEN);
if (jwtUser == null) {
throw new UnAuthorizedException("token无效");
}
int roleId1 = jwtUser.getRoleId(); int roleId1 = jwtUser.getRoleId();
if (!Objects.equals(roleId, roleId1)) { if (!Objects.equals(roleId, roleId1)) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "用户权限错误!"); return new ResultEntity(HttpStatus.BAD_REQUEST, "用户权限错误!");
} }
try { jwtUser = TzApi.foreignExchangeTradingLogin(jwtUser.getUsername(), jwtUser.getPassword());
} catch (Exception e) {
throw new UnAuthorizedException("密码错误");
}
jwtUser = TzApi.foreignExchangeTradingLogin(userName, passWord);
if (jwtUser == null) { if (jwtUser == null) {
throw new UnAuthorizedException("用户名或密码错误"); throw new UnAuthorizedException("用户名或密码错误");
} }
@ -168,7 +159,9 @@ public class UserController {
sysLoginLog.setLogId(uuid); sysLoginLog.setLogId(uuid);
sysLoginLog.setUserid(userId); sysLoginLog.setUserid(userId);
sysLoginLog.setName(name); sysLoginLog.setName(name);
sysLoginLog.setStudentId(studentId); if (studentId != null) {
sysLoginLog.setStudentId(studentId);
}
sysLoginLog.setLoginTime(new Date()); sysLoginLog.setLoginTime(new Date());
sysLoginLogMapper.insert(sysLoginLog); sysLoginLogMapper.insert(sysLoginLog);
return uuid; return uuid;

@ -101,7 +101,7 @@ public class TeaUserServiceImpl implements ITeaUserService {
} }
if (searcher == null) { if (searcher == null) {
try { try {
File file = ResourceUtils.getFile("classpath:ipdb/ip2region.xdb"); File file = ResourceUtils.getFile("/usr/local/tianzeProject/financial_bigdata/ipdb/ip2region.xdb");
String dbPath = file.getPath(); String dbPath = file.getPath();
searcher = Searcher.newWithFileOnly(dbPath); searcher = Searcher.newWithFileOnly(dbPath);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

Loading…
Cancel
Save