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.
64 lines
1.9 KiB
64 lines
1.9 KiB
package com.eco.plugin.xx.zgrsauth.utils; |
|
|
|
import com.eco.plugin.xx.zgrsauth.config.PluginSimpleConfig; |
|
import com.eco.plugin.xx.zgrsauth.webservice.ExeHttp; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
|
|
public class AuthUtils { |
|
|
|
/** |
|
* 判断是否有权限 |
|
* @param username |
|
* @param temp |
|
* @param psc |
|
* @return |
|
*/ |
|
public static boolean hasAuth(String username,String temp,PluginSimpleConfig psc){ |
|
JSONArray auths = new JSONArray(); |
|
try { |
|
auths = getAuth(username, psc); |
|
} catch (Exception e) { |
|
FRUtils.FRLogInfo("exception :"+e.getMessage()); |
|
return false; |
|
} |
|
|
|
boolean hasAuth = false; |
|
|
|
for(int i=0;i<auths.size();i++){ |
|
JSONObject auth = auths.getJSONObject(i); |
|
String dimensionValue = auth.getString("dimensionValue"); |
|
FRUtils.FRLogInfo("temp:"+temp+";dimensionValue:"+dimensionValue+";equals:"+String.valueOf(dimensionValue.equals(temp))); |
|
|
|
if(dimensionValue.equals(temp)){ |
|
hasAuth = true; |
|
break; |
|
} |
|
} |
|
|
|
return hasAuth; |
|
} |
|
|
|
/** |
|
* 获取auth数组 |
|
* @param psc |
|
* @return |
|
* @throws Exception |
|
*/ |
|
private static JSONArray getAuth(String username,PluginSimpleConfig psc) throws Exception { |
|
ExeHttp t = new ExeHttp(); |
|
|
|
String result = t.exeWebService4queryDimension(Integer.valueOf(username),psc.getDimensionCd(),psc.getSystemCd()); |
|
|
|
FRUtils.FRLogInfo("resule:"+result); |
|
|
|
if(Utils.isNullStr(result)){ |
|
throw new Exception("获取权限信息失败!"); |
|
} |
|
|
|
JSONObject resultJson = new JSONObject(result); |
|
JSONArray dimensionRanges = resultJson.getJSONArray("dimensionRanges"); |
|
JSONObject dimensionRange = dimensionRanges.getJSONObject(0); |
|
return dimensionRange.getJsonArray("authRange"); |
|
} |
|
}
|
|
|