REST Web服务中基于表单的身份验证

时间:2013-06-17 05:48:45

标签: eclipse rest tomcat forms-authentication

我在eclipse中使用动态Web项目创建了REST Web服务,并在tomcat 7中运行。    我能够为Web服务进行基本身份验证。现在我正在尝试实现基于表单的身份验证。现在,来自浏览器的任何Web服务调用都显示404错误而不是显示登录表单。      可能是,我猜问题是LoginForm.html的路径。我已直接在webcontent下创建了LoginForm.html。

我的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>CustomerConnect</display-name>

   <security-role>
        <role-name>manager</role-name>
    </security-role>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>management pages</web-resource-name>
            <url-pattern>/*</url-pattern>

        </web-resource-collection>
        <auth-constraint>
            <role-name>manager</role-name>
        </auth-constraint>
    </security-constraint>

  <login-config>
        <auth-method>FORM</auth-method>
         <form-login-config>
            <form-login-page>/LoginForm.html</form-login-page>
            <form-error-page>/LoginError.html</form-error-page>
         </form-login-config>
    </login-config>

<!--   <session-config> -->
<!--  <session-timeout> -->
<!--  1 -->
<!-- </session-timeout> -->
<!--  </session-config> -->


  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.feature.Redirect</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
      <param-value>/views/</param-value>
    </init-param>
    <init-param>
      <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
      <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.bvbi.customerconnect.middletier</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>Location to store uploaded file</description>
    <param-name>file-upload</param-name>
    <param-value>
         /home/bvbi/Desktop/apache-tomcat-7.0.26/webapps/CredoImages/
     </param-value>
  </context-param>

</web-app>

The project structure is

1 个答案:

答案 0 :(得分:0)

您的路径配置正确无误。从*内的<url-pattern>移除<servlet-mapping>

<servlet-mapping>
  <servlet-name>Jersey REST Service</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

它有什么不同吗?