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 ""; } }