Java 8 SearchResult - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SearchResult class.

This code example shows how to use the following methods:
        tested = new CountNameClassPairCallbackHandler(); 
    } 
 
    @Test 
    public void testHandleSearchResult() throws Exception { 
        SearchResult dummy = new SearchResult(null, null, null); 
        tested.handleNameClassPair(dummy); 
        tested.handleNameClassPair(dummy); 
        tested.handleNameClassPair(dummy); 
         
        assertEquals(3, tested.getNoOfRows()); 
    } 
     
} 
5
CodeRank
This code example shows how to use the following methods:getName, isRelative
    /** 
     * @param searchResult 
     * @param parent 
     */ 
    public LdapEntryNode(SearchResult searchResult, ILdapEntryNode parent) {
        this.sourceBaseName = searchResult.getName();
        this.parent = parent;
        this.relative = searchResult.isRelative();
        setLabel(getSourceBaseName()); 
    } 
 
    @Override 
    public boolean isRoot() { 
        return false; 
    } 
 
    @Override 
    public boolean isRelative() { 
        return relative;
    } 
4
CodeRank
This code example shows how to use the following methods:getNameInNamespace, getAttributes
This code example shows how to use the following methods:getName, getAttributes
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
        NamingEnumeration<SearchResult> results = ctx.search( "ou=system", "(pwdLastSet=3)", searchControls );
        assertTrue( results.hasMore() );
        SearchResult result = results.next();
        assertNotNull( result );
        assertEquals( "cn=foobar", result.getName() );
        Attributes attributes = result.getAttributes();
        assertEquals( "3", attributes.get( "pwdLastSet" ).get() );
        results.close();
 
        // Now search with bogus value for pwdLastSet 
        results = ctx.search( "ou=system", "(pwdLastSet=300)", searchControls );
        assertFalse( results.hasMore() );
        results.close();
    } 
 
 
    /** 
     * Test case for DIRSERVER-: Ensure that schema entry is returned, 
4
CodeRank
This code example shows how to use the following methods:getClassName, getName, getAttributes
            //			 DirContext ictx = new InitialDirContext(ldapEnv); 
            //			 NamingEnumeration<SearchResult> e = ldapContext.search("ou=monorganisationunit,dc=placeoweb", critere, controle); 
            NamingEnumeration<SearchResult> e = ldapContext.search(Play.configuration.getProperty("ldap.dn"), critere, controle);
            while (e.hasMore()) {
                SearchResult r = e.next();
                System.out.println("name: " + r.getName());
                System.out.println("object: " + r.getClassName());
                System.out.println("getAttributes: " + r.getAttributes());
                //System.out.println("bigsiri: " + r.getAttributes().get("userPassword").getID()); 
                //listerAttributs(r.getAttributes()); 
 
                return r.getAttributes();
            } 
 
        } catch (AuthenticationException error) {
            return null; 
 
        } catch (NamingException ex) {
            Logger.getLogger(Ldap.class.getName()).log(Level.SEVERE, null, ex);
        } 
4
CodeRank
This code example shows how to use the following methods:getAttributes
     
    public Attributes findAttributes(String rootDN, String filter) throws NamingException {
        NamingEnumeration<SearchResult> answer = searchSubTree(rootDN, filter);
        if (answer.hasMore()) {
            SearchResult sr = answer.next();
            return sr.getAttributes();
        } else { 
            return null; 
        } 
    } 
 
    public Attribute findAttribute(String rootDN, String filter, String attrName) throws NamingException {
        Attributes attrs = findAttributes(rootDN, filter);
        if (attrs != null) {
            Attribute attr = attrs.get(attrName);
            if (attr == null) {
                throw new RuntimeException("Did not find a matching attribute for root: " + rootDN 
                                           + " filter: " + filter + " attributeName: " + attrName);
            } 
            return attr;
4
CodeRank
This code example shows how to use the following methods:getAttributes
                throw new LoginException("User not found.");
            } 
 
            SearchResult result = findUser(username);
 
            Attributes attributes = result.getAttributes();
 
            Attribute attribute = attributes.get(_userPasswordAttribute);
            if (attribute != null)
            { 
                try 
                { 
                    byte[] value = (byte[]) attribute.get();
 
                    ldapCredential = new String(value);
                } 
                catch (NamingException e)
                { 
                    LOG.debug("no password available under attribute: " + _userPasswordAttribute);
                } 
5
CodeRank
This code example shows how to use the following methods:getAttributes
        // NamingEnumeration<SearchResult> results = context.search( suffix, "(" + attribute + "=" + value + ")", ctls 
        // ); 
 
        assertTrue( results.hasMoreElements() );
        SearchResult result = (SearchResult)results.nextElement();
        Attributes attrs = result.getAttributes();
        Attribute testAttr = attrs.get( attribute );
        assertEquals( value, testAttr.get() );
    } 
 
    private void unbind(InitialDirContext context, String dn) throws NamingException {
        try { 
            context.unbind(dn);
        } catch (LdapNameNotFoundException e) {
            // ignore 
        } 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:getNameInNamespace
 
        final String username = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getUsernameAttribute());
        final String email = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getEmailAttribute());
        final String firstname = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getFirstnameAttribute());
        final String lastname = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getLastnameAttribute());
        final String principal = result.getNameInNamespace();
 
        String domain = principal.replace("cn=" + LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getCommonNameAttribute()) + ",", "");
        domain = domain.replace("," + _ldapConfiguration.getBaseDn(), "");
        domain = domain.replace("ou=", "");
 
        return new LdapUser(username, email, firstname, lastname, principal, domain);
    } 
 
    private String generateSearchFilter(final String username) {
        final StringBuilder userObjectFilter = new StringBuilder();
        userObjectFilter.append("(objectClass=");
        userObjectFilter.append(_ldapConfiguration.getUserObject());
        userObjectFilter.append(")");
 
4
CodeRank
This code example shows how to use the following methods:getAttributes
		if (!(nameClassPair instanceof SearchResult)) {
			throw new IllegalArgumentException("Parameter must be an instance of SearchResult");
		} 
 
		SearchResult searchResult = (SearchResult) nameClassPair;
		Attributes attributes = searchResult.getAttributes();
		try { 
			return mapper.mapFromAttributes(attributes);
		} 
		catch (javax.naming.NamingException e) {
			throw LdapUtils.convertLdapException(e);
		} 
	} 
} 
4
CodeRank
See Code Examples for Java 8 SearchResult Methods: