Skip to content

Commit 7dc359f

Browse files
author
Vladimir Kotal
committed
allow RESTful API
fixes #2195
1 parent a1bc638 commit 7dc359f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/org/opensolaris/opengrok/web/AuthorizationFilter.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* CDDL HEADER END
1818
*/
1919

20-
/*
21-
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
20+
/*
21+
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.web;
2424

@@ -35,6 +35,7 @@
3535
import javax.servlet.http.HttpServletResponse;
3636
import org.opensolaris.opengrok.configuration.Project;
3737
import org.opensolaris.opengrok.logger.LoggerFactory;
38+
import org.opensolaris.opengrok.web.api.v1.RestApp;
3839

3940
public class AuthorizationFilter implements Filter {
4041

@@ -49,9 +50,19 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
4950
HttpServletRequest httpReq = (HttpServletRequest) sr;
5051
HttpServletResponse httpRes = (HttpServletResponse) sr1;
5152

52-
PageConfig config = PageConfig.get(httpReq);
53-
long processTime = System.currentTimeMillis();
53+
// All RESTful API requests are allowed for now (also see LocalhostFilter).
54+
// The /search endpoint will go through authorization via SearchEngine.search()
55+
// so does not have to be exempted here.
56+
if (httpReq.getServletPath().startsWith(RestApp.API_PATH)) {
57+
LOGGER.log(Level.FINER, "Allowing request to {0} in {1}",
58+
new Object[]{ httpReq.getServletPath(), AuthorizationFilter.class.getName() });
59+
fc.doFilter(sr, sr1);
60+
return;
61+
}
5462

63+
PageConfig config = PageConfig.get(httpReq);
64+
long processTime = System.currentTimeMillis();
65+
5566
Project p = config.getProject();
5667
if (p != null && !config.isAllowed(p)) {
5768
if (httpReq.getRemoteUser() != null) {

src/org/opensolaris/opengrok/web/api/v1/RestApp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
import javax.ws.rs.ApplicationPath;
2828

29-
@ApplicationPath("/api/v1")
29+
@ApplicationPath(RestApp.API_PATH)
3030
public class RestApp extends ResourceConfig {
3131

32+
public static final String API_PATH = "/api/v1";
33+
3234
public RestApp() {
3335
packages("org.opensolaris.opengrok.web.api.v1.controller", "org.opensolaris.opengrok.web.api.v1.filter");
3436
}

0 commit comments

Comments
 (0)