You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/11/04 10:05:21 UTC

[sling-site] branch feature/order-resources created (now 9745d8e)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a change to branch feature/order-resources
in repository https://gitbox.apache.org/repos/asf/sling-site.git.


      at 9745d8e  SLING-7975 document ordering of resources

This branch includes the following new commits:

     new 9745d8e  SLING-7975 document ordering of resources

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-site] 01/01: SLING-7975 document ordering of resources

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/order-resources
in repository https://gitbox.apache.org/repos/asf/sling-site.git

commit 9745d8e49d2ab9740dba4d5d206904b9c083f6db
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Nov 4 11:05:09 2021 +0100

    SLING-7975 document ordering of resources
---
 .../bundles/resource-access-security.md            | 84 +++++++++++-----------
 .../the-sling-engine/sling-api-crud-support.md     | 54 +++++++++-----
 2 files changed, 77 insertions(+), 61 deletions(-)

diff --git a/src/main/jbake/content/documentation/bundles/resource-access-security.md b/src/main/jbake/content/documentation/bundles/resource-access-security.md
index f19e9f5..d2eb89e 100644
--- a/src/main/jbake/content/documentation/bundles/resource-access-security.md
+++ b/src/main/jbake/content/documentation/bundles/resource-access-security.md
@@ -3,52 +3,41 @@ type=page
 status=published
 tags=security
 ~~~~~~
-Notice:    Licensed to the Apache Software Foundation (ASF) under one
-           or more contributor license agreements.  See the NOTICE file
-           distributed with this work for additional information
-           regarding copyright ownership.  The ASF licenses this file
-           to you under the Apache License, Version 2.0 (the
-           "License"); you may not use this file except in compliance
-           with the License.  You may obtain a copy of the License at
-           .
-             http://www.apache.org/licenses/LICENSE-2.0
-           .
-           Unless required by applicable law or agreed to in writing,
-           software distributed under the License is distributed on an
-           "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-           KIND, either express or implied.  See the License for the
-           specific language governing permissions and limitations
-           under the License.
 
-## Summary
-The ResourceAccessSecurity service allows it to restrict access to resources. The access can be granted or denied for read, create, update and delete actions.
+# Summary
+The `ResourceAccessSecurity` service allows to restrict access to resources. The access can be granted or denied for read, create, update, delete and order resources actions.
 
-The ResourceAccessSecurity defines a service API which is used in two different context: for securing resource providers which have no own access control and on the application level to further restrict the access to resources in general. 
+The `ResourceAccessSecurity` interface defines a service API which is used in two different context: 
 
-A resource access security service is registered with the service property “context”. Allowed values are “application” and “provider”. If the value is missing or invalid, the service will be ignored. 
+1. for securing resource providers which have no own access control and 
+2. on the application level to further restrict the access to resources in general. 
 
-In the context of resource providers, this service might be used for implementations of resource providers where the underlying persistence layer does not implement access control. The goal is to make it easy to implement a lightweight access control for such providers. For example, a JCR resource providers should not use the provider context resource access security - in a JCR context, security is fully delegated to the underlying repository, and mixing security models would be a bad idea. 
+A resource access security service is registered with the service property `context`. Allowed values are `application` and `provider`. If the value is missing or invalid, the service will be ignored. 
 
-In the context of the application, this service might be used to add additional or temporary constraints across the whole resource tree. 
+In the context of resource providers, this service might be used for those  providers where the underlying persistence layer does not implement access control. The goal is to make it easy to implement a lightweight access control for such providers. On the other hand a JCR resource providers should not use the provider context resource access security - in a JCR context, security is fully delegated to the underlying repository, and mixing security models would be a bad idea. 
 
-## How to use ResourceAccessSecurity
-To use the ResourceAccessSecurity service you don’t have to implement the interface ResourceAccessSecurity. Simply add the resourceaccesssecurity bundle to your sling instance. This adds an implementation of the ResourceAccessSecurity service for the provider context (“provider”) and also the application context (“application”).
+In the context of the application, this service might be used to add additional or temporary constraints across the whole resource tree. It is automatically called by the Resource Resolver implementation.
 
-Furthermore the implementation of ResourceAccessSecurity defines a service provider interface named ResourceAccessGate. This is the service interface which you can implement and register to control the access to the resources.
+# Default Implementation
 
-The ResourceAccessGate defines a service API which can be used to make some restrictions to accessing resources. Implementations of this service interface must be registered like ResourceProvider with a path (like provider.roots but with the property name “path”). If different ResourceAccessGate services match a path, not only the ResourceAccessGate with the longest path will be called, but all of them, that's in contrast to the ResourceProvider, but in this case more logical (and secure [...]
+To use the `ResourceAccessSecurity` service just rely on the default implementation provided by the [`resourceaccesssecurity `bundle][resourceaccesssecurity]. This adds an implementation of the `ResourceAccessSecurity` service for the provider context (“provider”) and also the application context (“application”).
 
-### Service properties
+Furthermore this implementation of `ResourceAccessSecurity` defines a service provider interface (SPI) named `ResourceAccessGate`. This is the service interface which you can implement and register to control the access to particular resources.
 
-Property name     |  description
------------------ | ----------------------- 
-Path              | regexp to define on which paths the service should be called (default .*) 
-operations        | set of operations on which the service should be called ("read,create,update,delete,execute", default all of them) 
-finaloperations   | set of operations on which the service answer is final and no further service should be called (default none of them), except the GateResult is GateResult.CANT_DECIDE 
-context           | “provider” or “application”. The resource access gate can either have the context “provider”, in this case the gate is only applied to resource providers requesting the security checks. Or the context can be “application”. In this case the access gate is invoked for the whole resource tree. This is indicated by the required service property “context”. If the property is missing or invalid, the service is ignored.
+The `ResourceAccessGate` interface defines an SPI which can be used to make some restrictions for accessing resources. Implementations of this service interface must be registered like `ResourceProvider`s with a path (like `provider.roots` but with the property name `path`). If multiple `ResourceAccessGate` services match a path, not only the `ResourceAccessGate` with the longest path will be called, but all of them. That is different from the ResourceProvider logic, but in this case mor [...]
 
-### How to implement ResourceAccessGate
-The implementation is straightforward. The easiest way is to extend ` AllowingResourceAccessGate ` which is exported by the resourceaccesssecurity bundle and does not deny any access. So if you wan’t restrict access on resources for read operations you have to implement to following two methods:
+## Service properties for `ResourceAccessGate` services
+
+Name     |  Description | Default 
+----------------- | -------------| ----- 
+`path`              | regexp to define on which paths the service should be called | `.*` 
+`operations`        | set of operations on which the service should be called. Allowed string values: `read`,`create`,`update`,`delete`,`execute`,`order-children`. The value `order-children` is only supported since version 1.2.0 ([SLING-7975](https://issues.apache.org/jira/browse/SLING-7975)) | `{ "read","create","update","delete","execute","order-children"}` (all operations)
+`finaloperations`   | set of operations on which the service answer is final and no further service should be called, except the GateResult is GateResult.CANT_DECIDE. Allows the same values as `operations`. | (none)
+`context`          | The resource access gate can either have the context `provider`. In this case the gate is only applied to resource providers requesting the security checks. Or the context can be `application`. In this case the access gate is invoked for the whole resource tree. If the property is missing or invalid, the service is ignored. | -
+
+## How to implement `ResourceAccessGate`
+
+The implementation is straightforward: The easiest way is to extend ` AllowingResourceAccessGate ` which is exported by the `resourceaccesssecurity` bundle and does not deny any access. So if you want to restrict access on resources for read operations you have to implement to following two methods:
 
 	::java
 	@Override
@@ -69,18 +58,27 @@ The implementation is straightforward. The easiest way is to extend ` AllowingRe
 		return returnValue;
 	}
 	
-And you have to register the ResourceAccessGate with the path where you wan’t to restrict access and the operation property set to “read”. Furthermore you have to decide if the ResourceAccessGate should operate on all resource providers (context=”application”) or only on the resourceproviders flagged with the property useResourceAccessSecurity=true (context=”provider”).
+You have to register the `ResourceAccessGate` with service properties outlined above.
 
 Tip: We do not recommend to mix up application and provider context in the same application. This can lead to confusing configurations in the ResourceAccessGate implementations.
 
-### GateResult
+## GateResult
 GateResult does have three states:
 
-  - GateResult.GRANTED
-  - GateResult.DENIED
-  - GateResult.CANT_DECIDE
+  1. `GateResult.GRANTED`
+  2. `GateResult.DENIED`
+  3. `GateResult.CANT_DECIDE`
+
+The first two of them are self-explanatory. `CANT_DECIDE` means that the actual gate neither can grant nor deny the access. If no other gate does return `GRANTED` or `DENIED` the access to the resource will be denied for security reasons. `CANT_DECIDE` comes handy if you declare `finaloperations` (where no other gate will be called after this gate). If such a gate returns `CANT_DECIDE`, further gates will be called regardless of the `finaloperations` property.
+
+## `ResourceAccessGates` Implementations
+
+There is an implementation of `ResourceAccessGate` provided by [bundle `org.apache.sling.jcr.resourcesecurity`][jcr-resourcesecurity] which grants/denies access based on the permissions set on a JCR node. *This should only be used for paths not provided by the JCR Resource Provider*. It is implemented as service factory so each OSGi configuration provides a dedicated `ResourceAccessGate` service.
+
+## Limitations
+
+By now the implementation is complete for securing access on resource level for CRUD operations. It is not yet ready to allow fine granular access rights on values of a resource. So at the moment the `canReadValue, canUpdateValue, canDeleteValue` and `canCreateValue` on `ResourceAccessGate` methods are ignored ([SLING-10906](https://issues.apache.org/jira/browse/SLING-10906)).
 
-The first two of them are self-explanatory. CANT_DECIDE means that the actual gate neither can grant nor deny the access. If no other gate does return GRANTED or DENIED the access to the resource will be denied for security reasons. CANT-DECIDE comes handy if you declare finaloperations (where no other gate will be called after this gate). If such a gate returns CANT_DECIDE, further gates will be called regardless of the setted finaloperations property.
 
-## Actual state of ResourceAccessSecurity
-By now the implementation is complete for securing access on resource level for CRUD operations. It is not yet ready to allow fine granular access rights on values of a resource. So at the moment the `canReadValue, canUpdateValue, canDeleteValue` and `canCreateValue` on `ResourceAccessGate` methods are ignored.
+[jcr-resourcesecurity]: https://github.com/apache/sling-org-apache-sling-jcr-resourcesecurity
+[resourceaccesssecurity]: https://github.com/apache/sling-org-apache-sling-resourceaccesssecurity
\ No newline at end of file
diff --git a/src/main/jbake/content/documentation/the-sling-engine/sling-api-crud-support.md b/src/main/jbake/content/documentation/the-sling-engine/sling-api-crud-support.md
index 3d6fd1e..daa887c 100644
--- a/src/main/jbake/content/documentation/the-sling-engine/sling-api-crud-support.md
+++ b/src/main/jbake/content/documentation/the-sling-engine/sling-api-crud-support.md
@@ -6,24 +6,25 @@ tags=api,core
 
 [TOC]
 
-## Apache Sling API Support
+# Apache Sling API Support
 
 As of version 2.3.0, the Sling API provides full Create Read Update Delete (CRUD) features.  CRUD support is provided by the addition of the following methods to the ResourceResolver:
 
- * [void delete(Resource resource) throws PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#delete-org.apache.sling.api.resource.Resource-)
- * [Resource create(Resource parent, String name, Map<String, Object> properties) throws PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#create-org.apache.sling.api.resource.Resource-java.lang.String-java.util.Map-)
- * [void revert()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#revert--)
- * [void commit() throws PersistenceException](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#commit--)
- * [boolean hasChanges()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#hasChanges--)
- * [void refresh()](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#refresh--)
+ * [`void delete(Resource resource) throws PersistenceException`](https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html#delete-org.apache.sling.api.resource.Resource-)
+ * [`Resource create(Resource parent, String name, Map<String, Object> properties) throws PersistenceException`](https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html#create-org.apache.sling.api.resource.Resource-java.lang.String-java.util.Map-)
+ * [`void revert()`](https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html#revert--)
+ * [`void commit()` throws PersistenceException](https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html#commit--)
+ * [`boolean hasChanges()`](https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html#hasChanges--)
+ * [`void refresh()`](https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html#refresh--)
+ * `orderBefore(Resource parent, String name, String followingSiblingName) throws UnsupportedOperationException, PersistenceException, IllegalArgumentException`(since [API 2.24.0](https://issues.apache.org/jira/browse/SLING-7975))
  
-Which provide the ability to create and delete resources as well as the addition of the ModifiableValueMap interface which is similar to the ValueMap interface, but allows for updating properties on a resource.
+Those methods provide the ability to create and delete resources as well. In addition you can adapt a `Resource` to a `ModifiableValueMap` interface which is similar to the `ValueMap` interface, but allows for updating properties on a resource.
 
-## Comparing Sling API CRUD to Sling Post Servlet
+# Examples
 
 Here are some examples of common operations performed using the Sling Post Servlet and Sling API CRUD support.  Note, the examples are derived from the cheat sheet in Adobe's AEM documentation at [https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/developing/full-stack/sling-cheatsheet.html](https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/developing/full-stack/sling-cheatsheet.html).
 
-### Updating a Property
+## Updating a Property
 
 Update /myresource, setting the title and body:
 
@@ -42,7 +43,7 @@ Update /myresource, setting the title and body:
     properties.put("body", {BODY});
     resourceResolver.commit();
     
-### Create New Resource
+## Create New Resource
 
 Create a new resource below /myresource
 
@@ -61,7 +62,7 @@ Create a new resource below /myresource
     Resource dummy = resourceResolver.create(myResource, "dummy", properties);
     resourceResolver.commit();
 
-### Remove a Property
+## Remove a Property
 
 Remove the property title
 
@@ -78,7 +79,7 @@ Remove the property title
     properties.remove("title");
     resourceResolver.commit();
 
-### Copy a Resource
+## Copy a Resource
 
 Copy the resource /myresource to /myresource2
 
@@ -96,7 +97,7 @@ Copy the resource /myresource to /myresource2
     Resource myResource2 = resourceResolver.create(null, "myresource2", properties);
     resourceResolver.commit();
 
-### Move a Resource
+## Move a Resource
 
 Move the resource /myresource2 to /myresource3
 
@@ -115,7 +116,7 @@ Move the resource /myresource2 to /myresource3
     resourceResolver.delete(myResource2);
     resourceResolver.commit();
 
-### Setting non-String Value
+## Setting non-String Value
 
 Set the property date to a particular date
 
@@ -134,7 +135,7 @@ Set the property date to a particular date
     properties.put("date", calendar);
     resourceResolver.commit();
 
-### Delete a Resource
+## Delete a Resource
 
 Delete the resource /myresource
 
@@ -150,14 +151,31 @@ Delete the resource /myresource
     resourceResolver.delete(myResource);
     resourceResolver.commit();
 
-## Value Class Support
+## Order a Resource
+
+Delete the resource /myresource
+
+**Sling Post Servlet**
+
+    <form action="/myresource" method="POST">
+      <input type="hidden" name=":order" value="before child1">
+    </form>
+    
+**Sling API CRUD**
+    
+    Resource myResource = resourceResolver.getResource("/myresource");
+    resourceResolver.orderBefore(myResource, "child2", "child1");
+    resourceResolver.commit();
+
+
+# Value Class Support
 
 
 <div class="info">
 	Please note, this information is specific to the Sling JCR Resource implementation provided by the Apache Sling project.  Other implementations may have different value class support.  
 </div>
 
-The Classes implementing the following types are supported directly when setting properties:
+The classes implementing the following types are supported directly when setting properties:
 
  * [Calendar](http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html)
  * [InputStream](http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html)