首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将限制添加到ACL中,会为Jack兔子Oak中的查询生成空结果。

将限制添加到ACL中,会为Jack兔子Oak中的查询生成空结果。
EN

Stack Overflow用户
提问于 2019-01-20 20:37:09
回答 1查看 142关注 0票数 1

我一直在尝试通过SecurityProviderSecurityConfiguration来配置安全性,特别是我一直在使用这些限制,这些限制通常都能像预期的那样工作。但是,在处理JCR-SQL2查询时,过滤的次数比预期的要多。

详细信息

它可以在下面的存储库中复制。

代码语言:javascript
复制
/
  node          [nt:unstructured]
    subnode     [nt:unstructured]

node上,我为user添加了一个带有特权JCR_ALL的访问控制条目,并添加了对rep:glob -> ""的限制,这样user就不能访问node的任何子级。

当使用session.getNode时,它按预期工作。

  • session.getNode("/node")返回节点
  • 由于限制,session.getNode("/node/subnode")按预期抛出PathNotFoundException

但是,当我执行以下JCR-SQL2查询时:

代码语言:javascript
复制
SELECT * FROM [nt:unstructured]

我没有得到的结果,。在这里,我希望得到/node,因为在使用session.getNode时,它是可用的。

代码语言:javascript
复制
public static void main(String[] args) throws Exception {
    Repository repository = new Jcr().with(new MySecurityProvider()).createRepository();
    Session session = repository.login(new UserIdCredentials(""));    // principal is "SystemPrincipal.INSTANCE"

    // Create nodes
    Node node = session.getRootNode().addNode("node", "nt:unstructured");
    node.addNode("subnode", "nt:unstructured");

    // Add access control entry + restriction
    AccessControlManager acm = session.getAccessControlManager();
    JackrabbitAccessControlList acl = (JackrabbitAccessControlList) acm
        .getApplicablePolicies("/node").nextAccessControlPolicy();
    Privilege[] privileges = new Privilege[]{acm.privilegeFromName(Privilege.JCR_ALL)};
    Map<String, Value> restrictions = new HashMap<String, Value>() {{put("rep:glob", new StringValue(""));}};
    acl.addEntry(new PrincipalImpl("user"), privileges, true, restrictions);
    acm.setPolicy("/node", acl);
    session.save();

    // executes query
    RowIterator rows = repository.login(new UserIdCredentials("user")).getWorkspace().getQueryManager()
        .createQuery("SELECT * FROM [nt:unstructured]", Query.JCR_SQL2).execute().getRows();
        System.out.println("Number of rows: " + rows.getSize());  //Prints 0
}

如果要从上面的代码中删除restrictions,那么nodesubnode都会像预期的那样出现在查询结果中。

MySecurityProvider使用ConfigurationParameters.EMPTY和所有SecurityConfiguration的默认实现,除了我自己实现的AuthenticationConfiguration之外:

代码语言:javascript
复制
class MyAuthenticationConfiguration extends AuthenticationConfigurationImpl {
    public MyAuthenticationConfiguration(SecurityProvider securityProvider) {
        super(securityProvider);
    }

    @NotNull
    @Override
    public LoginContextProvider getLoginContextProvider(ContentRepository contentRepository) {
        return new LoginContextProvider() {
            @NotNull
            public LoginContext getLoginContext(Credentials credentials, String workspaceName) {
                String userId = ((UserIdCredentials) credentials).getUserId();
                Set<Principal> principalSets = new HashSet<>();
                if (userId.isEmpty()) {
                    principalSets.add(SystemPrincipal.INSTANCE);
                } else {
                    principalSets.add(new PrincipalImpl(userId));
                }
                Map<String, ? extends Principal> publicPrivileges = new HashMap<>();
                AuthInfoImpl authInfoImpl = new AuthInfoImpl(userId, publicPrivileges, principalSets);
                Subject subject = new Subject(true, principalSets, Collections.singleton(authInfoImpl), new HashSet<Principal>());
                return new PreAuthContext(subject);
            }
        };
    }
}

我用的是杰克兔橡木1.10.0版。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-03 20:10:13

结果发现,这是杰克-兔子橡木链接到发布中的一个bug。

这个问题在1.12.0版本时已经解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54280740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档