【发布时间】:2014-12-07 13:11:08
【问题描述】:
我想对 Spring Security 使用基于 XML 的配置。第一个想法是使用 SHA-256 或任何其他散列函数作为用户密码。我找不到用普通 java 解决这个问题的好方法,所以我开始在 xml 中配置东西。这就是它开始变得有趣的关键。
我的配置:
- spring-boot 1.1.8.RELEASE
- spring-boot-starter-* 在 1.1.8
- tomcat-embed-jasper:8.0.8
spring-security.xml:
<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"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
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>
<http pattern="/css/**" security="none"/>
<http pattern="/login.html*" security="none"/>
<http>
<intercept-url pattern="/**" access="ROLE_USER" />
<form-login login-page='/login.html'/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="admin"
authorities="ROLE_USER, ROLE_ADMIN"/>
<user name="bob" password="bob"
authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我在类中加载xml文件,其中public static void main可以找到:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Order(HIGHEST_PRECEDENCE)
@ImportResource({
"/spring-security.xml"
})
public class PhrobeBootApplication extends SpringBootServletInitializer {
...
}
但我在任何页面加载时都会遇到以下异常:
[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
...
所以看起来resources/WEB-INF/web.xml 的配置没有加载,如果我有一个好的understanding from the documentation,,我应该在只使用普通弹簧时使用它,而无需启动。 (应配置过滤器)。我说的对吗?
为什么会出现这个错误?有没有更好的方法在 spring-boot 中为 spring-security 使用基于 xml 的配置? web.xml 甚至可以通过 tomcat 加载吗?
【问题讨论】:
标签: java spring spring-security spring-boot