繁体   English   中英

春季http-basic

[英]spring http-basic

我可以知道我们可以为http-basic指定url以便仅在转到特定页面时进行身份验证吗? 示例login.jsp? 我不想使用表单登录。

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

在Web应用程序中配置安全性

web.xml部署描述符的“ security-constant”元素中指定了要应用安全性约束的资源。 例如:

<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方法定义为BASIC,您还必须在web.xml文件的login-config元素中对其进行定义:

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

在login-config上,您还可以定义登录领域和其他选项。 您可以在web.xml部署描述符元素:login-config上找到更多信息。

春季方法:

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

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

代替使用<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM