权限管理对于文档来说非常,文档的权限就是一个安全锁,没有权限的人是无法获取该文件的。同样也会因为一些用户没有权限而造成读取文档的失败,这在项目中是会经常遇到的,不过这里不涉及用户因权限不够造成的问题。
import java.util.Iterator; import com.filenet.api.engine.EventActionHandler; import com.filenet.api.events.*; import com.filenet.api.util.Id; import com.filenet.api.core.*; import com.filenet.api.collection.FolderSet; import com.filenet.api.constants.*; import com.filenet.apiimpl.util.Base64; import org.apache.commons.logging.*; public class ParentageSecurityEvent implements EventActionHandler{ private static Log log = LogFactory.getLog(ParentageSecurityEvent.class); @SuppressWarnings("unused") public void onEvent(ObjectChangeEvent event, Id subId) { try{ ObjectStore os = event.getObjectStore(); Document document = (Document) event.get_SourceObject(); log.info("Verifing document :"+document.get_Name()+" ID: "+document.get_Id()); Folder folder = document.get_SecurityFolder(); if (folder.get_PathName().startsWith("/Documents")){ log.info("Setting folder parentage on document :"+ document.get_Name()+" "+document.get_Id() +" to parent folder :"+folder.get_PathName()); folder.set_InheritParentPermissions(true); folder.save(RefreshMode.NO_REFRESH); document.set_SecurityFolder(folder); }else log.debug("Not applying folder parentage security for folder :"+folder.get_PathName()); }catch (Exception e){ log.error("Security of document not changed, exception in event occurred :"+e,e); } } }
当然这些代码比较简单,下面是上面代码中一些方法的说明
Folder get_SecurityFolder()
void set_SecurityFolder(Folder value)
void set_InheritParentPermissions(java.lang.Boolean value)
void save(RefreshMode refreshMode)
更多的关于FileNet权限管理的介绍请参考http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1107wanghl/index.html