@Test void checkPermissionWithAttachSchemeChecker() throws Exception { VfsResourceReference reference = new VfsResourceReference(URI.create("attach:whatever"), "whatever"); DocumentReference attachmentDocumentReference = new DocumentReference("wiki", "space", "page"); AttachmentReference attachmentReference = new AttachmentReference("file", attachmentDocumentReference); when(this.resolver.resolve("whatever")).thenReturn(attachmentReference); ContextualAuthorizationManager authorizationManager = this.componentManager.registerMockComponent(ContextualAuthorizationManager.class); when(authorizationManager.hasAccess(Right.VIEW, attachmentReference)).thenReturn(true); this.checker.checkPermission(reference); when(authorizationManager.hasAccess(Right.VIEW, attachmentReference)).thenReturn(false); Throwable exception = assertThrows(VfsException.class, () -> this.checker.checkPermission(reference)); assertEquals("No View permission for attachment [Attachment wiki:space.page@file]", exception.getMessage()); }
@Override public void checkPermission(VfsResourceReference resourceReference) throws VfsException { String scheme = resourceReference.getScheme(); if (HINT.equals(scheme)) { throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT)); } VfsPermissionChecker resolvedChecker; ComponentManager componentManager = this.componentManagerProvider.get(); try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme); } catch (ComponentLookupException e) { try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class); } catch (ComponentLookupException ee) { throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee); } } resolvedChecker.checkPermission(resourceReference); }
CascadingVfsPermissionChecker implements VfsPermissionChecker { @Override public void checkPermission(VfsResourceReference resourceReference) throws VfsException { String scheme = resourceReference.getScheme(); if (HINT.equals(scheme)) { throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT)); } VfsPermissionChecker resolvedChecker; ComponentManager componentManager = this.componentManagerProvider.get(); try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme); } catch (ComponentLookupException e) { try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class); } catch (ComponentLookupException ee) { throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee); } } resolvedChecker.checkPermission(resourceReference); } }
CascadingVfsPermissionChecker implements VfsPermissionChecker { @Override public void checkPermission(VfsResourceReference resourceReference) throws VfsException { String scheme = resourceReference.getScheme(); if (HINT.equals(scheme)) { throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT)); } VfsPermissionChecker resolvedChecker; ComponentManager componentManager = this.componentManagerProvider.get(); try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme); } catch (ComponentLookupException e) { try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class); } catch (ComponentLookupException ee) { throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee); } } resolvedChecker.checkPermission(resourceReference); }  }
CascadingVfsPermissionChecker implements VfsPermissionChecker { @Override public void checkPermission(VfsResourceReference resourceReference) throws VfsException { String scheme = resourceReference.getScheme(); if (HINT.equals(scheme)) { throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT)); } VfsPermissionChecker resolvedChecker; ComponentManager componentManager = this.componentManagerProvider.get(); try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme); } catch (ComponentLookupException e) { try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class); } catch (ComponentLookupException ee) { throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee); } } resolvedChecker.checkPermission(resourceReference); }  @Override void checkPermission(VfsResourceReference resourceReference); }
CascadingVfsPermissionChecker implements VfsPermissionChecker { @Override public void checkPermission(VfsResourceReference resourceReference) throws VfsException { String scheme = resourceReference.getScheme(); if (HINT.equals(scheme)) { throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT)); } VfsPermissionChecker resolvedChecker; ComponentManager componentManager = this.componentManagerProvider.get(); try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme); } catch (ComponentLookupException e) { try { resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class); } catch (ComponentLookupException ee) { throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee); } } resolvedChecker.checkPermission(resourceReference); }  @Override void checkPermission(VfsResourceReference resourceReference);  }