<< Click to Display Table of Contents >> 定制邮件发送复制链接 |
查看报告里,打开一张报告,发送邮件;或调度任务里,新建发送邮件的任务,可以自定义类MailChecker接口中的方法来实现一些特殊的场景。
➢例如:
如果用户A发邮件给用户B,需要检测用户B是否有访问报告的权限。
如果用户B在永洪用户系统里,则检测报告读权限,如果没有读权限,则发送不成功。
如果用户B不在永洪用户系统里,则发送不成功(也可改为发送成功)。
实现类:
/*
* Copyright 2011 Yonghong Technology Corp, Inc. All rights reserved.
* Yonghong Technology Corp PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
import g5.db.rep.DBRep;
import g5.common.rep.AssetRef;
import g5.common.secure.Access;
import g5.common.secure.GPrincipal;
import g5.common.secure.IPrincipal;
import g5.secure.SecureServ;
import g5.db.util.DBUtil;
import g5.util.Util;
import g5.db.util.MailChecker;
import java.util.*;
import java.lang.StringBuilder;
/**
* DefDBMailChecker, check the email the dashboard is allow or not.
* @author Yonghong Technology Corp, Inc.
*/
public class DefDBMailChecker implements MailChecker {
/**
* Check the input is valid or not.
* If invalid should throw runtime exception with the error message.
*/
public CheckResult check(AssetRef ref, IPrincipal tiggerUser, String toAddrs, String ccAddrs,
String job)
{
if(ref == null) {
return null;
}
boolean result = true;
String msg = "验证通过";
try {
toAddrs = check(ref, toAddrs);
ccAddrs = check(ref, ccAddrs);
}
catch(Exception ex) {
result = false;
msg = "验证失败";
}
return new CheckResult(toAddrs,ccAddrs,result,msg);
}
/**
* Check the user is valid or not.
*/
private String check(AssetRef ref, String addr) throws Exception {
DBRep rep = DBRep.get();
HashSet<GPrincipal> sends = new HashSet<GPrincipal>();
System.err.println("check before addr:___ " + addr);
addr = DBUtil.trimUserSender(addr, sends);
StringBuilder sb = new StringBuilder();
int i = 0;
for(GPrincipal user : sends) {
SecureServ.get().authentication().authenticate(user);
if(rep.checkFilter(ref, user, Access.R, false)) {
if(i > 0) {
sb.append(";");
}
sb.append(user.name());
i++;
}
}
System.err.println("check after addr:___ " + addr + ", naddr=" + sb);
if(!Util.isEmptyString(addr)) {
throw new Exception("Not allow to send email to external address");
}
return sb.length() == 0 ? null : sb.toString();
}
}
编译此java文件,将其放入C节点的Classpath中,重启BI服务,或配置热加载目录,不重启BI服务器,参考热加载章节。