mvn jetty:run 找不到我的 LoginService

2022-09-04 22:11:02

我设置了一个码头安全领域,如下所示(将用于)。这有效:mvn jetty:run

pom.xml

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
      <webAppXml>src/test/resources/jetty-test.xml</webAppXml>
      <useTestScope>true</useTestScope>
    </configuration>
  </plugin>

jetty-test.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Get name="securityHandler">
    <Set name="loginService">
      <New class="org.eclipse.jetty.security.HashLoginService">
        <Set name="name">MySecurityRealm</Set>
        <Set name="config">src/test/resources/jetty-realm.properties</Set>
        <Call name="start"/>
      </New>
    </Set>
    <Set name="checkWelcomeFiles">true</Set>
  </Get>
</Configure>

然后我尝试删除对该文件的需求,如下所示:jetty-test.xml

pom.xml

    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <configuration>
   <!--      <webAppXml>src/test/resources/jetty-test.xml</webAppXml>  -->
          <useTestScope>true</useTestScope>
          <loginServices>
            <loginService implementation="org.eclipse.jetty.security.HashLoginService">
              <name>MySecurityRealm</name>
              <config>${basedir}/src/test/resources/jetty-realm.properties</config>
            </loginService>
          </loginServices>
        </configuration>
      </plugin>

但它失败了:

2013-03-26 16:33:26.197:WARN:oejuc.AbstractLifeCycle:FAILED org.eclipse.jetty.security.ConstraintSecurityHandler@73937bc8: java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.BasicAuthenticator@3d47dde in org.eclipse.jetty.security.ConstraintSecurityHandler@73937bc8

有什么想法吗?

我正在使用本文档:http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Configuring_Security_Settings


答案 1

请验证您的 jetty-maven-plugin 配置中的子元素是否与 web.xml 中的子元素相同。<name>MySecurityRealm</name><loginServices><realm-name>MySecurityRealm</realm-name><login-config>


答案 2

您的 Web.xml:引用中可能存在安全约束。这就是为什么当你注释掉码头测试时它失败了.xml配置。


推荐