标准产品是供应商点击登录时,跳到苍穹统一的登录界面,
实际上供应商门户是放开在外网给外部人员登录,不应该跳到跟内部人员登录的登录页面
并且应该对内外网做应用的访问隔离
供应商门户这里重新设计单独的登录界面flex,点右上方登录按钮时显示该flex
利用单点登录特性让供应商能正常登录苍穹
登录按钮的代码实现
String mobilePhone = pageObj.getString("xxx_mobilephone");
String password = pageObj.getString("xxx_password");
try
{
String username = mobilePhone.substring(mobilePhone.indexOf("-") + 1, mobilePhone.length());
//验证是否供应商用户
List<QFilter> filters = new ArrayList<QFilter>();
filters.add(new QFilter("phone", QCP.equals, username));
DynamicObject[] userObjColl = BusinessDataServiceHelper.load("bos_user", "number,name,usertype,phone",
filters.toArray(new QFilter[filters.size()]));
if (userObjColl != null && userObjColl.length > 0 && !"3".equals(userObjColl[0].getString("usertype")))
{
Label label = this.getView().getControl("scpg_label_mobilephone");
label.setText("非供应商账户不允许登录!");
return;
}
String ssoUrl = getUserSSOLoginUrl(username, password);
if (StringUtils.isEmpty(ssoUrl))
{
Label label = this.getView().getControl("scpg_label_mobilephone");
label.setText("手机号码或密码错误");
return;
}
logger.info("ssoUrl:" + ssoUrl);
IClientViewProxy proxy = (IClientViewProxy) this.getView().getService(IClientViewProxy.class);
Map<String, String> mpURL = new HashMap();
mpURL.put("url", ssoUrl);
mpURL.put("openStyle", "0");
proxy.addAction("openUrl", mpURL);
}
catch (Exception e)
{
logger.error("供应商门户登录异常:", e);
this.getView().showErrMessage(ExceptionUtils.getExceptionStackTraceMessage(e), "供应商门户登录异常,请联系管理员:");
}
public String getUserSSOLoginUrl(String userAccount, String password) throws Exception
{
Properties p = new Properties();
InputStream ins = DoHttpUtil.class.getClassLoader().getResourceAsStream("propertie.properties");
p.load(ins);
String url = System.getProperty("domain.contextUrl");
String appId = p.getProperty("cq_appid");
String appSecuret = p.getProperty("cq_appsecuret");
String accountId = p.getProperty("cq_accountid");
String tenantid = p.getProperty("cq_tenantid");
String language = p.getProperty("cq_language");
String app_token = getAppToken(url, appId, appSecuret, accountId, language);
String access_token = getUserLoginAccessToken(url, userAccount, password, app_token, tenantid, "2");//logintype 0:云之家 2 苍穹云 默认为云之家方式
String ssoUrl = "";
JSONObject jsonObj = JSONObject.parseObject(access_token);
if ("success".equals(jsonObj.getString("state")))
{
access_token = jsonObj.getJSONObject("data").getString("access_token");
ssoUrl = url + "/accessTokenLogin.do?access_token=" + access_token + "&redirect=" + url + "/index.html";//&loginOrg=001 需要切换的的组织的代码,非必填
}
return ssoUrl;
}
private String getAppToken(String url, String appId, String appSecuret, String accountId, String language) throws Exception
{
String httpurl = url + "/api/getAppToken.do";
Map<String, Object> params = new HashMap<String, Object>();
params.put("appId", appId);
params.put("appSecuret", appSecuret);
params.put("accountId", accountId);
params.put("language", language);
try
{
String ret = sendPostHttp(httpurl, JSONObject.toJSONString(params), null);
JSONObject jsonObj = JSONObject.parseObject(ret);
if ("success".equals(jsonObj.getString("state")))
{
return jsonObj.getJSONObject("data").getString("app_token");
}
else
{
throw new Exception("获取getAppToken调用失败,ret=" + ret);
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("获取getAppToken调用失败,Exception=" + e.getMessage());
}
}
private String getAccessToken(String url, String user, String usertype, String accountId, String appToken) throws Exception
{
String httpurl = url + "/api/login.do";
Map<String, Object> params = new HashMap<String, Object>();
params.put("user", user);
params.put("apptoken", appToken);
params.put("accountId", accountId);
params.put("usertype", usertype);
try
{
String ret = sendPostHttp(httpurl, JSONObject.toJSONString(params), null);
JSONObject jsonObj = JSONObject.parseObject(ret);
if ("success".equals(jsonObj.getString("state")))
{
return jsonObj.getJSONObject("data").getString("access_token");
}
else
{
throw new Exception("获取getAccessToken调用失败,ret=" + ret);
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("获取getAccessToken调用失败,Exception=" + e.getMessage());
}
}
推荐阅读