Search in sources :

Example 1 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Dept method getRoles.

public Set<String> getRoles(String deptId) throws HongsException {
    if (deptId == null)
        throw new HongsException(0x10000, "Dept Id required!");
    Table asoc;
    FetchCase caze;
    List<Map> rows;
    Set<String> roles = new HashSet();
    asoc = this.db.getTable("a_master_dept_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".dept_id = ?", deptId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    return roles;
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) HongsException(app.hongs.HongsException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class User method getRoles.

public Set<String> getRoles(String userId) throws HongsException {
    if (userId == null)
        throw new HongsException(0x10000, "User Id required!");
    Table asoc;
    FetchCase caze;
    List<Map> rows;
    Set<String> roles = new HashSet();
    Set<String> depts = new HashSet();
    asoc = this.db.getTable("a_master_user_dept");
    caze = this.fetchCase();
    caze.select(asoc.name + ".dept_id").filter(asoc.name + ".user_id = ?", userId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        depts.add((String) row.get("dept_id"));
    }
    asoc = this.db.getTable("a_master_dept_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".dept_id = ?", depts);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    asoc = this.db.getTable("a_master_user_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".user_id = ?", userId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    return roles;
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) HongsException(app.hongs.HongsException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class User method permit.

protected void permit(String id, Map data) throws HongsException {
    if (data != null) {
        // 权限限制, 仅能赋予当前登录用户所有的权限
        if (data.containsKey("roles")) {
            data.put("rtime", System.currentTimeMillis() / 1000);
            List list = Synt.asList(data.get("roles"));
            AuthKit.cleanUserRoles(list, id);
            if (list.isEmpty()) {
                throw new HongsException.Notice("ex.master.user.role.error").setLocalizedContext("master");
            }
            data.put("roles", list);
        }
        // 部门限制, 仅能指定当前登录用户下属的部门
        if (data.containsKey("depts")) {
            data.put("rtime", System.currentTimeMillis() / 1000);
            List list = Synt.asList(data.get("depts"));
            AuthKit.cleanUserDepts(list, id);
            if (list.isEmpty()) {
                throw new HongsException.Notice("ex.master.user.dept.error").setLocalizedContext("master");
            }
            data.put("depts", list);
        }
        // 加密密码
        data.remove("passcode");
        if (data.containsKey("password")) {
            String password = Synt.declare(data.get("password"), "");
            String passcode = Core.newIdentity();
            passcode = AuthKit.getCrypt(password + passcode);
            password = AuthKit.getCrypt(password + passcode);
            data.put("password", password);
            data.put("passcode", passcode);
        }
    }
    if (id != null) {
        // 超级管理员可操作任何用户
        ActionHelper helper = Core.getInstance(ActionHelper.class);
        String uid = (String) helper.getSessibute(Cnst.UID_SES);
        if (Cnst.ADM_UID.equals(uid)) {
            return;
        }
        // 可以操作自己
        if (uid.equals(id)) {
            return;
        }
        // 超级管理组可操作任何用户
        // 除了顶级部门和超级管理员
        Set cur = AuthKit.getUserDepts(uid);
        Set tar = AuthKit.getUserDepts(id);
        if (cur.contains(Cnst.ADM_GID) && !tar.contains(Cnst.ADM_GID) && !Cnst.ADM_UID.equals(id)) {
            return;
        }
        // 仅可以操作下级部门的用户
        Dept dept = new Dept();
        for (Object gid : cur) {
            Set cld = new HashSet(dept.getChildIds((String) gid, true));
            cld.retainAll(tar);
            if (!cld.isEmpty()) {
                return;
            }
        }
        throw new HongsException.Notice("ex.master.user.unit.error").setLocalizedContext("master");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HongsException(app.hongs.HongsException) ActionHelper(app.hongs.action.ActionHelper) List(java.util.List) HashSet(java.util.HashSet)

Example 4 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Form method makeDocument.

private Document makeDocument() throws HongsException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new HongsException.Common(e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HongsException(app.hongs.HongsException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with HongsException

use of app.hongs.HongsException in project HongsCORE by ihongs.

the class Unit method saveDocument.

private void saveDocument(String path, Document docm) throws HongsException {
    File file = new File(path);
    File fold = file.getParentFile();
    if (!fold.exists()) {
        fold.mkdirs();
    }
    TransformerFactory tf = TransformerFactory.newInstance();
    try {
        Transformer tr = tf.newTransformer();
        DOMSource ds = new DOMSource(docm);
        StreamResult sr = new StreamResult(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
        tr.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        tr.setOutputProperty(OutputKeys.METHOD, "xml");
        tr.setOutputProperty(OutputKeys.INDENT, "yes");
        tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        tr.transform(ds, sr);
    } catch (TransformerConfigurationException e) {
        throw new HongsException.Common(e);
    } catch (IllegalArgumentException e) {
        throw new HongsException.Common(e);
    } catch (TransformerException e) {
        throw new HongsException.Common(e);
    } catch (FileNotFoundException e) {
        throw new HongsException.Common(e);
    } catch (UnsupportedEncodingException e) {
        throw new HongsException.Common(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HongsException(app.hongs.HongsException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

HongsException (app.hongs.HongsException)89 Map (java.util.Map)42 HashMap (java.util.HashMap)34 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 Set (java.util.Set)15 List (java.util.List)13 File (java.io.File)11 SQLException (java.sql.SQLException)10 FileNotFoundException (java.io.FileNotFoundException)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 PreparedStatement (java.sql.PreparedStatement)8 Iterator (java.util.Iterator)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 HongsExpedient (app.hongs.HongsExpedient)7 FormSet (app.hongs.action.FormSet)7 Table (app.hongs.db.Table)7