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