LoginSignup
14
12

More than 5 years have passed since last update.

tomcatでBasic認証を有効にする方法

Last updated at Posted at 2017-10-08

1.「web.xml」に以下の記載を追加する。

<web.xmlの格納先>
\apache-tomcat-8.5.15\webapps\ROOT\WEB-INF\web.xml
or
\apache-tomcat-8.5.15\conf\web.xml

■記載内容

<security-constraint>
 <web-resource-collection>
  <web-resource-name>User Basic Auth</web-resource-name>
  <url-pattern>/*</url-pattern>
 </web-resource-collection>
 <auth-constraint>
  <role-name>role1</role-name>
 </auth-constraint>
</security-constraint>

<login-config>
 <auth-method>BASIC</auth-method>
 <realm-name>User Basic Auth</realm-name>
</login-config>

<security-role>
 <role-name>role1</role-name>
</security-role>

image.png

2.「tomcat-users.xml」に以下の記載をする。

<tomcat-users.xmlの格納先>
\apache-tomcat-8.5.15\conf\tomcat-users.xml

■記載内容

<role rolename="role1"/>
<user username="sample" password="test" roles="role1"/>

image.png

3.Tomcatを再起動する。

14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12