Spring security 使用JDBC身份验证的Spring安全性-未找到AuthenticationProvider
我是Spring Security的新手,我正在尝试针对PostgreSQL数据库设置身份验证/授权。我遵循了前3章,并在内存中使用用户名/密码,没有任何问题。创建架构()所需的表,然后在tomcat()中设置JNDI数据源以及Spring所需的所有bean之后,登录现在失败,并显示以下消息: 您的登录尝试未成功,请重试 原因:找不到的AuthenticationProvider org.springframework.security.authentication.UsernamePasswordAuthenticationToken 以下是我的servlet-context.xml中定义的bean:Spring security 使用JDBC身份验证的Spring安全性-未找到AuthenticationProvider,spring-security,tomcat7,jndi,spring-jdbc,Spring Security,Tomcat7,Jndi,Spring Jdbc,我是Spring Security的新手,我正在尝试针对PostgreSQL数据库设置身份验证/授权。我遵循了前3章,并在内存中使用用户名/密码,没有任何问题。创建架构()所需的表,然后在tomcat()中设置JNDI数据源以及Spring所需的所有bean之后,登录现在失败,并显示以下消息: 您的登录尝试未成功,请重试 原因:找不到的AuthenticationProvider org.springframework.security.authentication.UsernamePasswo
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/TyedArtDB"/>
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.tyedart.web" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
<beans:bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="userDetailsService"/>
<beans:property name="passwordEncoder" ref="passwordEncoder"/>
</beans:bean>
<beans:bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<beans:property name="providers">
<beans:list>
<beans:ref bean="daoAuthenticationProvider"/>
</beans:list>
</beans:property>
</beans:bean>
</beans:beans>
你知道我做错了什么吗?我刚刚用JDBC配置了安全性。我使用java注释来配置我的应用程序。我注意到的几件事:
.withDefaultSchema()
对我来说,出乎意料。我配置了一个数据源,但是我没有创建默认表。Spring连接到我的数据源并自动创建模式。我注意到您手动创建了模式。这也是我所期望的。文档看起来模棱两可,所以我只是运行我的应用程序,没有创建表。瞧,Spring为我创建了数据库表。可能模式不匹配(请参阅下一节,我发现文档稍微过时)
接下来,我将Spring安全性添加到一个小型Spring MVC应用程序中。Spring博客包含正确的配置注释:
@EnableWebMvcSecurity
如果你想让我发布我的安全配置,请告诉我。它是java而不是xml。因此,我不知道这是否有帮助 谢谢,这两件东西正是我需要的!您是否碰巧在注入数据源时遇到问题?我在这里有另一个帖子:很高兴能帮上忙。我通过Hibernate将数据源配置为JPA的一部分。我使用Spring而不是JNDI来访问数据源。即数据源用@Bean注释。我有一个GitHub项目,它有相同的设置(不包括spring安全性)。你想要url吗?
@EnableWebMvcSecurity