我正在尝试使用spring框架创建自己的UserDetailsService。
我做了以下简单的课程,但我收到了一个错误:Cannot convert value of type [com.mycompany.project.MyDetailsService] to required type org.springframework.security.core.userdetails.UserDetailsService]
全班:
package com.mycompany.myproject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
public class MyDetailsService implements UserDetailsService{
private static final Log log = LogFactory.getLog(MyDetailsService.class);
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException, DataAccessException {
return null; //It'll do something here later
}
}
如果有用,我可以包括填充堆栈跟踪。它只是很长,并且不容易放入盒子中,所以这里是堆栈跟踪之前的错误消息的全文。
28542 [main]错误StackTrace - 清理堆栈跟踪:org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.authentication.ProviderManager#0'的bean时出错:无法创建内部bean'(内部bean) )'设置bean属性'parent'时键入[org.springframework.security.config.authentication.AuthenticationManagerFactoryBean];嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'(内部bean)#15'的bean时出错:FactoryBean在创建对象时抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.authenticationManager'的bean时出错:在使用key [0]设置bean属性'providers'时无法解析对bean'casAuthenticationProvider'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:在文件[/usr/share/jetty/resources/OWFsecurityContext.xml]中定义名称为“casAuthenticationProvider”的bean时出错:bean的初始化失败;嵌套异常是org.springframework.beans.ConversionNotSupportedException:无法将类型'com.mycompany.myproject.MyDetailsService'的属性值转换为属性'userDetailsService'所需的类型'org.springframework.security.core.userdetails.UserDetailsService';嵌套异常是java.lang.IllegalStateException:无法将[com.mycompany.project.MyDetailsService]类型的值转换为属性“userDetailsService”的重新获取类型[org.springframework.security.core.userdetails.UserDetailsService]:没有匹配的编辑器或转换战略发现
安全背景:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security" 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-3.0.xsd">
<sec:http entry-point-ref="casProcessingFilterEntryPoint">
...
</sec:http>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="casAuthenticationProvider" />
</sec:authentication-manager>
<bean id="casProcessingFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="authenticationFailureHandler">
<bean
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/cas_failed.jsp" />
</bean>
</property>
<property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
<property name="proxyReceptorUrl" value="/secure/receptor" />
</bean>
<bean id="casProcessingFilterEntryPoint"
class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<property name="loginUrl" value="..." />
<property name="serviceProperties" ref="serviceProperties" />
</bean>
<bean id="casAuthenticationProvider"
class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<property name="userDetailsService" ref="userService" />
<property name="serviceProperties" ref="serviceProperties" />
<property name="ticketValidator" ref="ticketValidator" />
<property name="key" value="an_id_for_this_auth_provider_only" />
</bean>
<bean id="ticketValidator"
class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
<constructor-arg index="0" value="..." />
<property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
<property name="proxyCallbackUrl"
value="..." />
</bean>
<bean id="proxyGrantingTicketStorage"
class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" />
<bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<property name="service"
value="..." />
<property name="sendRenew" value="false" />
</bean>
<bean id="userService" class="com.mycompany.myproject.MyDetailsService" >
</bean>
...
</beans>