2010-09-21 45 views
0

我可以知道我们是否可以指定http-basic的url,这样只有在进入特定页面时才进行身份验证?例如login.jsp?我不想使用表单登录。spring http-basic

+0

你能说说你的问题吗?你是否要求身份验证,你想去一些页面?并且你不想使用表单登录 – 2010-09-21 12:11:16

+0

我使用的是spring 我可以用这个设置任何特定的url参数 – cometta 2010-09-21 13:29:28

回答

1

Spring采用的方法:

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

正如你看到的,在拦截的URL元素可以定义访问控制下的资源。它有一个属性模式您可以在其中定义此类资源的url模式(承认通配符)。

+0

不是很明确是否可以定义url = login.jsp做formlogin; url = login2.jsp,执行http-basic登录? – cometta 2010-09-21 14:38:14

+0

是的,从Spring Security 3.1开始,您可以将“pattern”属性添加到http元素,并且此配置将仅适用于匹配的url – 2010-09-21 16:35:50

1

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

Configuring Security in Web Applications

你要应用安全约束的上至极资源在web.xml部署描述符的“安全constrant”元素指定。举例:

<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> 

而且,定义验证方法为基本,你也必须把它定义在web.xml文件,在login-config元素:

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

在登录,配置您还可以定义登录领域和其他选项。你可以在web.xml Deployment Descriptor Elements: login-config找到更多信息。

+0

不,我想要使用弹簧方法,它是 cometta 2010-09-21 13:29:51

+0

@cometta:对不起,原来的问题 – 2010-09-21 13:56:55

1

而不是使用<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>