use of app.hongs.Core in project HongsCORE by ihongs.
the class ActsAction method service.
/**
* 服务方法
* Servlet Mapping: *.act<br/>
* 注意: 不支持请求URI的路径中含有"."(句点), 且必须区分大小写;
* 其目的是为了防止产生多种形式的请求路径, 影响动作过滤, 产生安全隐患.
*
* @param req
* @param rsp
* @throws javax.servlet.ServletException
*/
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException {
String act = ActionDriver.getRecentPath(req);
Core core = ActionDriver.getActualCore(req);
ActionHelper helper = core.get(ActionHelper.class);
Core.THREAD_CORE.set(core);
if (act == null || act.length() == 0) {
senderr(helper, 0x1104, null, "Action URI can not be empty.", "");
return;
}
// 去掉根和扩展名
act = act.substring(1);
int pos = act.lastIndexOf('.');
if (pos != -1)
act = act.substring(0, pos);
// 获取并执行动作
try {
ActionRunner runner = new ActionRunner(helper, act);
runner.doAction();
} catch (ClassCastException ex) {
// 类型转换失败按 400 错误处理
senderr(helper, new HongsException(0x1100, ex));
} catch (HongsException ex) {
senderr(helper, ex);
} catch (HongsExpedient ex) {
senderr(helper, ex);
} catch (HongsError ex) {
senderr(helper, ex);
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class AuthAction method service.
/**
* 服务方法
* 判断配置和消息有没有生成, 如果没有则生成; 消息按客户语言存放
* @param req
* @param rsp
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
// 受是否登录、不同用户等影响, 权限经常变化,必须禁止缓存
rsp.setHeader("Expires", "0");
rsp.addHeader("Pragma", "no-cache");
rsp.setHeader("Cache-Control", "no-cache");
Core core = ActionDriver.getActualCore(req);
ActionHelper helper = core.get(ActionHelper.class);
String name = req.getPathInfo();
if (name == null || name.length() == 0) {
helper.error400("Path info required");
return;
}
int p = name.lastIndexOf('.');
if (p < 0) {
helper.error400("File type required");
return;
}
String type = name.substring(1 + p);
name = name.substring(1, p);
if (!"js".equals(type) && !"json".equals(type)) {
helper.error400("Wrong file type: " + type);
return;
}
String s;
try {
NaviMap sitemap = NaviMap.getInstance(name);
Set<String> authset = sitemap.getAuthSet();
// 没有设置 rsname 的不公开
if (null == sitemap.session) {
helper.error404("Auth data for '" + name + "' is not open to the public");
return;
}
Map<String, Boolean> datamap = new HashMap();
if (null == authset)
authset = new HashSet();
for (String act : sitemap.actions) {
datamap.put(act, authset.contains(act));
}
s = Data.toString(datamap);
} catch (HongsException | HongsExpedient | HongsError ex) {
if (ex.getErrno() == 0x10e0) {
helper.error404(ex.getMessage());
} else {
helper.error500(ex.getMessage());
}
return;
}
// 输出权限信息
if ("json".equals(type)) {
helper.print(s, "application/json");
} else {
String c = req.getParameter("callback");
if (c != null && c.length() != 0) {
if (!c.matches("^[a-zA-Z_\\$][a-zA-Z0-9_]*$")) {
helper.error400("Illegal callback function name!");
return;
}
helper.print("function " + c + "() { return " + s + "; }", "text/javascript");
} else {
helper.print("if(!self.HsAUTH)self.HsAUTH={};Object.assign(self.HsAUTH," + s + ");", "text/javascript");
}
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class SearchEntity method getInstance.
/**
* 获取实例
* 存储为 conf/form 表单为 conf.form
* 表单缺失则尝试获取 conf/form.form
* 实例生命周期将交由 Core 维护
* @param conf
* @param form
* @return
* @throws HongsException
*/
public static SearchEntity getInstance(String conf, String form) throws HongsException {
String code = SearchEntity.class.getName() + ":" + conf + "." + form;
Core core = Core.getInstance();
if (!core.containsKey(code)) {
String path = conf + "/" + form;
String name = conf + "." + form;
String cxnf = FormSet.hasConfFile(path) ? path : conf;
Map fxrm = FormSet.getInstance(cxnf).getForm(form);
// 表单配置中可指定数据路径
Map c = (Map) fxrm.get("@");
if (c != null) {
String p;
p = (String) c.get("data-path");
if (null != p && 0 < p.length()) {
path = p;
}
p = (String) c.get("data-name");
if (null != p && 0 < p.length()) {
name = p;
}
}
SearchEntity inst = new SearchEntity(fxrm, path, name);
core.put(code, inst);
return inst;
} else {
return (SearchEntity) core.got(code);
}
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class Sesion method getRecord.
private static IRecord<Sesion> getRecord() throws HongsException {
String cls = CoreConfig.getInstance().getProperty("core.normal.sesion.model");
if (null == cls || 0 == cls.length()) {
cls = Recs.class.getName();
// 缺失则用私有类构造一个
Core core = Core.getInstance();
if (!core.containsKey(cls)) {
Recs rec = new Recs();
core.put(cls, rec);
return rec;
}
}
return (IRecord<Sesion>) Core.getInstance(cls);
}
use of app.hongs.Core in project HongsCORE by ihongs.
the class RoleSet method getInstance.
// ** 构造工厂方法 **/
public static RoleSet getInstance(String userId) throws HongsException {
String k = RoleSet.class.getName() + ":" + userId;
Core c = Core.getInstance();
if (c.containsKey(k)) {
return (RoleSet) c.get(k);
}
RoleSet s = new RoleSet(userId);
if (s.rtime == 0) {
// 状态不对
s = null;
}
// 缓存对象
c.put(k, s);
return s;
}
Aggregations