문제

Apache의 htpasswd 명령을 사용하여 이미 사용자 데이터베이스 파일을 만들었습니다. 이 파일은 이제 Apache 및 Subversion과 같은 다른 여러 응용 프로그램에서 사용됩니다.

사용자는 다음과 같이 생성됩니다.

htpasswd /path/to/users.htpasswd peter

이 사용자 파일은 디렉토리 별이 아닌 전역입니다.

Tomcat 6을 보안 영역과 같은 파일을 사용하게하는 방법은 무엇입니까?

도움이 되었습니까?

해결책

두 가지 옵션이 있습니다.

  1. Apache를 Tomcat (mod_jk 또는 mod_proxy_ajp 사용)의 프론트 엔드로 사용하면 Apache가 인증을 수행합니다. 그렇게하는 방법에 대한 세부 정보를 찾을 수 있습니다 여기

  2. Tomcat이 인증을 수행하려면 htpasswd 파일 이외의 다른 것을 사용해야합니다. 데이터베이스, JNDI/LDAP, XML 파일 또는 JAAS 제공 업체를 사용하여 사용자의 자격 증명을 저장하는 4 가지 방법이 있습니다. 모든 옵션에 대해 읽을 수 있습니다 영역 구성 방법.

다른 팁

htpasswd와 가장 유사한 것일 수 있습니다 MemoryRealm. 사용 방법을 간단한 예제를 찾는 데 문제가 있었으므로 여기에 쉬운 예제 코드를 게시하겠습니다.

  1. tomcat-users.xml에서 역할, 사용자 이름 및 비밀번호 설정

  2. 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>
    
  3. 이것을 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을 다시 시작하고 웹 앱에 액세스 할 때 올바른 자격 증명을 요청해야합니다.

또한보십시오:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top