use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormStructureHelperImplTest method testUpdateformStructure.
@Test
public void testUpdateformStructure() {
Resource resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container");
formStructureHelper.updateFormStructure(resource);
ValueMap properties = resource.adaptTo(ValueMap.class);
assertEquals("foundation/components/form/actions/store", properties.get("actionType", String.class));
String action = properties.get("action", String.class);
assertNotNull(action);
assertTrue(action.length() > 0);
}
use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormStructureHelperImplTest method testcanManage.
@Test
public void testcanManage() {
Resource resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/start");
assertFalse(formStructureHelper.canManage(resource));
resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container/text");
assertTrue(formStructureHelper.canManage(resource));
resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container");
assertTrue(formStructureHelper.canManage(resource));
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class JcrNodeResourceTest method testResourceSuperType.
public void testResourceSuperType() throws Exception {
String name = "resourceSuperType";
String typeNodeName = "some_resource_type";
String typeName = rootPath + "/" + typeNodeName;
Node node = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
getSession().save();
Resource jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
assertEquals(typeName, jnr.getResourceType());
// default super type is null
assertNull(jnr.getResourceSuperType());
String superTypeName = "supertype";
Node typeNode = rootNode.addNode(typeNodeName, JcrConstants.NT_UNSTRUCTURED);
typeNode.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, superTypeName);
getSession().save();
jnr = new JcrNodeResource(null, typeNode.getPath(), null, typeNode, getHelperData());
assertEquals(JcrConstants.NT_UNSTRUCTURED, jnr.getResourceType());
assertEquals(superTypeName, jnr.getResourceSuperType());
// overwrite super type with direct property
String otherSuperTypeName = "othersupertype";
node.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, otherSuperTypeName);
getSession().save();
jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
assertEquals(typeName, jnr.getResourceType());
assertEquals(otherSuperTypeName, jnr.getResourceSuperType());
// remove direct property to get supertype again
node.getProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY).remove();
getSession().save();
jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
assertEquals(typeName, jnr.getResourceType());
assertNull(jnr.getResourceSuperType());
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceAccessSecurityImpl method getReadableResource.
@Override
public Resource getReadableResource(final Resource resource) {
Resource returnValue = null;
final Iterator<ResourceAccessGateHandler> accessGateHandlers = getMatchingResourceAccessGateHandlerIterator(resource.getPath(), ResourceAccessGate.Operation.READ);
GateResult finalGateResult = null;
List<ResourceAccessGate> accessGatesForReadValues = null;
boolean canReadAllValues = false;
if (accessGateHandlers != null) {
boolean noGateMatched = true;
while (accessGateHandlers.hasNext()) {
noGateMatched = false;
final ResourceAccessGateHandler resourceAccessGateHandler = accessGateHandlers.next();
final GateResult gateResult = !resourceAccessGateHandler.getResourceAccessGate().hasReadRestrictions(resource.getResourceResolver()) ? GateResult.GRANTED : resourceAccessGateHandler.getResourceAccessGate().canRead(resource);
if (!canReadAllValues && gateResult == GateResult.GRANTED) {
if (resourceAccessGateHandler.getResourceAccessGate().canReadAllValues(resource)) {
canReadAllValues = true;
accessGatesForReadValues = null;
} else {
if (accessGatesForReadValues == null) {
accessGatesForReadValues = new ArrayList<ResourceAccessGate>();
}
accessGatesForReadValues.add(resourceAccessGateHandler.getResourceAccessGate());
}
}
if (finalGateResult == null) {
finalGateResult = gateResult;
} else if (finalGateResult != GateResult.GRANTED && gateResult != GateResult.CANT_DECIDE) {
finalGateResult = gateResult;
}
// stop checking if the operation is final and the result not GateResult.CANT_DECIDE
if (gateResult != GateResult.CANT_DECIDE && resourceAccessGateHandler.isFinalOperation(ResourceAccessGate.Operation.READ)) {
break;
}
}
// return null if access is denied or no ResourceAccessGate is present
if (finalGateResult == GateResult.DENIED) {
returnValue = null;
} else if (finalGateResult == GateResult.GRANTED) {
returnValue = resource;
} else if (noGateMatched && this.defaultAllowIfNoGateMatches) {
returnValue = resource;
}
}
boolean canUpdateResource = canUpdate(resource);
// wrap Resource if read access is not or partly (values) not granted
if (returnValue != null) {
if (!canReadAllValues || !canUpdateResource) {
returnValue = new AccessGateResourceWrapper(returnValue, accessGatesForReadValues, canUpdateResource);
}
}
return returnValue;
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceAccessSecurityImplTests method testCanUpdateUsingReadableResource.
@Test
public void testCanUpdateUsingReadableResource() {
// one needs to have also read rights to obtain the resource
initMocks("/content", new String[] { "read", "update" });
Resource resource = mock(Resource.class);
when(resource.getPath()).thenReturn("/content");
ModifiableValueMap valueMap = mock(ModifiableValueMap.class);
when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(valueMap);
when(resourceAccessGate.canRead(resource)).thenReturn(ResourceAccessGate.GateResult.GRANTED);
when(resourceAccessGate.canUpdate(resource)).thenReturn(ResourceAccessGate.GateResult.GRANTED);
Resource readableResource = resourceAccessSecurity.getReadableResource(resource);
ModifiableValueMap resultValueMap = readableResource.adaptTo(ModifiableValueMap.class);
resultValueMap.put("modified", "value");
verify(valueMap, times(1)).put("modified", "value");
}
Aggregations