use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class UserWhiteListPluginTest method shouldNotAllowRandomUserForAnyProject.
@ParameterizedTest
@MethodSource("parameters")
public void shouldNotAllowRandomUserForAnyProject(String param) {
init(param);
plugin.load(validPluginParameters);
DummyHttpServletRequest req = new DummyHttpServletRequest();
req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8)));
Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
boolean projectAllowed = plugin.isAllowed(req, randomProject);
assertFalse(projectAllowed, "should not allow random user for random project 1");
randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
projectAllowed = plugin.isAllowed(req, randomProject);
assertFalse(projectAllowed, "should not allow random user for random project 2");
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class LdapUserPluginTest method testNegativeCache.
@Test
void testNegativeCache() throws LdapException {
AbstractLdapProvider mockprovider = mock(LdapFacade.class);
when(mockprovider.lookupLdapContent(isNull(), isNull(), any(String[].class))).thenReturn(null);
Map<String, Object> params = getParamsMap();
params.put(LdapUserPlugin.ATTRIBUTES, "mail");
params.put(LdapUserPlugin.USE_DN, false);
LdapUserPlugin origPlugin = new LdapUserPlugin();
LdapUserPlugin plugin = Mockito.spy(origPlugin);
plugin.load(params, mockprovider);
assertSame(mockprovider, plugin.getLdapProvider());
HttpServletRequest dummyRequest = new DummyHttpServletRequestLdap();
User user = new User("foo@example.com", "id");
dummyRequest.setAttribute(UserPlugin.REQUEST_ATTR, new User("foo", "123"));
plugin.fillSession(dummyRequest, user);
assertNotNull(dummyRequest.getSession().getAttribute(SESSION_ATTR));
assertFalse(plugin.isAllowed(dummyRequest, new Project("foo")));
assertFalse(plugin.isAllowed(dummyRequest, new Group("bar")));
// Make sure that the session was filled so that the second call to isAllowed() did not fill it again.
verify(plugin, times(2)).updateSession(eq(dummyRequest), anyString(), anyBoolean());
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class UserPluginTest method testTimeoutedUser.
@Test
public void testTimeoutedUser() {
HttpServletRequest req;
assertFalse(plugin.isAllowed(req = createRequest("007", true), new Group()));
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
assertFalse(plugin.isAllowed(req = createRequest("008", true), new Project()));
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
assertFalse(plugin.isAllowed(req = createRequest("009", true), createGroup("some group")));
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
assertFalse(plugin.isAllowed(req = createRequest("00A", true), createProject("some project")));
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationEntity method processTargetGroupsAndProjects.
/**
* Discover all targeted groups and projects for every group given by
* {@link #forGroups()}.
*
* <ul>
* <li>add to the {@link #forGroups()} all groups which are descendant
* groups to the group</li>
* <li>add to the {@link #forGroups()} all groups which are parent groups to
* the group</li>
* <li>add to the {@link #forProjects()} all projects and repositories which
* are in the descendant groups or in the group itself</li>
* <li>issue a warning for non-existent groups</li>
* <li>issue a warning for non-existent projects</li>
* </ul>
*/
protected void processTargetGroupsAndProjects() {
Set<String> groups = new TreeSet<>();
for (String x : forGroups()) {
/**
* Full group discovery takes place here. All projects/repositories
* in the group are added into "forProjects" and all subgroups
* (including projects/repositories) and parent groups (excluding
* the projects/repositories) are added into "forGroups".
*
* If the group does not exist then a warning is issued.
*/
Group g;
if ((g = Group.getByName(x)) != null) {
forProjects().addAll(g.getAllProjects().stream().map(Project::getName).collect(Collectors.toSet()));
groups.addAll(g.getRelatedGroups().stream().map(Group::getName).collect(Collectors.toSet()));
groups.add(x);
} else {
LOGGER.log(Level.WARNING, "Configured group \"{0}\" in forGroups section" + " for name \"{1}\" does not exist", new Object[] { x, getName() });
}
}
setForGroups(groups);
forProjects().removeIf((t) -> {
/**
* Check the existence of the projects and issue a warning if there
* is no such project.
*/
Project p;
if ((p = Project.getByName(t)) == null) {
LOGGER.log(Level.WARNING, "Configured project \"{0}\" in forProjects" + " section for name \"{1}\" does not exist", new Object[] { t, getName() });
return true;
}
return false;
});
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetResourceFileList.
/**
* Testing the root of /xref for authorization filtering.
*/
@Test
public void testGetResourceFileList() {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
// backup original values
String oldSourceRootPath = env.getSourceRootPath();
AuthorizationFramework oldAuthorizationFramework = env.getAuthorizationFramework();
Map<String, Project> oldProjects = env.getProjects();
// Set up the source root directory containing some projects.
env.setSourceRoot(repository.getSourceRoot());
env.setProjectsEnabled(true);
// Enable projects.
for (String file : new File(repository.getSourceRoot()).list()) {
Project proj = new Project(file);
proj.setIndexed(true);
env.getProjects().put(file, proj);
}
HttpServletRequest req = createRequest("/source", "/xref", "");
PageConfig cfg = PageConfig.get(req);
List<String> allFiles = new ArrayList<>(cfg.getResourceFileList());
/**
* Check if there are some files (the "5" here is just a sufficient
* value for now which won't break any future repository tests) without
* any authorization.
*/
assertTrue(allFiles.size() > 5);
assertTrue(allFiles.contains("git"));
assertTrue(allFiles.contains("mercurial"));
/**
* Now set up the same projects with authorization plugin enabling only
* some of them.
* <pre>
* - disabling "git"
* - disabling "mercurial"
* </pre>
*/
env.setAuthorizationFramework(new AuthorizationFramework());
env.getAuthorizationFramework().reload();
env.getAuthorizationFramework().getStack().add(new AuthorizationPlugin(AuthControlFlag.REQUIRED, new TestPlugin() {
@Override
public boolean isAllowed(HttpServletRequest request, Project project) {
return !project.getName().startsWith("git") && !project.getName().startsWith("mercurial");
}
}));
req = createRequest("/source", "/xref", "");
cfg = PageConfig.get(req);
List<String> filteredFiles = new ArrayList<>(cfg.getResourceFileList());
// list subtraction - retains only disabled files
allFiles.removeAll(filteredFiles);
assertEquals(2, allFiles.size());
assertTrue(allFiles.contains("git"));
assertTrue(allFiles.contains("mercurial"));
// restore original values
env.setAuthorizationFramework(oldAuthorizationFramework);
env.setSourceRoot(oldSourceRootPath);
env.setProjects(oldProjects);
}
Aggregations