LDAP身份验证的问题:java.lang.IncompatibleClassChangeError

时间:2017-04-10 15:20:23

标签: java class javafx ldap

我有一个允许我使用 LDAP 进行身份验证的课程。当我在一个只有一个类的项目中运行此代码时(出于测试原因)我没有问题并且它返回一个布尔值,正如预期的那样,但是当我在我正在工作的项目中运行它时,我得到了以下错误:

java.lang.IncompatibleClassChangeError: Class org.apache.mina.filter.codec.ProtocolCodecFilter does not implement the requested interface org.apache.mina.core.filterchain.IoFilter

这是允许我进行身份验证的方法:

public static void autenticarUsuario(String usuar, String password) throws LdapException, CursorException{       

    Dn user = Dn.EMPTY_DN;
    try{
        BasicConfigurator.configure();
    LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(SERVER_IP);
    config.setLdapPort(PORT);
    config.setName("uid=ldapsearch,ou=System,ou=Users,dc=fiec,dc=espol,dc=edu,dc=ec");
    config.setCredentials(CREDENTIALS);        
    conn = new LdapNetworkConnection(config);
    }catch(Exception e){            
    }
    String s1 = usuar;
    String s2 = password;

    //System.out.println("Nombre: "+s1+"  Contra: "+s2);
    try {
        conn.bind();
        System.out.println(conn.isAuthenticated());            
        // Create the SearchRequest object
        SearchRequest req = new SearchRequestImpl();
        req.setScope( SearchScope.SUBTREE );
        req.addAttributes( "*" );
        req.setTimeLimit( 0 );
        req.setBase( new Dn( "ou=Users,dc=fiec,dc=espol,dc=edu,dc=ec" ) );
        req.setFilter( "(uid="+ s1 +")" );

        // Process the request
        SearchCursor searchCursor = conn.search( req );

        while ( searchCursor.next() )
        {
            Response r = searchCursor.get();
            if(r instanceof SearchResultEntry){
                Entry re = ((SearchResultEntry) r).getEntry();
                user = re.getDn();
            }
        }

        conn.bind(user, s2);
        //return(conn.isAuthenticated());
        inLDAP = conn.isAuthenticated();             
    } catch (InvalidConnectionException ex) {
        //System.out.println(ex);
    }        
    catch (LdapException e) {       
        e.printStackTrace();
    } catch (CursorException e) {           
        e.printStackTrace();        
     }
    inLDAP = false; 
}

我正在使用的项目是 JAVAFX 应用程序,但是这个方法是在一个不从应用程序扩展的类中调用的(只是用于验证用户凭据的java代码)。

这是堆栈跟踪:

Exception in thread "pool-1-thread-1" java.lang.IncompatibleClassChangeError: Class org.apache.mina.filter.codec.ProtocolCodecFilter does not implement the requested interface org.apache.mina.core.filterchain.IoFilter
at org.apache.mina.core.filterchain.DefaultIoFilterChain.register(DefaultIoFilterChain.java:267)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.addLast(DefaultIoFilterChain.java:174)
at org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder.buildFilterChain(DefaultIoFilterChainBuilder.java:436)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:528)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:501)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$400(AbstractPollingIoProcessor.java:67)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1116)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source) 

这些是我正在使用的库:

import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.SearchCursor;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.Response;
import org.apache.directory.api.ldap.model.message.SearchRequest;
import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
import org.apache.directory.api.ldap.model.message.SearchResultEntry;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.mina.*;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.directory.ldap.client.api.exception.InvalidConnectionException;
import org.apache.log4j.BasicConfigurator;

我不知道为什么会这样,我会提前感谢任何帮助

1 个答案:

答案 0 :(得分:1)

这是一个版本问题。在Mina 1.0和Mina 2.0之间,他们将IoFilter界面(以及其他内容)从org.apache.mina.filterchain移至org.apache.mina.core.filterchain。我想你正在尝试使用Mina 1.0实现为Mina 2.0编译的代码。

解决方案:检查构建和运行时类路径和依赖关系,以弄清楚这是如何发生的......并修复不一致性。