1

我正在尝试使用 CPE API 从 FileNet 中文档的安全性中删除/添加组。我可以删除没有任何问题。但是,当我尝试通过从文档类继承来添加缺少的组时,会在没有完全权限的情况下添加组。例如,我删除了“作者”组,当我尝试重新添加相同的组时,它没有所有权限。

删除组:

AccessPermissionList apl = doc.get_Permissions();
Iterator iter = apl.iterator();
while (iter.hasNext())
    {
        AccessPermission ap =  (AccessPermission)iter.next();
        if(ap.get_GranteeName().contains("group name")){
            iter.remove();
        }
    }
doc.set_Permissions(apl);
doc.save(RefreshMode.NO_REFRESH);

添加组:

DocumentClassDefinition docClassDef = Factory.DocumentClassDefinition.fetchInstance(os, classID, null);
AccessPermissionList docClassApl = docClassDef.get_Permissions();
Iterator docClassApliter = docClassApl.iterator();
for(Object obj : docClassApl)
            {
                AccessPermission ap =  (AccessPermission)obj;
                if(!apl.contains(ap)){
                    apl.add(ap);
                }
            }
doc.set_Permissions(apl);
doc.save(RefreshMode.NO_REFRESH);

已解决: 必须使用 DefaultInstanceSecurity 而不是常规安全性,因为两个实例中的权限不同。所以刚刚更新了以下代码行:

AccessPermissionList docClassApl = docClassDef.get_DefaultInstancePermissions();

特性

4

1 回答 1

1

您还需要设置 AccessMask。如下所示:

AccessPermission ap;
ap.set_AccessMark ( new Integer (AccessLevel.FULL_CONTROL_DOCUMENT_AS_INT));
//AccessLevel.WRITE_DOCUMENT_AS_INT
//AccessLevel.MAJOR_VERSION_DOCUMENT_AS_INT

从 5.2.0 版本开始,AccessLevel 已弃用,但您可以尝试一下。AccessRight 现在是替代品。参考这个

更新

public static void setPermissions(Document doc) throws IOException {

    //In cpetarget.properties file
    //cpetarget.security=Administrator:FULL_CONTROL,p8admin:MODIFY_PROPERTIES

    InputStream input = new FileInputStream("cpetarget.properties");
    java.util.Properties prop = new java.util.Properties();
    prop.load(input);
    List<String> strList = new ArrayList<String>(Arrays.asList(prop.getProperty("cpetarget.security").split(",")));

    AccessPermissionList apl = doc.get_Permissions();
    Iterator<AccessPermission> itr = apl.iterator();
    List<AccessPermissionList> oldPermissionsList = new ArrayList<AccessPermissionList>();
    oldPermissionsList.addAll(apl);
    // Remove all your old permissions here
    apl.removeAll(oldPermissionsList);
    // Add all your new permissions here
    try {
        for (String str : strList) {
            String[] strArray = str.split(":");
            AccessPermission permission = Factory.AccessPermission.createInstance();
            permission.set_GranteeName(strArray[0]);
            permission.set_AccessType(AccessType.ALLOW);
            permission.set_InheritableDepth(new Integer(0));
            //permission.set_InheritableDepth(new Integer(0)); // this object only
            //permission.set_InheritableDepth(new Integer(-1));this object and all children
            //permission.set_InheritableDepth(new Integer(1)); this object and immediate children

            if (strArray[1].equalsIgnoreCase("FULL_CONTROL")) {
                permission.set_AccessMask(new Integer(AccessLevel.FULL_CONTROL_DOCUMENT_AS_INT));
                //permission.set_AccessMask(AccessRight.MAJOR_VERSION_AS_INT);
            }
            if (strArray[1].equalsIgnoreCase("READ_ONLY")) {
                permission.set_AccessMask(new Integer(AccessLevel.VIEW_AS_INT));
            }
            if (strArray[1].equalsIgnoreCase("MODIFY_PROPERTIES")) {
                permission.set_AccessMask(new Integer(AccessLevel.WRITE_DOCUMENT_AS_INT));
            }
            if (strArray[1].equalsIgnoreCase("MAJOR_VERSIONING")) {
                permission.set_AccessMask(new Integer(AccessLevel.MAJOR_VERSION_DOCUMENT_AS_INT));
            }

            AccessPermissionList permissions = doc.get_Permissions();
            permissions.add(permission);
            doc.set_Permissions(permissions);
            doc.save(RefreshMode.REFRESH);
            System.out.println("Done");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
于 2020-04-09T20:41:31.767 回答