请帮我解决这个问题。过去两天我坚持这个问题。我正在使用spring MVC + spring security + hibernate,当我尝试在Authentication-Manager中使用UserAuthenticationProvider时,我遇到了这个问题,我不知道我的代码有什么问题。任何帮助将不胜感激。谢谢
org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.authenticationManager'的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定索引/类型/名称参数以避免类型歧义)
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:295) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.security.config.authentication.AuthenticationManagerFactoryBean.getObject(AuthenticationManagerFactoryBean.java:28) 在org.springframework.security.config.authentication.AuthenticationManagerFactoryBean.getObject(AuthenticationManagerFactoryBean.java:20) 在org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142) ......还有73个
Web.xml
<servlet>
<servlet-name>sdnext</servlet-name>
<servlet- class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sdnext</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/sdnext-servlet.xml,
/WEB-INF/sdnext-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AuthFilter</filter-name>
<filter-class>com.box.practice.common.web.AuthFilter</filter-class>
<init-param>
<param-name>host</param-name>
<param-value>http://172.17.4.15:8089/Spr_SperSec_DB</param-value>
<!-- <param-value>http://localhost:38080/HRAlign_V3Talent</param- value> -->
</init-param>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>sdnext</servlet-name>
</filter-mapping>
sdnext-servlet.xml
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<annotation-driven></annotation-driven>
<context:property-placeholder location="classpath:resources/database.properties" />
<context:component-scan base-package="com.box.practice"/>
<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
<beans:bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
</beans:bean>
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.box.practice.security.login.model.Users</beans:value>
<beans:value>com.box.practice.personalDetails.personalInfo.model.Concept_Underst anding_CURD</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">${hibernate.dialect} </beans:prop>
<beans:prop key="hibernate.show_sql">${hibernate.show_sql} </beans:prop>
<beans:prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<beans:bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
</beans:beans>
sdnext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<security:http auto-config="true" >
<security:intercept-url pattern="/**" />
<security:form-login login-page="/login" default-target-url="/security/login/index.html"
authentication-failure-url="/security/login/fail2login" />
<security:logout logout-success-url="/security/login/logout" />
</security:http>
<beans:bean id="passwordEncoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/>
<beans:bean class="com.box.practice.common.web.UserAuthenticationProvider"
id="userAuthenticationProvider" autowire-candidate="true">
</beans:bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="userAuthenticationProvider"/>
<security:authentication-provider>
<security:user-service>
<security:user name="abc" password="xyz" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans:beans>
UserAuthenticationProvider.class
public class UserAuthenticationProvider implements Authentication{
private static final long serialVersionUID = 1L;
@Autowired HttpSession session;
@Autowired PasswordEncoder passwordEncoder;
@Autowired UserCredentialsService userCredentialsService;
public Authentication authenticate(Authentication authentication) throws AuthenticationException{
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
String userName = token.getName();String key="";
String jCryption=(String)token.getCredentials();
key = (String) session.getAttribute("jCryptionKey");
if(key==null || key.equals(""))
{
throw new PreAuthenticatedCredentialsNotFoundException("");
}
String passwordStr = AesCtr.decrypt(jCryption, key, 256); // added jar javacryption-1.0.jar
String password = passwordEncoder.encode(passwordStr);
User user=null;
user = userCredentialsService.authenticateUser(userName, password);
if(user == null) {
throw new UsernameNotFoundException("Invalid username/password");
}else{
if(!passwordEncoder.matches(passwordStr, user.getPassword())){
throw new BadCredentialsException("Invalid username/password");
}
}
session.setAttribute("user", user);
return new UsernamePasswordAuthenticationToken(user,password);
}