List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:net.identio.server.service.authentication.ldap.LdapConnectionFactory.java
private InitialLdapContext createContext(LdapAuthMethod ldapAuthMethod, String userDn, String password) throws NamingException { LOG.debug("Begin creation of an LDAP connection to: {}", ldapAuthMethod.getName()); int currentUrlIndexTs = currentUrlIndex; String currentUrl = ldapAuthMethod.getLdapUrl().get(currentUrlIndexTs); Hashtable<String, String> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, currentUrl); if (currentUrl.startsWith("ldaps://")) { // Add a custom SSL Socket factory to validate server CA env.put("java.naming.ldap.factory.socket", "net.identio.server.service.authentication.ldap.LdapSslSocketFactory"); }//from www . j a va 2 s .co m if (userDn != null) { env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, userDn); env.put(Context.SECURITY_CREDENTIALS, password); } InitialLdapContext ctx; try { ctx = new InitialLdapContext(env, null); } catch (CommunicationException e) { LOG.error("Error when contacting LDAP server {}", ldapAuthMethod.getLdapUrl().get(currentUrlIndexTs)); if (ldapAuthMethod.getLdapUrl().size() > 1) { int newCurrentUrlIndex = currentUrlIndexTs < ldapAuthMethod.getLdapUrl().size() - 1 ? currentUrlIndexTs + 1 : 0; LOG.error("Switching to LDAP server {}", ldapAuthMethod.getLdapUrl().get(newCurrentUrlIndex)); currentUrlIndex = newCurrentUrlIndex; env.put(Context.PROVIDER_URL, ldapAuthMethod.getLdapUrl().get(newCurrentUrlIndex)); ctx = new InitialLdapContext(env, null); } else { throw e; } } return ctx; }
From source file:org.eclipse.virgo.snaps.SnapsTagTests.java
@Test public void snapsFromServiceRegistry() throws JspException, InvalidSyntaxException { Dictionary<String, Object> properties1 = new Hashtable<String, Object>(); properties1.put("a", "b"); properties1.put("c", new Integer(6)); ServiceReference<?> serviceReference1 = createServiceReference(properties1); Dictionary<String, Object> properties2 = new Hashtable<String, Object>(); properties2.put("d", "e"); properties2.put("f", Boolean.TRUE); ServiceReference<?> serviceReference2 = createServiceReference(properties2); expect(servletContext.getAttribute(WebContainer.ATTRIBUTE_BUNDLE_CONTEXT)).andReturn(bundleContext); Bundle bundle = createMock(Bundle.class); expect(bundleContext.getBundle()).andReturn(bundle); expect(bundle.getBundleId()).andReturn(27L); expect(bundleContext.getServiceReferences("org.eclipse.virgo.snaps.core.internal.Snap", "(snap.host.id=27)")).andReturn(new ServiceReference[] { serviceReference1, serviceReference2 }); expect(serviceReference1.compareTo(serviceReference2)).andReturn(1).anyTimes(); expect(serviceReference2.compareTo(serviceReference1)).andReturn(-1).anyTimes(); replay(servletContext, bundleContext, serviceReference1, serviceReference2, bundle); snapsTag.doStartTag();//w w w .j a v a 2s . c o m verify(servletContext, bundleContext, serviceReference1, serviceReference2, bundle); @SuppressWarnings("unchecked") List<Snap> snaps = (List<Snap>) pageContext.getAttribute(SnapsTag.SNAPS_ATTRIBUTE_NAME); assertNotNull(snaps); assertEquals(2, snaps.size()); Snap snap = snaps.get(1); assertEquals("b", snap.getProperties().get("a")); assertEquals(new Integer(6), snap.getProperties().get("c")); snap = snaps.get(0); assertEquals("e", snap.getProperties().get("d")); assertEquals(Boolean.TRUE, snap.getProperties().get("f")); }