Jetty不接受来自realm.properties的密码

时间:2018-12-18 13:41:55

标签: jetty password-protection

我有一个示例码头网络应用程序,我想用密码保护它,例如sample.war。我被要求输入密码,但是用户/密码组合不被接受,而是再次被询问。我究竟做错了什么?登录失败的尝试是否记录在任何地方?

这是我当前的配置:

web.xml {jetty.home}/webapps/sample.war:WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
         version="2.4">

    <display-name>Sample</display-name>
    <description>
        Dummy web application to test password protected folders.
    </description>

    <servlet>
        <servlet-name>SampleServlet</servlet-name>
        <servlet-class>mypackage.Sample</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SampleServlet</servlet-name>
        <url-pattern>/sample</url-pattern>
    </servlet-mapping>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>sample realm</realm-name>
    </login-config>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secure resources</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>user</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <role-name>user</role-name>
    </security-role>

</web-app>

上下文文件 {jetty.home}/webapps/sample.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" 
    "http://www.eclipse.org/jetty/configure_9_2.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/sample</Set>
  <Set name="war">webapps/sample.war</Set>
  <Get name="securityHandler">
    <Set name="loginService">
      <New class="org.eclipse.jetty.security.HashLoginService">
        <Set name="name">sample realm</Set>
        <Set name="config">etc/realm.properties</Set>
      </New>
    </Set>
  </Get>
</Configure>

领域文件 {jetty.home}/etc/realm.properties

foo: bar,user

1 个答案:

答案 0 :(得分:0)

Okay, as I suspected this was a PEBKAC case...

I created the realm.properties file in the wrong place, due to being mistaken what jetty.home was set to. So instead of the correct place /etc/jetty9/realm.properties, I used the wrong /var/lib/jetty9/etc/realm.properties.