2015-03-01 5 views
2

Моя цель - предложить пользователю войти на сайт перед отображением первой страницы. Страница обслуживается через HTTPS.Jetty 9 HashLoginService

Использования Jetty 9.2 и ниже соответствующие конфигурации сделаны:

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0"> 
    <display-name>test-jetty</display-name> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Secured area</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <user-data-constraint> 
      <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 
    <login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>Test Realm</realm-name> 
    </login-config> 
</web-app> 

сделаны также конфигурации в {} jetty.home /etc/jetty.xml:

<Configure id="Server" class="org.eclipse.jetty.server.Server”> 
… 
<Call name="addBean"> 
     <Arg> 
       <New class="org.eclipse.jetty.security.HashLoginService"> 
         <Set name="name">Test Realm</Set> 
         <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> 
         <Set name="refreshInterval">5</Set> 
         <Call name="start"></Call> 
       </New> 
     </Arg> 
    </Call> 
</Configure> 

, а также установить файл realm.properties в {jetty.home} /etc/realm.properties:

admin: CRYPT:1a97ec915dcd5bd27d34ef8a7a86f918,admin 

после перезапущенного причалу, нет никаких ошибок в лог-файле, ни сделать приглашение Войти работы при загрузке страницы сервера на https://localhost:8443

Любые идеи, что я пропустил?

Благодаря /д

ответ

0

Хорошо, только что узнал, что я пропустил две записи в web.xml: <security-role> и <auth-constraint>.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0"> 
    <display-name>test-jetty</display-name> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Secured area</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>admin</role-name> 
     </auth-constraint> 
     <user-data-constraint> 
      <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 
    <login-config> 
     <auth-method>BASIC</auth-method> 
     <realm-name>Test Realm</realm-name> 
    </login-config> 
    <security-role> 
     <role-name>admin</role-name> 
    </security-role> 
</web-app> 
Смежные вопросы