Tomcat에서 Htpasswd 보호를 사용하는 방법은 무엇입니까?
-
09-09-2019 - |
문제
Apache의 htpasswd 명령을 사용하여 이미 사용자 데이터베이스 파일을 만들었습니다. 이 파일은 이제 Apache 및 Subversion과 같은 다른 여러 응용 프로그램에서 사용됩니다.
사용자는 다음과 같이 생성됩니다.
htpasswd /path/to/users.htpasswd peter
이 사용자 파일은 디렉토리 별이 아닌 전역입니다.
Tomcat 6을 보안 영역과 같은 파일을 사용하게하는 방법은 무엇입니까?
다른 팁
htpasswd와 가장 유사한 것일 수 있습니다 MemoryRealm. 사용 방법을 간단한 예제를 찾는 데 문제가 있었으므로 여기에 쉬운 예제 코드를 게시하겠습니다.
tomcat-users.xml에서 역할, 사용자 이름 및 비밀번호 설정
Web.xml은 다음과 같은 것을 포함해야합니다.
<security-constraint> <web-resource-collection> <web-resource-name> My Protected WebSite </web-resource-name> <url-pattern> /* </url-pattern> <http-method> GET </http-method> <http-method> POST </http-method> </web-resource-collection> <auth-constraint> <!-- the same like in your tomcat-users.conf file --> <role-name> test </role-name> </auth-constraint> </security-constraint> <login-config> <auth-method> BASIC </auth-method> <realm-name> Basic Authentication </realm-name> </login-config> <security-role> <description> Test role </description> <role-name> test </role-name> </security-role>
이것을 Server.xml 파일에 추가하십시오.
<Realm className="org.apache.catalina.realm.MemoryRealm"></Realm>
Tomcat WebApp에 대한 액세스를 보장하려면 간단한 보안 제약 조건을 구현할 수 있습니다 (예 : /var/lib/tomcat7/webapps/*/WEB-INF/web.xml
) 아래와 같이 (전에 추가하십시오 </web-app>
종결):
<!-- This security constraint protects your webapp interface. -->
<login-config>
<!-- Define the Login Configuration -->
<auth-method>BASIC</auth-method>
<realm-name>Webapp</realm-name>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
<!-- Specifying a Secure Connection -->
<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL (forced SSL), INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- Authorization, see: tomcat-users.xml -->
<security-role>
<role-name>*</role-name>
</security-role>
로그인 -Config 요소에는 다음을 포함합니다
auth-method
우리가 사용하는 인증 방법을 지정하는 요소, 즉BASIC
. 그만큼security-constraint
요소에는 3 가지 요소가 포함됩니다.web-resource-collection
,auth-constraint
, 그리고user-data-constraint
. Web Resource Collection은 인증이 필요한 응용 프로그램의 부분을 지정합니다. 그만큼/*
전체 응용 프로그램에 인증이 필요하다는 것을 나타냅니다. 인증은 보호 된 리소스에 액세스하기 위해 사용자가 필요한 역할을 지정합니다. 사용자 데이터-제약의 운송-구조가 될 수 있습니다NONE
,CONFIDENTIAL
또는INTEGRAL
. 우리는 그것을 설정했습니다NONE
, 이는 그 리디렉션을 의미합니다SSL
보호 자원을 치려고 할 때는 필요하지 않습니다.
또한 당신이 줄을 봐야합니다.
<Realm className="org.apache.catalina.realm.MemoryRealm" />
당신의 내부 conf/server.xml
(Engine
부분).
구성 파일을 변경하지 않은 경우 파일을 검사하십시오. conf/tomcat-users.xml
설치에서 (locate tomcat-users.xml
). 이 파일에는 Tomcat WebApp을 사용할 수 있도록 자격 증명이 포함되어야합니다.
예를 들어, 지명 된 사용자에게 관리자 GUI 역할을 추가하려면 tomcat
비밀번호로 s3cret
, 위에 나열된 구성 파일에 다음을 추가하십시오.
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
그런 다음 WebApps Manager에 액세스 할 수 있습니다 /manager/html
(예 : 구성 변경 후 재 장전).
더 읽기 : 관리자 앱 방법.
그런 다음 Tomcat을 다시 시작하고 웹 앱에 액세스 할 때 올바른 자격 증명을 요청해야합니다.
또한보십시오:
- Java의 HTTP 기본 인증 오라클 사이트에서
- Java에서 인증 메커니즘을 지정합니다 오라클 사이트에서
- 영역 구성 방법 Apache Tomcat 사이트에서
- Tomcat에서 역할 기반 보안 설정
- Tomcat과 함께 기본 인증을 어떻게 사용합니까?