Search in sources :

Example 1 with SysAppToken

use of com.publiccms.entities.sys.SysAppToken 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);
    }
}
Also used : SysApp(com.publiccms.entities.sys.SysApp) SysAppToken(com.publiccms.entities.sys.SysAppToken)

Example 2 with SysAppToken

use of com.publiccms.entities.sys.SysAppToken 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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysApp(com.publiccms.entities.sys.SysApp) SysAppToken(com.publiccms.entities.sys.SysAppToken) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SysAppToken

use of com.publiccms.entities.sys.SysAppToken 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;
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TemplateModel(freemarker.template.TemplateModel) SysApp(com.publiccms.entities.sys.SysApp) BaseMethod(com.publiccms.common.base.BaseMethod) SysAppToken(com.publiccms.entities.sys.SysAppToken) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysApp (com.publiccms.entities.sys.SysApp)3 SysAppToken (com.publiccms.entities.sys.SysAppToken)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BaseMethod (com.publiccms.common.base.BaseMethod)1 LogOperate (com.publiccms.entities.log.LogOperate)1 SysSite (com.publiccms.entities.sys.SysSite)1 TemplateModel (freemarker.template.TemplateModel)1 TemplateModelException (freemarker.template.TemplateModelException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1