代码之家  ›  专栏  ›  技术社区  ›  cometta

Spring HTTP基本版

  •  0
  • cometta  · 技术社区  · 15 年前

    我可以知道我们是否可以为HTTP BASIC指定URL,以便仅在转到特定页面时进行身份验证?例如login.jsp?我不想使用表单登录。

    3 回复  |  直到 15 年前
        1
  •  1
  •   Tomas Narros    15 年前

    Spring方法:

    <security:http>
        <security:http-basic></security:http-basic>
        <security:intercept-url method="POST" pattern="/mypage.jsp" access="ROLE_USER" />
    </security:http>
    

    如你所见,在 截获URL 元素,您可以定义受访问控制的资源。它有一个属性 图案 您可以在其中定义此类资源的URL模式(允许通配符)。

        2
  •  1
  •   Tomas Narros    15 年前

    无论您是否使用Spring,都可以通过配置Web应用程序来实现。

    Configuring Security in Web Applications

    要应用安全约束的wich上的资源在 web.xml 部署描述符。举例来说:

    <security-constraint>
         <web-resource-collection>
              <web-resource-name>SecureOrdersEast</web-resource-name>
              <description>
                 Security constraint for
                 resources in the orders/east directory
              </description>
              <url-pattern>/orders/east/*</url-pattern>
              <http-method>POST</http-method>
              <http-method>GET</http-method>
         </web-resource-collection>
         <auth-constraint>
              <description>
               constraint for east coast sales
              </description>
              <role-name>east</role-name>
              <role-name>manager</role-name>
         </auth-constraint>
         <user-data-constraint>
              <description>SSL not required</description>
              <transport-guarantee>NONE</transport-guarantee>
         </user-data-constraint>
    </security-constraint>
    

    而且,要将auth方法定义为基本方法,还必须在 web.xml文件 文件,在登录配置元素中:

    <login-config>
      <auth-method>BASIC</auth-method>
    </login-config>
    

    在登录配置中,您还可以定义登录领域和其他选项。有关更多信息,请访问 web.xml Deployment Descriptor Elements: login-config .

        3
  •  1
  •   Raghuram    15 年前

    而不是使用 <security:http-basic> ,您可以定义自己的过滤器并适当地使用。例如

    <bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
        <security:filter-chain-map path-type="ant">
            <security:filter-chain pattern="/login.jsp"        filters="formExceptionTranslationFilter"/>
            <security:filter-chain pattern="/login2.jsp"        filters="basicProcessingFilter"/>
        </security:filter-chain-map>
    </bean>
    
    推荐文章