17
17
* CDDL HEADER END
18
18
*/
19
19
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.
22
22
*/
23
23
package org .opensolaris .opengrok .web ;
24
24
35
35
import javax .servlet .http .HttpServletResponse ;
36
36
import org .opensolaris .opengrok .configuration .Project ;
37
37
import org .opensolaris .opengrok .logger .LoggerFactory ;
38
+ import org .opensolaris .opengrok .web .api .v1 .RestApp ;
38
39
39
40
public class AuthorizationFilter implements Filter {
40
41
@@ -49,9 +50,19 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
49
50
HttpServletRequest httpReq = (HttpServletRequest ) sr ;
50
51
HttpServletResponse httpRes = (HttpServletResponse ) sr1 ;
51
52
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
+ }
54
62
63
+ PageConfig config = PageConfig .get (httpReq );
64
+ long processTime = System .currentTimeMillis ();
65
+
55
66
Project p = config .getProject ();
56
67
if (p != null && !config .isAllowed (p )) {
57
68
if (httpReq .getRemoteUser () != null ) {
0 commit comments