0
|
XushuaisLv6初级互助发布于2024-5-17 17:21
|
|
-
HiPooh(提问者)
- 老师好,代码主要部分如下,上传附件这网页就崩了,只能直接复制出来了
@Path("/fr")
public class FRLogin {
private static final int FRAGMENT_LENGTH = 245;
@GET
@Path("/login")
@Produces({MediaType.TEXT_PLAIN})
public String getCompanyCode(@Context HttpServletRequest request, @Context HttpServletResponse response) {
String nwip = "http://192.168.1.248:18301/digiwin/kanban?ssoToken=";
String wwip = "http://113.108.246.214:18301/digiwin/kanban?ssoToken=";
String url="";
url = request.getRequestURL().toString();
if(url.indexOf("192.168.1.20")>=0){
url = nwip;
}else{
url = wwip;
}
User u = (User)request.getSession().getAttribute("weaver_user@bean");
try {
url += getToken(u.getLoginid());
response.sendRedirect(url);
return url;
} catch (Exception e) {
e.printStackTrace();
}
/* Enumeration s = request.getSession().getAttributeNames();
while(s.hasMoreElements()){
String sss = s.nextElement().toString();
ss+=sss+":";
ss+=request.getSession().getAttribute(sss).toString()+",";
if("weaver_user@bean".equals(sss)){
User u = (User)request.getSession().getAttribute(sss);
ss+=u.getUsername()+";";
ss+=u.getAccount()+";";
}
}*/
return url;
//return ss;
// return "OK";
}
public String getToken(String workcode)throws UnsupportedEncodingException{
String un = "{\n" +
" \"username\": \"sysadmin\",\n" +
" \"issueTime\":1640832102097\n" +
"}";
String currentTimeMillis = String.valueOf(System.currentTimeMillis()+1000*10);
un=un.replace("1640832102097",currentTimeMillis);
un=un.replace("sysadmin",workcode);
String text = System.getProperty("text");
String key = System.getProperty("publicKey");
String username = text == null ? un : text;
/* String defaultKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAphdj55QhPruspjwkgTRbPB8/Gi0N3UYG\n" +
"nGHSHJ6yo26HH2CwadAaXpLAA5N8wewQGE/q0ZBmD8eZA4RDIUkQkMX1gGE+ZlunYH74lhGwvv1z\n" +
"3UKCVt7i3h6L+/rMFLALxo9ttTL4FDzvU0vJWYxZyJopl+9xymOcdtYTsbU5mbX+K5DtIw+tFVWl\n" +
"zNbCGnU2ro0AN1ShZLbthgfMwnY4W9z4FMeFBrVJNBm6E+nSgy7o4lfnaFKxsuJKwa2usDwwVHPd\n" +
"gAf/7pUCDgPYbMJ0bLHhxFimeAzQ1jk4L6BGYgPORlPw31v4B6VNvCpnMe/FMCLzGQoFd0u4AhYd\n" +
"a+E2sQIDAQAB";*/
String defaultKey ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApah8X8e8BP5VZhu+g9KA57npFBn+nVNQ\n" +
"8+T6hsLJoNg4IbfK5h4LKNP4bztFSue5DvCfuy5MLoAjMTpY62/yLawaZN1SvQm3vKG77Stgf4L9\n" +
"DrNuKc2jXSfpn9fg0lOllVzzdEQvsaYr/60gboeZoIg3T/PQtRyJuM9epb/hs7NXQoKd/R82D+Oc\n" +
"+dJPu8QyRLSb3xsGUlWyHHDZZAVNAts9+Y/gBY0DtHoAwJiRVU4wCqRAcgCZAUxYw+1HjHGGohPp\n" +
"LoZFg/fY/UNUXZTTjCHd72i0TI0ITgccEez2+mlxZkSCtXhT7dyM/kjELHbCu+AwC2ig6seIGTKi\n" +
"OamzhwIDAQAB";
//从插件配置页面获取
String publicKey = key == null ? defaultKey : key;
System.out.println(" un: " + un);
System.out.println("defaultKey : " + defaultKey);
//加密后的ssoToken,可以在前台界面进行解密测试
String encrypt = encrypt(username, publicKey);
System.out.println("encrypted username: " + encrypt);
//encode后的token,可以直接放于url上进行单点
String encode = URLEncoder.encode(encrypt, "UTF-8");
System.out.println("ssoToken: " + encode);
return encode;
}
-
Xushuais 回复 HiPooh(提问者)
- response.sendRedirect(url);
return url;
在重定向前,对user进行判断,异常直接重定向login页面
|
|