【发布时间】:2018-01-14 19:01:24
【问题描述】:
在我的应用程序中,我希望有基于 url 模式的单独的 spring 安全实现。
例如。 /rest/ ** 将拥有自己的身份验证提供程序(基本身份验证)和
/web/ ** 将有自己的身份验证提供程序(表单登录)。
请在下面找到我已经完成的配置
<?xml version="1.0"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<!-- config for rest services using basic auth-->
<http pattern="/rest/**">
<intercept-url pattern="/MyAppRestServices" access="permitAll" />
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
<http-basic />
</http>
<!-- AUTHENTICATION MANAGER FOR CUSTOM AUTHENTICATION PROVIDER -->
<authentication-manager alias="authenticationManager">
<authentication-provider ref="customAuthenticationProvider" />
</authentication-manager>
<!-- config for web using form login-->
<http pattern="/web/**">
<intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')" />
<form-login/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="nimda" authorities="ROLE_ADMIN" />
</user-service>
</authentication-provider>
</authentication-manager>
在上面的配置中,第一个配置工作正常,即带有基本身份验证的 restservice,但带有表单登录配置的 web 不起作用。它甚至没有拦截网址?
请告诉我上面的配置有什么问题?
【问题讨论】:
-
看来您的第二次拦截正在寻找 /web/**/** 作为您的网址。这是故意的吗?如果没有,您可以从 html 中删除模式“/web/**”并将其添加到拦截 URL。除非你打算添加更多的 url 来拦截。