use of com.publiccms.entities.sys.SysApp in project PublicCMS-preview by sanluan.
the class AbstractTemplateDirective method execute.
@Override
public void execute(HttpMessageConverter<Object> httpMessageConverter, MediaType mediaType, HttpServletRequest request, String callback, HttpServletResponse response) throws IOException, Exception {
HttpParameterHandler handler = new HttpParameterHandler(httpMessageConverter, mediaType, request, callback, response);
SysApp app = null;
if (needAppToken() && (null == (app = getApp(handler)) || CommonUtils.empty(app.getAuthorizedApis()) || !ArrayUtils.contains(StringUtils.split(app.getAuthorizedApis(), COMMA_DELIMITED), getName()))) {
if (null == app) {
handler.put("error", ApiController.NEED_APP_TOKEN).render();
} else {
handler.put("error", ApiController.UN_AUTHORIZED).render();
}
} else if (needUserToken() && null == getUser(handler)) {
handler.put("error", ApiController.NEED_LOGIN).render();
} else {
execute(handler);
handler.render();
}
}
use of com.publiccms.entities.sys.SysApp in project PublicCMS-preview by sanluan.
the class AppTokenDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
SysApp entity = appService.getEntity(handler.getString("appKey"));
if (null != entity) {
if (entity.getAppSecret().equalsIgnoreCase(handler.getString("appSecret"))) {
SysAppToken token = new SysAppToken(UUID.randomUUID().toString(), entity.getId(), CommonUtils.getDate());
appTokenService.save(token);
handler.put("appToken", token.getAuthToken());
} else {
handler.put("error", SECRET_ERROR);
}
} else {
handler.put("error", KEY_NOT_EXISTS);
}
}
use of com.publiccms.entities.sys.SysApp in project PublicCMS-preview by sanluan.
the class SysAppTokenAdminController method delete.
/**
* @param authToken
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("delete")
public String delete(String authToken, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
SysAppToken entity = service.getEntity(authToken);
Long userId = getAdminFromSession(session).getId();
if (null != entity) {
SysApp app = appService.getEntity(entity.getAppId());
if (null != app) {
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), app.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.delete(authToken);
logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB_MANAGER, "delete.apptoken", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysApp in project PublicCMS-preview by sanluan.
the class MethodController method method.
/**
* 接口指令统一分发
*
* @param name
* @param appToken
* @param request
* @param response
* @return result
*/
@RequestMapping("method/{name}")
public Object method(@PathVariable String name, String appToken, HttpServletRequest request, HttpServletResponse response) {
BaseMethod method = methodMap.get(name);
if (null != method) {
try {
if (method.needAppToken()) {
SysAppToken token = appTokenService.getEntity(appToken);
if (null == token) {
return NEED_APP_TOKEN_MAP;
}
SysApp app = appService.getEntity(token.getAppId());
if (null == app) {
return NEED_APP_TOKEN_MAP;
}
}
Map<String, Object> map = new HashMap<>();
String[] paramters = request.getParameterValues("paramters");
if (CommonUtils.notEmpty(paramters) && paramters.length >= method.minParamtersNumber()) {
List<TemplateModel> list = new ArrayList<>();
for (String paramter : paramters) {
list.add(getObjectWrapper().wrap(paramter));
}
map.put("result", method.exec(list));
return map;
} else if (CommonUtils.empty(paramters) && 0 == method.minParamtersNumber()) {
map.put("result", method.exec(null));
return map;
} else {
map.put(ERROR, "paramtersError");
return map;
}
} catch (TemplateModelException e) {
log.error(e.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put(ERROR, ApiController.EXCEPTION);
return map;
}
} else {
return ApiController.NOT_FOUND_MAP;
}
}
use of com.publiccms.entities.sys.SysApp in project PublicCMS-preview by sanluan.
the class SysAppAdminController method delete.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
SysApp entity = service.getEntity(id);
if (null != entity) {
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.delete(id);
entity.setAppSecret(null);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.app", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
Aggregations