[ 
https://issues.apache.org/jira/browse/DIRAPI-204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14148610#comment-14148610
 ] 

Robert Hou commented on DIRAPI-204:
-----------------------------------

Sorry for attaching source late!!! I use OpenLDAP 2.4.39.

@Test
public void testAliasWithOpenLDAP(){
        LdapConnectionConfig config = new LdapConnectionConfig();
        config.setLdapHost("192.168.80.214");
        config.setLdapPort(389);
        config.setName("cn=Manager,dc=maxcrc,dc=com");
        config.setCredentials("secret");
        DefaultConfigurableBinaryAttributeDetector bad = new 
DefaultConfigurableBinaryAttributeDetector();
        config.setBinaryAttributeDetector(bad);
        PoolableLdapConnectionFactory factory = new 
PoolableLdapConnectionFactory(config);
        LdapConnectionPool pool = new LdapConnectionPool(factory);
        pool.setTestOnBorrow(true);
        
        LdapConnection connection = null;
        try {
                connection = pool.getConnection();
        } catch (Exception e1) {
                e1.printStackTrace();
        }
        try {
                connection.bind("cn=Manager,dc=maxcrc,dc=com", "secret");
        } catch (LdapException e) {
                e.printStackTrace();
        }
        
        SearchRequest req = new SearchRequestImpl();
        req.setScope(SearchScope.SUBTREE);
        req.addAttributes("*");
        req.setTimeLimit(0);
                try {
                        String DN = "dc=maxcrc,dc=com";
                        req.setBase(new Dn(DN));
                } catch (LdapInvalidDnException e1) {
                        e1.printStackTrace();
                }
                try {
                        req.setFilter("(objectclass=alias)");                   
                } catch (LdapException e) {
                        e.printStackTrace();
                }
                req.setSizeLimit(0);
                
//              req.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);
                req.setDerefAliases(AliasDerefMode.NEVER_DEREF_ALIASES);
                SearchCursor searchCursor = null;
                try {
                        searchCursor = connection.search(req);
                } catch (LdapException e) {
                        e.printStackTrace();
                }
                
                try {
                        while (searchCursor.next()) {

                                try {
                                        Entry entry= searchCursor.getEntry();
                                        System.out.println(entry.getDn());
                                } catch (LdapInvalidAttributeValueException e) {
                                        e.printStackTrace();
                                } catch (LdapException e) {
                                        e.printStackTrace();
                                }

                        }
                } catch (LdapException e) {
                        e.printStackTrace();
                } catch (CursorException e) {
                        e.printStackTrace();
                }               
        
}

> API can't search out the entry which's objectclass is alias when server is 
> OpenLDAP
> -----------------------------------------------------------------------------------
>
>                 Key: DIRAPI-204
>                 URL: https://issues.apache.org/jira/browse/DIRAPI-204
>             Project: Directory Client API
>          Issue Type: Bug
>    Affects Versions: 1.0.0-M24
>            Reporter: Robert Hou
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to