javax.naming.NameClassPair Java Examples

The following examples show how to use javax.naming.NameClassPair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapTemplateListTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void testList_Name() throws NamingException {
    expectGetReadOnlyContext();

    NameClassPair listResult = new NameClassPair(NAME, CLASS);

    setupListAndNamingEnumeration(listResult);

    List list = tested.list(nameMock);

    verify(dirContextMock).close();
    verify(namingEnumerationMock).close();

    assertThat(list).isNotNull();
    assertThat(list).hasSize(1);
    assertThat(list.get(0)).isSameAs(NAME);
}
 
Example #2
Source File: LegacyLDAPSecuritySettingPluginTest2.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
 
Example #3
Source File: NamingContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Enumerates the names bound in the named context, along with the class
 * names of objects bound to them. The contents of any subcontexts are
 * not included.
 * <p>
 * If a binding is added to or removed from this context, its effect on
 * an enumeration previously returned is undefined.
 *
 * @param name the name of the context to list
 * @return an enumeration of the names and class names of the bindings in
 * this context. Each element of the enumeration is of type NameClassPair.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<NameClassPair> list(Name name)
    throws NamingException {
    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        return new NamingContextEnumeration(bindings.values().iterator());
    }

    NamingEntry entry = bindings.get(name.get(0));

    if (entry == null) {
        throw new NameNotFoundException
            (sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }

    if (entry.type != NamingEntry.CONTEXT) {
        throw new NamingException
            (sm.getString("namingContext.contextExpected"));
    }
    return ((Context) entry.value).list(name.getSuffix(1));
}
 
Example #4
Source File: LegacyLDAPSecuritySettingPluginListenerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRunning() throws Exception {
   DirContext ctx = getContext();

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
 
Example #5
Source File: EmbeddedLdapRuleTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Test
public void testList() throws Exception {
  final Context context = embeddedLdapRule.context();
  NamingEnumeration list = context.list("ou=semi-people,dc=zapodot,dc=org");

  while (list.hasMore()){
    NameClassPair nc = (NameClassPair) list.next();
    String user, group = null;
    ArrayList user_sp = new ArrayList();
    StringTokenizer user_info = new StringTokenizer(nc.getNameInNamespace(), ",");

    while (user_info.hasMoreTokens()){
      user_sp.add(user_info.nextToken());
    }
    user = user_sp.get(0).toString().substring(3, user_sp.get(0).toString().length());
    group = user_sp.get(1).toString().substring(3, user_sp.get(1).toString().length());

    LOG.info(user);

    assertEquals((user + "," + group) , "Fake-Eros,semi-people");
  }

  context.close();
}
 
Example #6
Source File: SimpleNamingContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String root) throws NamingException {
	if (logger.isDebugEnabled()) {
		logger.debug("Listing name/class pairs under [" + root + "]");
	}
	return new NameClassPairEnumeration(this, root);
}
 
Example #7
Source File: LDAPAuthorizationMapTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testOpen() throws Exception {
   DirContext ctx = authMap.open();
   HashSet<String> set = new HashSet<>();
   NamingEnumeration<NameClassPair> list = ctx.list("ou=destinations,o=ActiveMQ,ou=system");
   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }
   assertTrue(set.contains("ou=topics"));
   assertTrue(set.contains("ou=queues"));
}
 
Example #8
Source File: JdbcWrapperHelper.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private static Map<String, DataSource> getJndiDataSourcesAt(String jndiPrefix)
		throws NamingException {
	final InitialContext initialContext = new InitialContext();
	final Map<String, DataSource> dataSources = new LinkedHashMap<String, DataSource>(2);
	try {
		for (final NameClassPair nameClassPair : Collections
				.list(initialContext.list(jndiPrefix))) {
			// note: il ne suffit pas de tester
			// (DataSource.class.isAssignableFrom(Class.forName(nameClassPair.getClassName())))
			// car nameClassPair.getClassName() vaut "javax.naming.LinkRef" sous jboss 5.1.0.GA
			// par exemple, donc on fait le lookup pour voir
			final String jndiName;
			if (nameClassPair.getName().startsWith("java:")) {
				// pour glassfish v3
				jndiName = nameClassPair.getName();
			} else {
				jndiName = jndiPrefix + '/' + nameClassPair.getName();
			}
			final Object value = initialContext.lookup(jndiName);
			if (value instanceof DataSource) {
				dataSources.put(jndiName, (DataSource) value);
			}
		}
	} catch (final NamingException e) {
		// le préfixe ("comp/env/jdbc", "/jdbc" ou "java:global/jdbc", etc) n'existe pas dans jndi,
		// (dans glassfish 3.0.1, c'est une NamingException et non une NameNotFoundException)
		return dataSources;
	}
	initialContext.close();
	return dataSources;
}
 
Example #9
Source File: LdapTemplate.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
/**
       * {@inheritDoc}
       */
public T getObjectFromNameClassPair(NameClassPair nameClassPair) {
	try {
		return mapper.mapFromNameClassPair(nameClassPair);
	}
	catch (javax.naming.NamingException e) {
		throw LdapUtils.convertLdapException(e);
	}
}
 
Example #10
Source File: JndiTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void assertNameClassPair(NamingEnumeration<NameClassPair> namingEnumeration) {
    assertNotNull("namingEnumeration", namingEnumeration);

    Map<String, String> map = new HashMap<String, String>();
    while (namingEnumeration.hasMoreElements()) {
        NameClassPair pair = namingEnumeration.nextElement();
        map.put(pair.getName(), pair.getClassName());
    }

    assertTrue("OrangeRemote", map.containsKey("OrangeRemote"));
    assertTrue("AppleRemote", map.containsKey("AppleRemote"));
    assertTrue("PeachRemote", map.containsKey("PeachRemote"));
    assertTrue("PearRemote", map.containsKey("PearRemote"));
    assertTrue("PlumRemote", map.containsKey("PlumRemote"));
}
 
Example #11
Source File: PingsResource.java    From ping with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/jndi/{namespace}")
public JsonObject jndi(@PathParam("namespace") String namespace) throws NamingException {
    JsonObjectBuilder builder = Json.createObjectBuilder();
    InitialContext c = new InitialContext();
    NamingEnumeration<NameClassPair> list = c.list(namespace);
    while (list.hasMoreElements()) {
        NameClassPair nameClassPair = list.nextElement();
        String name = nameClassPair.getName();
        String type = nameClassPair.getClassName();
        builder.add(name, type);
    }
    return builder.build();
}
 
Example #12
Source File: TestContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
   Object o = lookup(name);
   if (o == this) {
      return new ListEnumeration();
   } else if (o instanceof Context) {
      return ((Context) o).list("");
   } else {
      throw new NotContextException();
   }
}
 
Example #13
Source File: SimpleNamingContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String root) throws NamingException {
	if (logger.isDebugEnabled()) {
		logger.debug("Listing name/class pairs under [" + root + "]");
	}
	return new NameClassPairEnumeration(this, root);
}
 
Example #14
Source File: NameClassPairEnumeration.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    // write out the version of the serialized data for future use
    out.writeByte(1);

    out.writeInt(list.size());
    for (final NameClassPair pair : list) {
        out.writeObject(pair.getName());
        out.writeObject(pair.getClassName());
    }
}
 
Example #15
Source File: LdapTemplateListTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
public void testList_Name_CallbackHandler() throws NamingException {
    expectGetReadOnlyContext();

    NameClassPair listResult = new NameClassPair(NAME, CLASS);

    setupListAndNamingEnumeration(listResult);

    tested.list(nameMock, handlerMock);

    verify(handlerMock).handleNameClassPair(listResult);
    verify(namingEnumerationMock).close();
    verify(dirContextMock).close();
}
 
Example #16
Source File: LdapTemplateListTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
public void testList_String_CallbackHandler() throws NamingException {
    expectGetReadOnlyContext();

    NameClassPair listResult = new NameClassPair(NAME, CLASS);

    setupStringListAndNamingEnumeration(listResult);

    tested.list("o=example.com", handlerMock);

    verify(handlerMock).handleNameClassPair(listResult);
    verify(namingEnumerationMock).close();
    verify(dirContextMock).close();
}
 
Example #17
Source File: CoverageTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    System.out.println("ParallelizeAntRunnerTest.MyContextFactory.getInitialContext()");
    InitialContext mockedInitialContext = PowerMockito.mock(InitialContext.class);
    NamingEnumeration<NameClassPair> mockedEnumeration = PowerMockito.mock(NamingEnumeration.class);
    // Look at this again ...
    PowerMockito.mockStatic(NamingEnumeration.class);
    //
    PowerMockito.when(mockedEnumeration.hasMore()).thenReturn(true, true, true, true, false);
    PowerMockito.when(mockedEnumeration.next()).thenReturn(
            new NameClassPair("data.dir", String.class.getName()),
            new NameClassPair("parallelize", String.class.getName()),
            new NameClassPair("mutant.coverage", String.class.getName()),
            new NameClassPair("ant.home", String.class.getName())//
    );
    //
    PowerMockito.when(mockedInitialContext.toString()).thenReturn("Mocked Initial Context");
    PowerMockito.when(mockedInitialContext.list("java:/comp/env")).thenReturn(mockedEnumeration);
    //
    Context mockedEnvironmentContext = PowerMockito.mock(Context.class);
    PowerMockito.when(mockedInitialContext.lookup("java:/comp/env")).thenReturn(mockedEnvironmentContext);

    PowerMockito.when(mockedEnvironmentContext.lookup("mutant.coverage")).thenReturn("enabled");
    // FIXMED
    PowerMockito.when(mockedEnvironmentContext.lookup("parallelize")).thenReturn("disabled");
    //
    PowerMockito.when(mockedEnvironmentContext.lookup("data.dir"))
            .thenReturn(codedefendersHome.getAbsolutePath());

    PowerMockito.when(mockedEnvironmentContext.lookup("ant.home")).thenReturn("/usr/local");
    //
    return mockedInitialContext;
}
 
Example #18
Source File: SaslKrb5LDAPSecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaslGssapiLdapAuth() throws Exception {

   final Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");

   LoginContext loginContext = new LoginContext("broker-sasl-gssapi");
   loginContext.login();
   try {
      Subject.doAs(loginContext.getSubject(), (PrivilegedExceptionAction<Object>) () -> {

         HashSet<String> set = new HashSet<>();

         DirContext ctx = new InitialDirContext(env);
         NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

         while (list.hasMore()) {
            NameClassPair ncp = list.next();
            set.add(ncp.getName());
         }

         Assert.assertTrue(set.contains("uid=first"));
         Assert.assertTrue(set.contains("cn=users"));
         Assert.assertTrue(set.contains("ou=configuration"));
         Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));

         ctx.close();
         return null;

      });
   } catch (PrivilegedActionException e) {
      throw e.getException();
   }
}
 
Example #19
Source File: ConsistencyTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    System.out.println("ParallelizeAntRunnerTest.MyContextFactory.getInitialContext()");
    InitialContext mockedInitialContext = PowerMockito.mock(InitialContext.class);
    NamingEnumeration<NameClassPair> mockedEnumeration = PowerMockito.mock(NamingEnumeration.class);
    // Look at this again ...
    PowerMockito.mockStatic(NamingEnumeration.class);
    //
    PowerMockito.when(mockedEnumeration.hasMore()).thenReturn(true, true, true, true, false);
    PowerMockito.when(mockedEnumeration.next()).thenReturn(
            new NameClassPair("data.dir", String.class.getName()),
            new NameClassPair("parallelize", String.class.getName()),
            new NameClassPair("mutant.coverage", String.class.getName()),
            new NameClassPair("ant.home", String.class.getName())//
    );
    //
    PowerMockito.when(mockedInitialContext.toString()).thenReturn("Mocked Initial Context");
    PowerMockito.when(mockedInitialContext.list("java:/comp/env")).thenReturn(mockedEnumeration);
    //
    Context mockedEnvironmentContext = PowerMockito.mock(Context.class);
    PowerMockito.when(mockedInitialContext.lookup("java:/comp/env")).thenReturn(mockedEnvironmentContext);

    PowerMockito.when(mockedEnvironmentContext.lookup("mutant.coverage")).thenReturn("enabled");
    // FIXMED
    PowerMockito.when(mockedEnvironmentContext.lookup("parallelize")).thenReturn("enabled");
    //
    PowerMockito.when(mockedEnvironmentContext.lookup("data.dir"))
            .thenReturn(codedefendersHome.getAbsolutePath());

    PowerMockito.when(mockedEnvironmentContext.lookup("ant.home")).thenReturn("/usr/local");
    //
    return mockedInitialContext;
}
 
Example #20
Source File: ParallelizeTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    System.out.println("ParallelizeAntRunnerTest.MyContextFactory.getInitialContext()");
    InitialContext mockedInitialContext = PowerMockito.mock(InitialContext.class);
    NamingEnumeration<NameClassPair> mockedEnumeration = PowerMockito.mock(NamingEnumeration.class);
    // Look at this again ...
    PowerMockito.mockStatic(NamingEnumeration.class);
    //
    PowerMockito.when(mockedEnumeration.hasMore()).thenReturn(true, true, true, true, false);
    PowerMockito.when(mockedEnumeration.next()).thenReturn(
            new NameClassPair("data.dir", String.class.getName()),
            new NameClassPair("parallelize", String.class.getName()),
            new NameClassPair("mutant.coverage", String.class.getName()),
            new NameClassPair("ant.home", String.class.getName())//
    );

    PowerMockito.when(mockedInitialContext.toString()).thenReturn("Mocked Initial Context");
    PowerMockito.when(mockedInitialContext.list("java:/comp/env")).thenReturn(mockedEnumeration);

    Context mockedEnvironmentContext = PowerMockito.mock(Context.class);
    PowerMockito.when(mockedInitialContext.lookup("java:/comp/env")).thenReturn(mockedEnvironmentContext);

    PowerMockito.when(mockedEnvironmentContext.lookup("mutant.coverage")).thenReturn("enabled");
    // FIXME
    PowerMockito.when(mockedEnvironmentContext.lookup("parallelize")).thenReturn("enabled");

    PowerMockito.when(mockedEnvironmentContext.lookup("data.dir"))
            .thenReturn(codedefendersHome.getAbsolutePath());

    PowerMockito.when(mockedEnvironmentContext.lookup("ant.home")).thenReturn("/usr/local");

    return mockedInitialContext;
}
 
Example #21
Source File: RetryingContext.java    From james-project with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public NamingEnumeration<NameClassPair> list(final String name) throws NamingException {
    return (NamingEnumeration<NameClassPair>) new LoggingRetryHandler(
            DEFAULT_EXCEPTION_CLASSES, this, schedule, maxRetries) {

        @Override
        public Object operation() throws NamingException {
            return getDelegate().list(name);
        }
    }.perform();
}
 
Example #22
Source File: LdapSender.java    From iaf with Apache License 2.0 5 votes vote down vote up
/** 
 * Return a list of all of the subcontexts of the current context, which is relative to parentContext. 
 * @return an array of Strings containing a list of the subcontexts for a current context.
 */ 
public String[] getSubContextList (DirContext parentContext, String relativeContext, IPipeLineSession session) {
	String[] retValue = null;

	try {
		// Create a vector object and add the names of all of the subcontexts
		//  to it
		Vector n = new Vector();
		NamingEnumeration list = parentContext.list(relativeContext);
		if (log.isDebugEnabled()) log.debug("getSubCOntextList(context) : context = " + relativeContext);
		for (int x = 0; list.hasMore(); x++) {
			NameClassPair nc = (NameClassPair)list.next();
			n.addElement (nc);
		}

		// Create a string array of the same size as the vector object
		String contextList[] = new String[n.size()];
		for (int x = 0; x < n.size(); x++) {
			// Add each name to the array
			contextList[x] = ((NameClassPair)(n.elementAt(x))).getName();
		}
		retValue = contextList;

	} catch (NamingException e) {
		storeLdapException(e, session);
		log.error("Exception in operation [" + getOperation()+ "] ", e);
	}
	
	return retValue;
}
 
Example #23
Source File: SaslKrb5LDAPSecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunning() throws Exception {
   Hashtable<String, String> env = new Hashtable<>();
   env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   env.put(Context.SECURITY_AUTHENTICATION, "simple");
   env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
   env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
   DirContext ctx = new InitialDirContext(env);

   HashSet<String> set = new HashSet<>();

   NamingEnumeration<NameClassPair> list = ctx.list("ou=system");

   while (list.hasMore()) {
      NameClassPair ncp = list.next();
      set.add(ncp.getName());
   }

   Assert.assertTrue(set.contains("uid=admin"));
   Assert.assertTrue(set.contains("ou=users"));
   Assert.assertTrue(set.contains("ou=groups"));
   Assert.assertTrue(set.contains("ou=configuration"));
   Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));

   ctx.close();
}
 
Example #24
Source File: SimpleNamingContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(String root) throws NamingException {
	if (logger.isDebugEnabled()) {
		logger.debug("Listing name/class pairs under [" + root + "]");
	}
	return new NameClassPairEnumeration(this, root);
}
 
Example #25
Source File: CollectingNameClassPairCallbackHandlerTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    expectedResult = new Object();
    expectedNameClassPair = new NameClassPair(null, null);
    tested = new CollectingNameClassPairCallbackHandler() {
        public Object getObjectFromNameClassPair(NameClassPair nameClassPair) {
            assertThat(nameClassPair).isSameAs(expectedNameClassPair);
            return expectedResult;
        }
    };
}
 
Example #26
Source File: SelectorContext.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Enumerates the names bound in the named context, along with the class
 * names of objects bound to them.
 *
 * @param name the name of the context to list
 * @return an enumeration of the names and class names of the bindings in
 * this context. Each element of the enumeration is of type NameClassPair.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<NameClassPair> list(String name)
    throws NamingException {

    if (log.isDebugEnabled()) {
        log.debug(sm.getString("selectorContext.methodUsingString", "list",
                name));
    }

    return getBoundContext().list(parseName(name));
}
 
Example #27
Source File: BaseDirContext.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Enumerates the names bound in the named context, along with the class 
 * names of objects bound to them.
 * 
 * @param name the name of the context to list
 * @return an enumeration of the names and class names of the bindings in 
 * this context. Each element of the enumeration is of type NameClassPair.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<NameClassPair> list(String name)
    throws NamingException {

    if (!aliases.isEmpty()) {
        AliasResult result = findAlias(name);
        if (result.dirContext != null) {
            return result.dirContext.list(result.aliasName);
        }
    }

    // Next do a standard lookup
    List<NamingEntry> bindings = doListBindings(name);

    // Check the alternate locations
    List<NamingEntry> altBindings = null;

    String resourceName = "/META-INF/resources" + name;
    for (DirContext altDirContext : altDirContexts) {
        if (altDirContext instanceof BaseDirContext) {
            altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
        }
        if (altBindings != null) {
            if (bindings == null) {
                bindings = altBindings;
            } else {
                bindings.addAll(altBindings);
            }
        }
    }

    if (bindings != null) {
        return new NamingContextEnumeration(bindings.iterator());
    }

    // Really not found
    throw new NameNotFoundException(
            sm.getString("resources.notFound", name));
}
 
Example #28
Source File: ContextMapperCallbackHandler.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
/**
   * Cast the NameClassPair to a {@link Binding} and pass its object to
   * the ContextMapper.
   * 
   * @param nameClassPair
   *            a Binding instance.
   * @return the Object returned from the mapper.
   * @throws NamingException if an error occurs.
   * @throws ObjectRetrievalException if the object of the nameClassPair is null.
   */
  public T getObjectFromNameClassPair(NameClassPair nameClassPair) throws NamingException {
if (!(nameClassPair instanceof Binding)) {
	throw new IllegalArgumentException("Parameter must be an instance of Binding");
}

Binding binding = (Binding) nameClassPair;
      Object object = binding.getObject();
      if (object == null) {
          throw new ObjectRetrievalException(
                  "Binding did not contain any object.");
      }
      return mapper.mapFromContext(object);
  }
 
Example #29
Source File: IvmContext.java    From tomee with Apache License 2.0 5 votes vote down vote up
public NamingEnumeration<NameClassPair> list(final String name) throws NamingException {
    final Object obj = lookup(name);
    if (obj.getClass() == IvmContext.class) {
        return new MyListEnumeration(((IvmContext) obj).mynode);
    } else {
        return null;
    }
}
 
Example #30
Source File: StubContext.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
    return new NamingEnumerationStub();
}