关于 HTTP 基本配置,XML 配置和 Java 似乎在 Spring Security 中执行的任务不同。
当使用以下 Java 配置时:
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.authorizeRequests()
.anyRequest().authenticated();
}
当请求 HTTP header X-Requested-With
为 XMLHttpRequest
时,使用 HttpBasicConfigurer
来使用不同的 EntryPoint。
使用配置时
<s:http use-expressions="true" create-session="ifRequired">
<s:intercept-url pattern='/**' access='isAuthenticated()' />
<s:http-basic />
<s:http />
未使用HTTPBassicConfigurer
。
有人知道如何使用 XML 配置添加它吗?
最佳答案
根据本文中的人员提供的评论,最终的解决方案是不可能将 HTTPBasicConfigurer
与 XML 配置一起使用。但是还有其他方法可以执行与 HTTPBasicConfigurer 中现在实现的几乎相同的操作。我最终使用的解决方案主要是基于Lea提供的备注:
<s:http use-expressions="true" create-session="ifRequired" >
<s:intercept-url pattern='/**' access='isAuthenticated()' />
<s:http-basic entry-point-ref="entryPoint" />
</s:http>
<bean id="entryPoint"
class="org.springframework.security.web.authentication
.DelegatingAuthenticationEntryPoint">
<constructor-arg>
<map>
<entry key="hasHeader('X-Requested-With','XMLHttpRequest')"
value-ref="ajaxEntyPoint" />
</map>
</constructor-arg>
<property name="defaultEntryPoint" ref="defaultEntryPoint"/>
</bean>
<bean id="ajaxEntyPoint"
class="org.springframework.security.web.authentication.HttpStatusEntryPoint">
<constructor-arg name="httpStatus"
value="#{T(org.springframework.http.HttpStatus).UNAUTHORIZED}"/>
</bean>
<bean id="defaultEntryPoint"
class="org.springframework.security.web.authentication.www
.BasicAuthenticationEntryPoint">
<property name="realmName" value="My webservices"/>
</bean>
关于java - 使用 Spring Security XML 配置的 HTTP Basic 不使用 HttpBasicConfigurer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30304680/