Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /
- node [nt:unstructured]
- subnode [nt:unstructured]
- SELECT * FROM [nt:unstructured]
- 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
- }
- 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);
- }
- };
- }
- }
Add Comment
Please, Sign In to add comment