SecurityProviderJackrabbit Oak を使用して、およびsを使用してセキュリティを構成しようとしましたSecurityConfiguration。特に、通常は期待どおりに機能する制限を使用しています。ただし、JCR-SQL2クエリを処理する場合、予想よりも多くのものが除外されます。
詳細
以下のリポジトリで再現できます。
/
node [nt:unstructured]
subnode [nt:unstructured]
に、 の子にアクセスできないように、->の制限とともに特権を持つアクセス制御エントリnodeを追加します。JCR_ALLuserrep:glob""usernode
を使用すると、期待どおりに機能しsession.getNodeます。
session.getNode("/node")ノードを返しますsession.getNode("/node/subnode")PathNotFoundException制限により、期待どおりにスローされます。
ただし、次の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上記のコードから1 つを削除すると、予想どおりクエリ結果にnodeとの両方が表示されます。subnode
MySecurityProvider私が自分で実装したものを除いて、すべての s の使用ConfigurationParameters.EMPTYとデフォルトの実装:SecurityConfigurationAuthenticationConfiguration
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 を使用しています