You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.2 KiB
87 lines
3.2 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: DingTalkHttpHandlerDecorator |
|
* Author: Louis |
|
* Date: 2021/6/24 20:30 |
|
*/ |
|
package com.fr.plugin.xxxx.dingtalksyn.handler; |
|
|
|
import com.fanruan.api.log.LogKit; |
|
import com.fr.decision.fun.HttpHandler; |
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
import com.fr.decision.webservice.exception.general.NoPrivilegeException; |
|
import com.fr.plugin.xxxx.dingtalksyn.exceptions.DingTalkRequestException; |
|
import com.fr.plugin.xxxx.dingtalksyn.exceptions.DingTalkTokenEmptyException; |
|
import com.fr.plugin.xxxx.dingtalksyn.helper.DingTalkDecUserHelper; |
|
import com.fr.plugin.xxxx.dingtalksyn.utils.DingTalkAuthorityUtils; |
|
import com.fr.plugin.xxxx.dingtalksyn.utils.DingTalkLogUtil; |
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
|
import com.fr.web.utils.WebUtils; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import static com.fr.plugin.xxxx.dingtalksyn.provider.DingTalkSystemOption.DING_TALK_SYN_SYSTEM_OPTION; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <DingTalkHttpHandlerDecorator> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class DingTalkHttpHandlerDecorator extends BaseHttpHandler { |
|
private HttpHandler handler; |
|
private boolean checkModulePrivilege; |
|
|
|
public DingTalkHttpHandlerDecorator(HttpHandler handler) { |
|
this.handler = handler; |
|
this.checkModulePrivilege = true; |
|
} |
|
|
|
public DingTalkHttpHandlerDecorator(HttpHandler handler, boolean checkModule) { |
|
this.handler = handler; |
|
this.checkModulePrivilege = checkModule; |
|
} |
|
|
|
public RequestMethod getMethod() { |
|
return this.handler.getMethod(); |
|
} |
|
|
|
public String getPath() { |
|
return this.handler.getPath(); |
|
} |
|
|
|
public boolean isPublic() { |
|
return this.handler.isPublic(); |
|
} |
|
|
|
public String[] modules() { |
|
return this.checkModulePrivilege ? new String[]{DING_TALK_SYN_SYSTEM_OPTION} : new String[0]; |
|
} |
|
|
|
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
try { |
|
if (this.checkModulePrivilege && !this.handler.isPublic()) { |
|
String var3 = DingTalkDecUserHelper.getCurrentUserId(request); |
|
if (!DingTalkAuthorityUtils.hasModulePrivilege(var3, DING_TALK_SYN_SYSTEM_OPTION)) { |
|
throw new NoPrivilegeException(); |
|
} |
|
this.handler.handle(request, response); |
|
} else { |
|
this.handler.handle(request, response); |
|
} |
|
} catch (DingTalkRequestException e) { |
|
DingTalkLogUtil.error(e.getMessage(), e, 44001); |
|
WebUtils.flushFailureMessageAutoClose(request, response, 11205037, e.getMessage()); |
|
} catch (DingTalkTokenEmptyException e) { |
|
String message = "获取token失败,钉钉返回信息为:" + e.getMessage(); |
|
DingTalkLogUtil.error(message, 44002); |
|
WebUtils.flushFailureMessageAutoClose(request, response, 11205031, message); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
throw e; |
|
} |
|
} |
|
} |