You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.3 KiB
66 lines
2.3 KiB
3 years ago
|
package com.fr.plugin;
|
||
|
|
||
|
import com.fanruan.api.log.LogKit;
|
||
|
import com.fanruan.api.net.http.HttpKit;
|
||
|
import com.fr.decision.authorize.impl.AbstractPassport;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.tools.ToolDES;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class USAAPassport extends AbstractPassport {
|
||
|
@Override
|
||
|
public boolean checkTicket(String username, String inputPassword, String savedPassword, String hashPassword) {
|
||
|
boolean checkTicket = false;
|
||
|
String st = null;
|
||
|
try {
|
||
|
st = getSt(username, inputPassword);
|
||
|
if (StringUtils.isBlank(st)) {
|
||
|
return false;
|
||
|
}
|
||
|
String un = getUserInfo(st);
|
||
|
if (StringUtils.equals(un,username)) {
|
||
|
return true;
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
LogKit.error("认证失败:",e);
|
||
|
return false;
|
||
|
}
|
||
|
return checkTicket;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String markType() {
|
||
|
return "USAA";
|
||
|
}
|
||
|
|
||
|
private String getSt(String name, String pwd) throws IOException {
|
||
|
String encrypt = ToolDES.encrypt(pwd);
|
||
|
UASSLOGINConfig uassloginConfig = UASSLOGINConfig.getInstance();
|
||
|
String url = String.format("%s/ssouas/ssologincheck?loginname=%s&password=%s", uassloginConfig.getApiUrl(), name, encrypt);
|
||
|
String resp = HttpKit.get(url);
|
||
|
LogKit.info("访问:{} 获取st 响应:{}", url, resp);
|
||
|
JSONObject entries = new JSONObject(resp);
|
||
|
String err = entries.getString("err");
|
||
|
if (StringUtils.equals(err, "1")) {
|
||
|
String st = entries.getString("st");
|
||
|
return st;
|
||
|
}
|
||
|
return resp;
|
||
|
}
|
||
|
private String getUserInfo(String st) throws IOException {
|
||
|
UASSLOGINConfig uassloginConfig = UASSLOGINConfig.getInstance();
|
||
|
String userInfoUrl = String.format("%s/ssouas/loginuass?st=%s", uassloginConfig.getApiUrl(), st);
|
||
|
String resp = HttpKit.get(userInfoUrl);
|
||
|
LogKit.info("访问:{} 获取userInfo 响应:{}", userInfoUrl, resp);
|
||
|
JSONObject entries = new JSONObject(resp);
|
||
|
String err = entries.getString("err");
|
||
|
if (StringUtils.equals(err, "1")) {
|
||
|
String userName = entries.getString("userName");
|
||
|
return userName;
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
}
|