参阅官方文档 1. 设置专属角色和用户

1
sudo vim /etc/tomcat9/tomcat-users.xml
1
2
<role rolename="code"/>
<user username="code-user" password="code-user" roles="code"/>
  1. 添加权限
1
sudo vim /path/of/opengrok/WEB-INF/web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<security-constraint>
<web-resource-collection>
<web-resource-name>API endpoints are checked separately by the web app</web-resource-name>
<url-pattern>/api/*</url-pattern>
</web-resource-collection>
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>In general everything needs to be authenticated</web-resource-name>
<url-pattern>/*</url-pattern> <!-- protect the whole application -->
<url-pattern>/api/v1/search</url-pattern> <!-- protect search endpoint whitelisted above -->
<url-pattern>/api/v1/suggest/*</url-pattern> <!-- protect suggest endpoint whitelisted above -->
</web-resource-collection>

<auth-constraint>
<role-name>*</role-name>
</auth-constraint>

<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>

<security-role>
<role-name>*</role-name>
</security-role>

<login-config>
<auth-method>BASIC</auth-method>
</login-config>
  1. 重启tomcat 服务