首页 > 解决方案 > 向 ACL 添加限制会在 Jackrabbit Oak 中的查询产生空结果

问题描述

使用 Jackrabbit Oak,我一直在尝试通过SecurityProviderSecurityConfigurations 配置安全性。特别是,我一直在使用通常按预期工作的限制。但是,在处理JCR-SQL2查询时,过滤掉的内容比预期的要多。

细节

可以使用下面的存储库复制它。

/
  node          [nt:unstructured]
    subnode     [nt:unstructured]

在 上node,我添加了一个具有权限的访问控制条目以及JCR_ALL- >user的限制,这样就无法访问.rep:glob""usernode

使用时按预期工作session.getNode

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

SELECT * FROM [nt:unstructured]

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

代码

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要从上面的代码中删除一个,则node和都会subnode按预期出现在查询结果中。

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

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);
            }
        };
    }
}

我正在使用 Jackrabbit Oak 1.10.0 版

标签: securityjcrjackrabbitjcr-sql2jackrabbit-oak

解决方案


这原来是 Jackrabbit Oak- Link 中的一个错误问题

从 1.12.0 版开始,此问题已得到解决


推荐阅读