Java 8 NamingEnumeration - 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 NamingEnumeration class.

This code example shows how to use the following methods:hasMoreElements, nextElement
    when(mockUserResult.getNameInNamespace()).thenReturn("CN=some_user,DC=test,DC=com");
     
    SearchResult mockGroupResult = mock(SearchResult.class);
    // We're going to have to define the loop here. We want two iterations, 
    // to get both the groups 
    when(mockGroupNamingEnum.hasMoreElements()).thenReturn(true, true, false);
    when(mockGroupNamingEnum.nextElement()).thenReturn(mockGroupResult);
     
    // Define the attribute for the name of the first group 
    Attribute group1Attr = new BasicAttribute("cn");
    group1Attr.add(testGroups[0]);
    Attributes group1Attrs = new BasicAttributes();
    group1Attrs.put(group1Attr);
     
    // Define the attribute for the name of the second group 
    Attribute group2Attr = new BasicAttribute("cn");
    group2Attr.add(testGroups[1]);
    Attributes group2Attrs = new BasicAttributes();
    group2Attrs.put(group2Attr);
     
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, hasMore, next
      String attrList[] = { uidName };
      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(2);
      constraints.setReturningAttributes(attrList);
      NamingEnumeration<SearchResult> results = ctx.search(base, condition, constraints);
      if (results.hasMore()) {
        SearchResult si = results.next();
        result = Strings.concat(si.getName(), ",", base);
      } 
      results.close();
      results = null;
    } catch (Throwable e) {
      logger.error("Ldap search error,uid=" + uid, e);
    } 
    return result;
  } 
 
  public String getPassword(String uid) {
    Set<Attribute> passwords = getAttributes(uid, "userPassword");
    if (passwords.isEmpty()) return null;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMore, next
                                   + " attributeName: " + attrName);
    } 
     
    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);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
    } 
 
    public static void closeEnumeration(NamingEnumeration ne) {
        try { 
            if (ne != null) {
                ne.close();
            } 
        } catch (NamingException e) {
            logger.error("Failed to close enumeration.", e);
        } 
    } 
 
    /** 
     * Obtains the part of a DN relative to a supplied base context. 
     * <p>If the DN is "cn=bob,ou=people,dc=springframework,dc=org" and the base context name is 
     * "ou=people,dc=springframework,dc=org" it would return "cn=bob". 
     * </p> 
     * 
     * @param fullDn the DN 
     * @param baseCtx the context to work out the name relative to. 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMore
    private LdapConfigurationStore parentLdapConfigurationStore = new LdapConfigurationStore();
 
    @Test(expected = ConstrettoException.class)
    public void testParseConfigurationAttributesReadFailed() throws Exception {
 
        when(attributes.getAll()).thenReturn(attributesNamingEnumeration);
        when(attributesNamingEnumeration.hasMore()).thenThrow(new NamingException());
        try { 
            final LdapConfigurationStore ldapConfigurationStore = new LdapConfigurationStore(
                    parentLdapConfigurationStore,
                    attributes);
            ldapConfigurationStore.parseConfiguration();
 
        } finally { 
            verify(attributes).getAll();
            verify(attributesNamingEnumeration).hasMore();
        } 
    } 
 
    @Test
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, hasMore, next
 
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        NamingEnumeration<SearchResult> results = ctx.search( NEW_DN, "(objectClass=*)", controls );
        assertNotNull( results );
        assertTrue( "Could not find entry after move.", results.hasMore() );
        SearchResult result = results.next();
        assertNotNull( result );
        assertEquals( NEW_DN, result.getNameInNamespace() );
 
        results.close();
        ctx.close();
    } 
 
 
    @Test
    public void testMoveAndRdnChange() throws ExceptionLdapContext ctx = getWiredContext( getLdapServer() );
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMore, next
        when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
    } 
 
    private void setupStringListAndNamingEnumeration(NameClassPair listResult)
            throws NamingException {
        when(dirContextMock.list(NAME)).thenReturn(namingEnumerationMock);
 
        setupNamingEnumeration(listResult);
    } 
 
    private void setupListAndNamingEnumeration(NameClassPair listResult)
            throws NamingException {
        when(dirContextMock.list(nameMock)).thenReturn(namingEnumerationMock);
 
        setupNamingEnumeration(listResult);
    } 
 
    private void setupStringListBindingsAndNamingEnumeration( 
            NameClassPair listResult) throws NamingException {
        when(dirContextMock.listBindings(NAME)).thenReturn(namingEnumerationMock);

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMoreElements, nextElement
            _userIdAttribute, 
            username 
        }; 
        NamingEnumeration<SearchResult> results = _rootContext.search(_userBaseDn, filter, filterArguments, ctls);
 
        LOG.info("Found user?: " + results.hasMoreElements());
 
        if (!results.hasMoreElements())
        { 
            throw new LoginException("User not found.");
        } 
 
        return (SearchResult) results.nextElement();
    } 
 
 
    /** 
     * Init LoginModule. 
     * Called once by JAAS after new instance is created. 
     * 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMoreElements, nextElement
        final SearchControls controls = new SearchControls();
        controls.setSearchScope(_ldapConfiguration.getScope());
        controls.setReturningAttributes(_ldapConfiguration.getReturnAttributes());
 
        NamingEnumeration<SearchResult> result = context.search(userdn, "(objectClass=" + _ldapConfiguration.getUserObject() + ")", controls);
        if (result.hasMoreElements()) {
            return createUser(result.nextElement());
        } else { 
            throw new NamingException("No user found for dn " + userdn);
        } 
    } 
 
    public List<LdapUser> searchUsers(final LdapContext context) throws NamingException, IOException {
        return searchUsers(null, context);
    } 
 
    public List<LdapUser> searchUsers(final String username, final LdapContext context) throws NamingException, IOException {
 
        final SearchControls searchControls = new SearchControls();
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasMoreElements, nextElement
 
        NamingEnumeration results = context.search( suffix, matchingAttributes );
        // 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 
        } 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 NamingEnumeration Methods: