public PathPattern(Path path) { super(); this.path = path; patternElements = path.getElements(); }
public PathPattern(Path path) { super(); this.path = path; patternElements = path.getElements(); }
/** * Creates a new PathBuilder and initialized it with elements of the * given path. * * @param parent */ public PathBuilder(Path parent) { this(); addAll(parent.getElements()); }
/** * Sets the relative path to the property in this relation. * * @param relPath the relative path to a property. * @throws IllegalArgumentException if <code>relPath</code> is absolute. */ public void setRelativePath(Path relPath) { if (relPath.isAbsolute()) { throw new IllegalArgumentException("relPath must be relative"); } Element[] elements = relPath.getElements(); for (Element element : elements) { addPathElement(element); } }
/** * Sets the relative path to the property in this relation. * * @param relPath the relative path to a property. * @throws IllegalArgumentException if <code>relPath</code> is absolute. */ public void setRelativePath(Path relPath) { if (relPath.isAbsolute()) { throw new IllegalArgumentException("relPath must be relative"); } Element[] elements = relPath.getElements(); for (Element element : elements) { addPathElement(element); } }
/** * Checks whether this element has the specified path. Introduced to * avoid catching a <code>MalformedPathException</code> for simple * path comparisons. * @param path path to compare to * @return <code>true</code> if this child has the path * <code>path</code>, <code>false</code> otherwise */ public boolean hasPath(Path path) { return hasPath(path.getElements(), path.getLength()); }
/** * Checks whether this element has the specified path. Introduced to * avoid catching a <code>MalformedPathException</code> for simple * path comparisons. * @param path path to compare to * @return <code>true</code> if this child has the path * <code>path</code>, <code>false</code> otherwise */ public boolean hasPath(Path path) { return hasPath(path.getElements(), path.getLength()); }
/** * Checks whether this element has the specified path. Introduced to * avoid catching a <code>MalformedPathException</code> for simple * path comparisons. * @param path path to compare to * @return <code>true</code> if this child has the path * <code>path</code>, <code>false</code> otherwise */ public boolean hasPath(Path path) { return hasPath(path.getElements(), path.getLength()); }
@Test public void testVerifyThatSessionIsUsedAsResolver() throws RepositoryException { // GIVEN DefaultACLBasedPermissions permissions = new DefaultACLBasedPermissions(list, session, null); Element element = mock(Element.class); Name name = mock(Name.class); when(element.getName()).thenReturn(name); when(itemPath.getElements()).thenReturn(new Element[]{element}); // WHEN permissions.pathResolver.getJCRPath(itemPath); // THEN verify(session).getJCRName(name); } }
protected Context match(Context input) throws RepositoryException { if (input.isExhausted()) { return input.noMatch(); } Path inputPath = input.getRemainder(); if (!inputPath.isNormalized()) { throw new IllegalArgumentException("Not normalized"); } Element[] inputElements = inputPath.getElements(); if (inputElements.length < 1 || !matches(inputElements[0])) { return input.noMatch(); } return input.match(1); }
protected Context match(Context input) throws RepositoryException { if (input.isExhausted()) { return input.noMatch(); } Path inputPath = input.getRemainder(); if (!inputPath.isNormalized()) { throw new IllegalArgumentException("Not normalized"); } Element[] inputElements = inputPath.getElements(); if (inputElements.length < 1 || !matches(inputElements[0])) { return input.noMatch(); } return input.match(1); }
@Test public void testGrants() throws RepositoryException { //GIVEN RootOnlyPermissions permissions = new RootOnlyPermissions(session); when(itemPath.getElements()).thenReturn(new Element[]{rootElement}); //WHEN boolean access = permissions.grants(itemPath, 12); //THEN assertTrue(access); }
@Test public void testPermissionClassNotDefined() throws RepositoryException { // GIVEN MagnoliaAccessProvider provider = new MagnoliaAccessProvider(); Map<Object, Object> configuration = new HashMap<Object, Object>(); provider.init(systemSession, configuration); when(itemPath.getElements()).thenReturn(new Element[]{pageElement, contentNodeElement}); // WHEN CompiledPermissions permissions = provider.compilePermissions(principals); // THEN assertTrue(permissions instanceof DefaultACLBasedPermissions); }
@Test public void testCanRead() throws RepositoryException { //GIVEN RootOnlyPermissions permissions = new RootOnlyPermissions(session); when(itemPath.getElements()).thenReturn(new Element[]{rootElement}); //WHEN boolean access = permissions.canRead(itemPath, itemId); //THEN assertTrue(access); }
@Test public void testNoRootNode() throws RepositoryException { //GIVEN RootOnlyPermissions permissions = new RootOnlyPermissions(session); when(itemPath.getElements()).thenReturn(new Element[]{pageElement}); //WHEN boolean access = permissions.grants(itemPath, 12); //THEN assertFalse(access); } }
@Test public void testCanReadOnPageNode() throws RepositoryException { //GIVEN UrlPattern urlPattern = new SimpleUrlPattern("page"); permissionImpl.setPattern(urlPattern); permissionImpl.setPermissions(info.magnolia.cms.security.Permission.READ); Map<Object, Object> configuration = new HashMap<Object, Object>(); configuration.put("permissionsClass", "info.magnolia.cms.core.NodeTypeBasedPermissions"); configuration.put("nodeTypes", MgnlNodeType.NT_PAGE); when(itemPath.getElements()).thenReturn(new Element[]{pageElement}); NodeTypeBasedPermissions permissions = new NodeTypeBasedPermissions(list, session, configuration); //WHEN boolean access = permissions.canRead(itemPath, itemId); //THEN assertTrue(access); }
@Test public void testGrantsHigherPermissionThenAssigned() throws RepositoryException { //GIVEN UrlPattern urlPattern = new SimpleUrlPattern("page"); Map<Object, Object> configuration = new HashMap<Object, Object>(); configuration.put("nodeType", MgnlNodeType.NT_PAGE); when(itemPath.getElements()).thenReturn(new Element[]{pageElement}); DefaultACLBasedPermissions permissions = new DefaultACLBasedPermissions(list, session, configuration); long convertedPermissions = permissions.convertJackrabbitPermissionsToMagnoliaPermissions(org.apache.jackrabbit.core.security.authorization.Permission.READ); permissionImpl.setPattern(urlPattern); permissionImpl.setPermissions(convertedPermissions); //WHEN boolean access = permissions.grants(itemPath, org.apache.jackrabbit.core.security.authorization.Permission.ALL); //THEN assertFalse(access); }
@Test public void testGrantsOnContentNode() throws RepositoryException { //GIVEN UrlPattern urlPattern = new SimpleUrlPattern("page"); Map<Object, Object> configuration = new HashMap<Object, Object>(); configuration.put("nodeTypes", MgnlNodeType.NT_PAGE); when(itemPath.getElements()).thenReturn(new Element[]{pageElement, contentNodeElement}); NodeTypeBasedPermissions permissions = new NodeTypeBasedPermissions(list, session, configuration); long convertedPermissions = permissions.convertJackrabbitPermissionsToMagnoliaPermissions(org.apache.jackrabbit.core.security.authorization.Permission.READ); permissionImpl.setPattern(urlPattern); permissionImpl.setPermissions(convertedPermissions); //WHEN boolean access = permissions.grants(itemPath, org.apache.jackrabbit.core.security.authorization.Permission.READ); //THEN assertTrue(access); }
@Test public void testGrantsHigherPermissionThenAssigned() throws RepositoryException { //GIVEN UrlPattern urlPattern = new SimpleUrlPattern("page"); Map<Object, Object> configuration = new HashMap<Object, Object>(); configuration.put("nodeTypes", MgnlNodeType.NT_PAGE); when(itemPath.getElements()).thenReturn(new Element[]{pageElement, contentNodeElement}); NodeTypeBasedPermissions permissions = new NodeTypeBasedPermissions(list, session, configuration); long convertedPermissions = permissions.convertJackrabbitPermissionsToMagnoliaPermissions(org.apache.jackrabbit.core.security.authorization.Permission.READ); permissionImpl.setPattern(urlPattern); permissionImpl.setPermissions(convertedPermissions); //WHEN boolean access = permissions.grants(itemPath, org.apache.jackrabbit.core.security.authorization.Permission.ALL); //THEN assertFalse(access); }
@Test public void testReorderingIsNotAllowedWithReadOnlyPermissions() throws RepositoryException { // GIVEN UrlPattern urlPattern = new SimpleUrlPattern("page"); permissionImpl.setPattern(urlPattern); permissionImpl.setPermissions(info.magnolia.cms.security.Permission.READ); when(itemPath.getElements()).thenReturn(new Element[]{pageElement}); DefaultACLBasedPermissions permissions = new DefaultACLBasedPermissions(list, session, null); // WHEN boolean isReadOnly = !permissions.grants(itemPath, org.apache.jackrabbit.core.security.authorization.Permission.ADD_NODE); boolean canReorder = permissions.grants(itemPath, org.apache.jackrabbit.core.security.authorization.Permission.MODIFY_CHILD_NODE_COLLECTION); // THEN assertTrue(isReadOnly); assertFalse(canReorder); }