use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationFilter method doFilter.
@Override
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) sr;
HttpServletResponse httpRes = (HttpServletResponse) sr1;
PageConfig config = PageConfig.get(httpReq);
long processTime = System.currentTimeMillis();
Project p = config.getProject();
if (p != null && !config.isAllowed(p)) {
LOGGER.log(Level.INFO, "access denied for uri: {0}", httpReq.getRequestURI());
config.getEnv().getStatistics().addRequest(httpReq);
config.getEnv().getStatistics().addRequest(httpReq, "requests_forbidden");
config.getEnv().getStatistics().addRequestTime(httpReq, "requests_forbidden", System.currentTimeMillis() - processTime);
httpRes.sendError(403, "Access forbidden");
return;
}
fc.doFilter(sr, sr1);
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class Results method prettyPrint.
/**
* Prints out results in html form. The following search helper fields are
* required to be properly initialized: <ul>
* <li>{@link SearchHelper#dataRoot}</li>
* <li>{@link SearchHelper#contextPath}</li>
* <li>{@link SearchHelper#searcher}</li> <li>{@link SearchHelper#hits}</li>
* <li>{@link SearchHelper#historyContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#sourceContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#summarizer} (if sourceContext is not
* {@code null})</li> <li>{@link SearchHelper#compressed} (if sourceContext
* is not {@code null})</li> <li>{@link SearchHelper#sourceRoot} (if
* sourceContext or historyContext is not {@code null})</li> </ul>
*
* @param out write destination
* @param sh search helper which has all required fields set
* @param start index of the first hit to print
* @param end index of the last hit to print
* @throws HistoryException
* @throws IOException
* @throws ClassNotFoundException
*/
public static void prettyPrint(Writer out, SearchHelper sh, int start, int end) throws HistoryException, IOException, ClassNotFoundException {
Project p;
String ctxE = Util.URIEncodePath(sh.contextPath);
String xrefPrefix = sh.contextPath + Prefix.XREF_P;
String morePrefix = sh.contextPath + Prefix.MORE_P;
String xrefPrefixE = ctxE + Prefix.XREF_P;
File xrefDataDir = new File(sh.dataRoot, Prefix.XREF_P.toString());
for (Map.Entry<String, ArrayList<Document>> entry : createMap(sh.searcher, sh.hits, start, end).entrySet()) {
String parent = entry.getKey();
out.write("<tr class=\"dir\"><td colspan=\"3\"><a href=\"");
out.write(xrefPrefixE);
out.write(Util.URIEncodePath(parent));
out.write("/\">");
// htmlize ???
out.write(parent);
out.write("/</a>");
if (sh.desc != null) {
out.write(" - <i>");
// htmlize ???
out.write(sh.desc.get(parent));
out.write("</i>");
}
JSONArray messages;
if ((p = Project.getProject(parent)) != null && (messages = Util.messagesToJson(p, RuntimeEnvironment.MESSAGES_MAIN_PAGE_TAG)).size() > 0) {
out.write(" <a ");
out.write("href=\"" + xrefPrefix + "/" + p.getName() + "\">");
out.write("<span class=\"important-note important-note-rounded\" data-messages='" + messages + "'>!</span>");
out.write("</a>");
}
out.write("</td></tr>");
for (Document doc : entry.getValue()) {
String rpath = doc.get(QueryBuilder.PATH);
String rpathE = Util.URIEncodePath(rpath);
DateFormat df;
out.write("<tr>");
Util.writeHAD(out, sh.contextPath, rpathE, false);
out.write("<td class=\"f\"><a href=\"");
out.write(xrefPrefixE);
out.write(rpathE);
out.write("\"");
if (RuntimeEnvironment.getInstance().isLastEditedDisplayMode()) {
try {
// insert last edited date if possible
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String dd = df.format(DateTools.stringToDate(doc.get("date")));
out.write(" class=\"result-annotate\" title=\"");
out.write("Last modified: ");
out.write(dd);
out.write("\"");
} catch (ParseException ex) {
LOGGER.log(Level.WARNING, "An error parsing date information", ex);
}
}
out.write(">");
// htmlize ???
out.write(rpath.substring(rpath.lastIndexOf('/') + 1));
out.write("</a>");
out.write("</td><td><tt class=\"con\">");
if (sh.sourceContext != null) {
Genre genre = Genre.get(doc.get("t"));
Definitions tags = null;
IndexableField tagsField = doc.getField(QueryBuilder.TAGS);
if (tagsField != null) {
tags = Definitions.deserialize(tagsField.binaryValue().bytes);
}
Scopes scopes;
IndexableField scopesField = doc.getField(QueryBuilder.SCOPES);
if (scopesField != null) {
scopes = Scopes.deserialize(scopesField.binaryValue().bytes);
} else {
scopes = new Scopes();
}
if (Genre.XREFABLE == genre && sh.summarizer != null) {
String xtags = getTags(xrefDataDir, rpath, sh.compressed);
// FIXME use Highlighter from lucene contrib here,
// instead of summarizer, we'd also get rid of
// apache lucene in whole source ...
out.write(sh.summarizer.getSummary(xtags).toString());
} else if (Genre.HTML == genre && sh.summarizer != null) {
String htags = getTags(sh.sourceRoot, rpath, false);
out.write(sh.summarizer.getSummary(htags).toString());
} else {
FileReader r = genre == Genre.PLAIN ? new FileReader(new File(sh.sourceRoot, rpath)) : null;
sh.sourceContext.getContext(r, out, xrefPrefix, morePrefix, rpath, tags, true, sh.builder.isDefSearch(), null, scopes);
}
}
if (sh.historyContext != null) {
sh.historyContext.getContext(new File(sh.sourceRoot, rpath), rpath, out, sh.contextPath);
}
out.write("</tt></td></tr>\n");
}
}
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationFrameworkTest method createAllowedProject.
private Project createAllowedProject() {
Project p = new Project();
p.setName("allowed" + "_" + "project" + Math.random());
return p;
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationPluginClassLoaderTest method testTruePlugin.
@Test
public void testTruePlugin() {
AuthorizationPluginClassLoader instance = new AuthorizationPluginClassLoader(pluginDirectory);
Class clazz = loadClass(instance, "org.sample.plugin.TruePlugin");
IAuthorizationPlugin plugin = getNewInstance(clazz);
Group g = new Group();
g.setName("group1");
Project p = new Project();
p.setName(("project1"));
Assert.assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), g));
Assert.assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationPluginClassLoaderTest method testFalsePlugin.
@Test
public void testFalsePlugin() {
AuthorizationPluginClassLoader instance = new AuthorizationPluginClassLoader(pluginDirectory);
Class clazz = loadClass(instance, "org.sample.plugin.FalsePlugin");
IAuthorizationPlugin plugin = getNewInstance(clazz);
Group g = new Group();
g.setName("group1");
Project p = new Project();
p.setName(("project1"));
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), g));
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Aggregations