@Test public void testNotPermitted() { sourceLookup.setSource(new ImmutableMap.Builder<String, Object>() .put("format", FORMAT) .put("repository_name", REPOSITORY_NAME) .put("assets", Collections.singletonList(Collections.singletonMap("name", PATH))) .build()); when(contentPermissionChecker.isPermitted(Collections.singleton(REPOSITORY_NAME), FORMAT, BROWSE, variableSource)).thenReturn(false); assertThat(underTest.run(), is(false)); verify(contentPermissionChecker, times(1)).isPermitted(Collections.singleton(REPOSITORY_NAME), FORMAT, BROWSE, variableSource); }
@Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { log.error("Thread.sleep interruped", e); } } } }
ContentAuthPluginScript extends AbstractSearchScript { @Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { log.error("Thread.sleep interruped", e); } } } } }
ContentAuthPluginScript extends AbstractSearchScript { @Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { log.error("Thread.sleep interruped", e); } } } } ContentAuthPluginScript(final Subject subject,
                                 final ContentPermissionChecker contentPermissionChecker,
                                 final VariableResolverAdapterManager variableResolverAdapterManager,
                                 final RepositoryManager repositoryManager,
                                 final boolean contentAuthSleep); }
ContentAuthPluginScript extends AbstractSearchScript { @Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { log.error("Thread.sleep interruped", e); } } } } ContentAuthPluginScript(final Subject subject,
                                 final ContentPermissionChecker contentPermissionChecker,
                                 final VariableResolverAdapterManager variableResolverAdapterManager,
                                 final RepositoryManager repositoryManager,
                                 final boolean contentAuthSleep); @Override Object run(); }
ContentAuthPluginScript extends AbstractSearchScript { @Override public Object run() { ThreadState threadState = new SubjectThreadState(subject); threadState.bind(); try { SourceLookup sourceLookup = getSourceLookup(); String format = (String) checkNotNull(sourceLookup.get(FORMAT)); String repositoryName = (String) checkNotNull(sourceLookup.get(REPOSITORY_NAME)); VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format); @SuppressWarnings("unchecked") List<Map<String, Object>> assets = (List<Map<String, Object>>) sourceLookup.getOrDefault("assets", Collections.emptyList()); if (assets != null && !assets.isEmpty()) { Map<String, Object> asset = assets.get(0); VariableSource variableSource = variableResolverAdapter.fromSourceLookup(sourceLookup, asset); Set<String> repoNames = new HashSet<>(); repoNames.add(repositoryName); repoNames.addAll(repositoryManager.findContainingGroups(repositoryName)); return contentPermissionChecker.isPermitted(repoNames, format, BROWSE, variableSource); } return false; } finally { threadState.clear(); if (contentAuthSleep) { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException e) { log.error("Thread.sleep interruped", e); } } } } ContentAuthPluginScript(final Subject subject,
                                 final ContentPermissionChecker contentPermissionChecker,
                                 final VariableResolverAdapterManager variableResolverAdapterManager,
                                 final RepositoryManager repositoryManager,
                                 final boolean contentAuthSleep); @Override Object run(); static final String NAME; }