Search in sources :

Example 1 with SysApp

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();
    }
}
Also used : SysApp(com.publiccms.entities.sys.SysApp) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler)

Example 2 with SysApp

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

Example 3 with SysApp

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;
}
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 4 with SysApp

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

Example 5 with SysApp

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

Aggregations

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