Commit cc0c82c6 authored by 胡文斌's avatar 胡文斌

修改消息跳转

parent 94e0a86f
...@@ -59,7 +59,7 @@ public class IndexController extends Controller { ...@@ -59,7 +59,7 @@ public class IndexController extends Controller {
/** /**
* 超期时间:24小时,即:24 * 60 * 60 * 1000 * 超期时间:24小时,即:24 * 60 * 60 * 1000
*/ */
private static int EXPIRATION = 24 * 60 * 60 * 1000; public static final int EXPIRATION = 24 * 60 * 60 * 1000;
private static int permitLoginTimes = 5;// 允许登陆次数 private static int permitLoginTimes = 5;// 允许登陆次数
private static int hour = 2; // 两小时内不可登录 private static int hour = 2; // 两小时内不可登录
@Inject @Inject
......
package com.archser.aserver.controller; package com.archser.aserver.controller;
import java.util.List;
import com.archser.aserver.interceptor.JwtInterceptor; import com.archser.aserver.interceptor.JwtInterceptor;
import com.archser.aserver.model.System; import com.archser.aserver.model.System;
import com.archser.aserver.service.LogService; import com.archser.aserver.service.LogService;
import com.archser.aserver.service.SystemService; import com.archser.aserver.service.SystemService;
import com.archser.aserver.util.JwtUtils;
import com.jfinal.aop.Before; import com.jfinal.aop.Before;
import com.jfinal.aop.Clear; import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject; import com.jfinal.aop.Inject;
...@@ -14,6 +13,8 @@ import com.jfinal.kit.Ret; ...@@ -14,6 +13,8 @@ import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.tx.Tx; import com.jfinal.plugin.activerecord.tx.Tx;
import java.util.List;
/** /**
* 应用相关 * 应用相关
* *
...@@ -150,4 +151,15 @@ public class SystemController extends Controller { ...@@ -150,4 +151,15 @@ public class SystemController extends Controller {
this.renderJson(Ret.ok("system", system)); this.renderJson(Ret.ok("system", system));
} }
/**
* 获取系统url和生成用户token
*/
public void getTokenAndUrl() {
Integer systemId = this.getParaToInt("systemId");
String username = this.getAttrForStr("username");
System system = System.dao.findById(systemId);
String token = JwtUtils.generateToken(system, username);
this.renderJson(Ret.ok("token", token).set("url", system.getUrl()));
}
} }
package com.archser.aserver.util;
import com.archser.aserver.controller.IndexController;
import com.archser.aserver.interceptor.JwtInterceptor;
import com.archser.aserver.model.System;
import com.sun.deploy.util.URLUtil;
import io.jsonwebtoken.JwsHeader;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.undertow.util.URLUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Auther: huwenbin
* @Date: 2020/11/6 18:16
*/
public class JwtUtils {
public static String generateToken(System system, String username) {
URL url = null;
try {
url = new URL(system.getUrl());
String host = url.getHost();
return generateToken(system.getKeyid(), system.getPrivatekey(), system.getName(), username, host);
} catch (MalformedURLException ignored) {
}
return null;
}
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://39.104.28.145:11028");
String host = url.getHost();
java.lang.System.out.println(host);
}
/**
* 生成Token
* @param keyId 系统keyid
* @param privateKey 系统私钥
* @param app 系统名称
* @param username 用户名
* @param ip ip地址
* @return token
*/
public static String generateToken(String keyId, String privateKey, String app, String username, String ip) {
return Jwts.builder()
// 设置密匙ID
.setHeaderParam(JwsHeader.KEY_ID, keyId)
// 赋予应用
.setSubject(app)
// 签发时间
.setIssuedAt(new Date())
// 超期时间
.setExpiration(new Date(java.lang.System.currentTimeMillis() + IndexController.EXPIRATION))
// 用户名
.claim("name", username).claim("ip", ip)
// 签名
.signWith(KeysUtil.privatekey(privateKey), SignatureAlgorithm.RS256).compact();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment