Java Springframework用户详细信息服务错误

Java Springframework用户详细信息服务错误,java,spring,spring-security,Java,Spring,Spring Security,我正在尝试使用spring框架创建自己的UserDetails服务 我创建了以下简单的类,但出现了一个错误:无法将[com.mycompany.project.MyDetailsService]类型的值转换为所需的类型org.springframework.security.core.userdetails.UserDetailsService] 全班: package com.mycompany.myproject; import java.io.IOException; import ja

我正在尝试使用spring框架创建自己的UserDetails服务

我创建了以下简单的类,但出现了一个错误:
无法将[com.mycompany.project.MyDetailsService]类型的值转换为所需的类型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-清理StackTrace:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.authentication.ProviderManager#0”的bean时出错:无法创建[org.springframework.security.config.authentication.AuthenticationManagerFactoryBean]类型的内部bean(内部bean)]设置bean属性“parent”时;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名为“(内部bean)#15”的bean时出错:FactoryBean在创建对象时抛出异常;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.authenticationManager”的bean时出错:在使用键[0]设置bean属性“providers”时,无法解析对bean“casAuthenticationProvider”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“casAuthenticationProvider”的bean时出错,该名称在文件[/usr/share/jetty/resources/OWFsecurityContext.xml]中定义:bean初始化失败;嵌套异常为org.springframework.beans.ConversionNotSupportedException:未能将类型为“com.mycompany.myproject.MyDetailsService”的属性值转换为属性“UserDetailsService”所需的类型“org.springframework.security.core.userdetails.UserDetailsService”;嵌套异常为java.lang.IllegalStateException:无法将[com.mycompany.project.MyDetailsService]类型的值转换为属性“UserDetailsService”的reuired类型[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>

...
...

我们可以看一下您的OWFsecurityContext.xml文件的片段吗?当然可以。我不知道你需要多少,但我把大部分都贴在上面了。请让我知道填写任何省略号是否有帮助。谢谢。我看不出有什么问题。值得一提的是,CasAuthenticationProvider(这是虚拟的)确实说setUserDetailsService已被弃用,您应该使用setAuthenticationUserDetailsService,它接受不同的用户详细信息服务。看看这是否是问题所在-我不能说。谢谢你的帮助。我尝试将类更改为实现AuthenticationUserDetailsService,并将安全上下文更改为使用AuthenticationUserDetailsService,但我仍然收到类似的错误,只是这次它无法转换为AuthenticationUserDetailsService。