⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securityutil.java

📁 VC++
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.sinosoft.security.util;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;

import com.sinosoft.security.EDMPermConstants;
import com.sinosoft.security.SecurityFactory;
import com.sinosoft.security.manager.OrganizationManager;
import com.sinosoft.security.model.Application;
import com.sinosoft.security.model.BaseObject;
import com.sinosoft.security.model.Meta;
import com.sinosoft.security.model.Organization;
import com.sinosoft.security.model.Permission;
import com.sinosoft.security.model.Person;
import com.sinosoft.security.model.Role;
import com.sinosoft.security.model.RoleClass;
import com.sinosoft.security.model.ldap.entry.SmileEntry;
import com.sinosoft.security.provider.ldap.coresupports.LDAPWaitor;
import com.sinosoft.security.util.maxtree.MaxTree;
import com.sinosoft.security.util.maxtree.MaxTreeFactory;
import com.sinosoft.security.util.maxtree.MaxTreeItem;
import com.sinosoft.util.StringToolkit;
import com.sinosoft.utility.ExeSQL;
import com.sinosoft.utility.SSRS;
import common.DBManager;
import common.MMException;

public class SecurityUtil {

	public static Organization getParentCorp(Person currUser) throws Exception {
		return SecurityFactory.getOrganizationManager().getParentCorp(currUser);

	}

	public static Organization getParentCompany(Organization currOrg)
			throws Exception {
		return SecurityFactory.getOrganizationManager().getParentCompany(
				currOrg);

	}

	public static String getHeadParentOrg(String manID) throws Exception {
		Person man = SecurityFactory.getPersonManager()
				.getPersonByHandle(manID);
		if (man == null)
			return "";
		String dn = man.getParentOrgDN();
		Organization result = null;
		if (dn == null || dn.equals(""))
			return "";
		else {
			String hdn = SmileEntry.getDnByLevel(dn, 6);// 石景山是5,市平台是6
			result = SecurityFactory.getOrganizationManager().getOrgByDN(hdn);
			if (result == null)
				return "";
		}
		// return result.getName() + ";" + result.getInnerCode();
		return result.getName();

	}

	public static String getHeadParentOrgCode(String manID) throws Exception {
		Person man = SecurityFactory.getPersonManager()
				.getPersonByHandle(manID);
		if (man == null)
			return "";
		String dn = man.getParentOrgDN();
		Organization result = null;
		if (dn == null || dn.equals(""))
			return "";
		else {
			String hdn = SmileEntry.getDnByLevel(dn, 6);// 石景山是5,市平台是6
			result = SecurityFactory.getOrganizationManager().getOrgByDN(hdn);
			if (result == null)
				return "";
		}
		// return result.getName() + ";" + result.getInnerCode();
		return result.getInnerCode();

	}

	public static Role[] getRoles(Person currUser, Application app)
			throws Exception {
		return SecurityFactory.getRoleManager().getRoles(currUser, app);

	}

	public static RoleClass[] getManageRoleClasses(Person currUser)
			throws Exception {
		Application app = null;
		return SecurityFactory.getRoleClassManager().getManageRoleClasses(
				currUser);

	}

	public static Permission[] getPermissions(Person currUser) throws Exception {
		Application app = null;
		return SecurityFactory.getPermissionManager().getPermissions(currUser,
				app);
	}

	public static Organization[] getScopeOrganizations(Person currUser,
			Application app) throws Exception {
		ArrayList orglist = new ArrayList();
		Organization tempOrgs = null;
		Organization[] scopeOrgs = null;

		if (currUser.getEName().equalsIgnoreCase("God")) {

			scopeOrgs = new Organization[] { SecurityFactory
					.getOrganizationManager().getRootOrg() };
		}

		else {

			scopeOrgs = SecurityFactory.getOrganizationManager()
					.getScopeOrganizations(currUser, app);
		}
		return scopeOrgs;
	}

	public static String[] getMetaManagerScopeOrganizations(String userID)
			throws Exception {
		Organization[] temp = null;
		ArrayList templist = new ArrayList();
		String[] morgs = null;
		Person one = SecurityFactory.getPersonManager().getPersonByHandle(
				userID);
		Application app = SecurityFactory.getApplicationManager()
				.getAppByEName(EDMPermConstants.EDM_DIR_MANAGE_APPNAME);
		temp = getScopeOrganizations(one, app);
		if (temp != null) {
			for (int i = 0; i < temp.length; i++) {
				if (temp[i] != null)
					templist.add(temp[i].getName());

			}
			int size = templist.size();
			morgs = (String[]) templist.toArray(new String[size]);

		}
		return morgs;
	}

	public static String[] getScopeOrganizationsByPersonAndPerm(String userID,
			String permEname) throws Exception {
		Organization[] temp = null;
		ArrayList templist = new ArrayList();
		String[] morgs = null;
		if (userID.equalsIgnoreCase("god")) {
			temp = new Organization[1];
			temp[0] = SecurityFactory.getOrganizationManager().getRootOrg();
		} else {
			Person one = SecurityFactory.getPersonManager().getPersonByHandle(
					userID);
			if (one == null)
				return null;
			Permission perm = SecurityFactory.getPermissionManager()
					.getPermByEname(permEname);
			if (perm == null)
				return null;
			temp = SecurityFactory.getOrganizationManager()
					.getOrgsByPermission(perm, one);
		}
		if (temp != null) {
			for (int i = 0; i < temp.length; i++) {
				if (temp[i] != null) {

					Organization[] childs = SecurityFactory
							.getOrganizationManager().getAllOrgsInOrg(temp[i]);
					for (int j = 0; j < childs.length; j++)
						templist.add(childs[j].getName());
				}

			}
			int size = templist.size();
			morgs = (String[]) templist.toArray(new String[size]);

		}
		return morgs;
	}

	public static String[] getManageOrgIDs(String urls) {
		List list = new ArrayList();
		try {
			String[] urlarray = StringToolkit.splitString(urls, ";", false);
			int len = urlarray != null ? urlarray.length : 0;
			OrganizationManager orgmgr = SecurityFactory
					.getOrganizationManager();
			Organization[] orgs = null;
			Organization org = null;
			for (int i = 0; i < len; i++) {
				org = orgmgr.getOrgByFullEname(urlarray[i]);
				list.add(org.getHandle());
				orgs = orgmgr.getAllOrgsInOrg(org);
				int orglen = orgs != null ? orgs.length : 0;
				for (int k = 0; k < orglen; k++)
					list.add(orgs[k].getHandle());
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		String[] orgIDs = new String[list.size()];
		orgIDs = (String[]) list.toArray(orgIDs);
		return orgIDs;
	}

	public static String[] getDirectManageOrgIDs(String urls) {
		List list = new ArrayList();
		try {
			String[] urlarray = StringToolkit.splitString(urls, ";", false);
			int len = urlarray != null ? urlarray.length : 0;
			OrganizationManager orgmgr = SecurityFactory
					.getOrganizationManager();
			Organization org = null;
			for (int i = 0; i < len; i++) {
				org = orgmgr.getOrgByFullEname(urlarray[i]);
				list.add(org.getHandle());
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		String[] orgIDs = new String[list.size()];
		orgIDs = (String[]) list.toArray(orgIDs);
		return orgIDs;
	}

	public static boolean checkPermission(Person currUser, String permename)
			throws Exception {
		Permission[] thePerms = getPermissions(currUser);
		int leng = thePerms != null ? thePerms.length : 0;
		boolean hasPerm = false;
		for (int i = 0; i < leng; i++) {
			String ename = thePerms[i].getEName();
			if (ename.equalsIgnoreCase(permename)) {
				hasPerm = true;
				break;
			}
		}
		return hasPerm;
	}

	public static Role getRoleByRoleClassFromOrg(String roleClassID,
			String orgURL) throws Exception {

		RoleClass roleclass = SecurityFactory.getRoleClassManager()
				.getRoleClassByHandle(roleClassID);
		Organization org = SecurityFactory.getOrganizationManager()
				.getOrgByFullEname(orgURL);
		return SecurityFactory.getRoleManager().getRoleByRoleClassFromOrg(
				roleclass, org);

	}

	public static String[] getMetaManagerScopeOrganizationCodes(String userID)
			throws Exception {
		Organization[] temp = null;
		ArrayList templist = new ArrayList();
		String[] morgs = null;
		Person one = SecurityFactory.getPersonManager().getPersonByHandle(
				userID);
		Application app = SecurityFactory.getApplicationManager()
				.getAppByEName(EDMPermConstants.EDM_DIR_MANAGE_APPNAME);
		temp = getScopeOrganizations(one, app);
		if (temp != null) {
			for (int i = 0; i < temp.length; i++) {
				if (temp[i] != null)
					templist.add(temp[i].getInnerCode());

			}
			int size = templist.size();
			morgs = (String[]) templist.toArray(new String[size]);

		}
		return morgs;
	}

	public static void delTree(BaseObject base) throws Exception {

		LDAPWaitor myService = new LDAPWaitor();

		String dn = base.getDN();
		try {
			myService.deleteEntryTree(dn);
			System.out.println(dn + "干掉了!");
		} catch (Exception e) {
			e.printStackTrace();
			delTree(base);
		}

	}

	// public static String[] getTreeSchemaList(String owner) throws Exception {
	// String[] list = null;
	// Meta smeta = SecurityFactory.getMetaManager().getMetaByHandle(owner);
	// if (smeta != null)
	// list = smeta.getSchemaOwner();
	// return list;
	// }

	// public static ArrayList getSchemaTree(String sEname, String key,
	// String treetype, HttpServletRequest request) throws Exception {
	// ArrayList trees = new ArrayList();
	// Meta sub = null;
	// Meta smeta = SecurityFactory.getMetaManager().getMetaByEName(sEname);
	// UserManage user = new UserManage(request.getSession());
	// String systemscope = user.getSystemscope();
	// String username = user.getUserName();
	// String systemSwift = request.getSession().getServletContext()
	// .getInitParameter("systemSwift");
	// String treeNumber = request.getSession().getServletContext()
	// .getInitParameter("treeNumber");
	// String schemaId = (String) request.getSession().getValue(
	// "currentSchemaId");
	// String schema[] = new String[1];
	// schema[0] = schemaId;
	// if (smeta == null)
	// return null;
	// else
	// // else {
	// {
	// Meta[] subs = SecurityFactory.getMetaManager().getMetasByParent(
	// smeta);
	// for (int i = 0; i < subs.length; i++) {
	// if (subs[i].getSchemaValueCode().startsWith(key)) {
	// sub = subs[i];
	// break;
	// }
	// }
	// }
	// if (sub != null) {
	//
	// String xml = "";
	// if (treeNumber.equalsIgnoreCase("false")) {
	// xml = NaviXMLTreeEngine.generateNoServiceXMLTree(sub);
	// } else {
	// List list = null;
	//
	// // 档案系统
	// if (systemSwift.equalsIgnoreCase("dangan"))
	// list = NavTree.getService(sub, systemscope, username,
	// schemaId);
	// // 1.1系统
	// if (systemSwift.equalsIgnoreCase("dir"))
	// list = NavTree.getService(sub,schema);
	// xml = NaviXMLTreeEngine.generateNoServiceXMLTreeWithNumber(sub,
	// list);
	// }
	// String type = (String) request.getSession().getServletContext()
	// .getInitParameter("isDynaTree");
	// if (type.equalsIgnoreCase("true")) {
	// xml = makeTreeScript(xml, treetype, request);
	// request.getSession().setAttribute("isDynaTree", "true");
	// }
	// HashMap temp = new HashMap();
	// String realkey = sub.getSchemaValueCode() == null ? "none" : sub
	// .getSchemaValueCode();
	// temp.put(realkey, xml);
	// trees.add(temp);
	//
	// }

	// }
	// ArrayList
	// Iterator iter = ((HashMap)trees.get(0)).keySet().iterator();
	// while(iter.hasNext()){
	// String key = (String)iter.next();
	// String value = (String)((HashMap)trees.get(0)).get(key);
	// }
	// return trees;
	//
	// }

	// public static ArrayList getSchemaTreeAll(String sEname,
	// HttpServletRequest request) throws Exception {
	// ArrayList trees = new ArrayList();
	// Meta smeta = SecurityFactory.getMetaManager().getMetaByEName(sEname);
	// UserManage user = new UserManage(request.getSession());
	// String systemscope = user.getSystemscope();
	// String username = user.getUserName();
	// String systemSwift = request.getSession().getServletContext()
	// .getInitParameter("systemSwift");
	// String treeNumber = request.getSession().getServletContext()
	// .getInitParameter("treeNumber");
	// String schemaId = (String) request.getSession().getValue(
	// "currentSchemaId");
	// String schema[] = new String[1];
	// schema[0] = schemaId;
	// if (smeta == null)
	// return null;
	// else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -