@Test(expected = AuthenticationException.class) public void testEmptyByteArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new byte[0]); }
@Test(expected = AuthenticationException.class) public void testEmptyCharArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new char[0]); }
@Test(expected = AuthenticationException.class) public void testEmptyStringCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", ""); }
@Test(expected = AuthenticationException.class) public void testEmptyNullCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", null); }
/** * This is the only test that does not fake the JNDI environment. It is provided for 100% test coverage. * * @throws NamingException thrown because the host is always broken. */ @Test(expected = NamingException.class) public void testGetLdapContext() throws NamingException { factory = new JndiLdapContextFactory(); //garbage URL to test that the context is being created, but fails: String brokenHost = UUID.randomUUID().toString(); factory.setUrl("ldap://" + brokenHost + ":389"); factory.getLdapContext((Object) "foo", "bar"); }
@Test public void testGetLdapContextDefault() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object) "foo", "bar"); }
@SuppressWarnings({"deprecation"}) @Test public void testGetLdapContextStringArguments() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setUrl("ldap://localhost:389"); factory.getLdapContext("foo", "bar"); }
contextFactory.setUrl(securityConfig.getShiroLDAPUrl());
@Test public void testGetSystemLdapContext() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNotNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setSystemUsername("foo"); factory.setSystemPassword("bar"); factory.setUrl("ldap://localhost:389"); factory.getSystemLdapContext(); }
@Test public void testGetSystemLdapContextPoolingDisabled() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setSystemUsername("foo"); factory.setSystemPassword("bar"); factory.setPoolingEnabled(false); factory.setUrl("ldap://localhost:389"); factory.getSystemLdapContext(); }
@Inject @SuppressWarnings("unchecked") public ConcordLdapContextFactory(LdapConfiguration cfg) { JndiLdapContextFactory f = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { String url = cfg.getUrl(); if (url != null && url.startsWith("ldaps:")) { env.put("java.naming.ldap.factory.socket", TrustingSslSocketFactory.class.getName()); } return super.createLdapContext(env); } }; f.setUrl(cfg.getUrl()); f.setSystemUsername(cfg.getSystemUsername()); f.setSystemPassword(cfg.getSystemPassword()); f.setPoolingEnabled(true); this.delegate = f; }
protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword, String userNameTemplate) { JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory(); jndiLdapContextFactory.setUrl(ldapUrl); jndiLdapContextFactory.setSystemUsername(systemUser); jndiLdapContextFactory.setSystemPassword(systemUserPassword); ldapRealm = new JndiLdapRealm(); ldapRealm.setContextFactory(jndiLdapContextFactory); ldapRealm.setUserDnTemplate(userNameTemplate); ldapRealm.init(); } }
contextFactory.setUrl(securityConfig.getShiroLDAPUrl());
contextFactory.setUrl(securityConfig.getShiroLDAPUrl());
environment.put( JNDI_LDAP_READ_TIMEOUT, readTimeoutMillis.toString() ); contextFactory.setEnvironment( environment ); contextFactory.setUrl( parseLdapServerUrl( config.get( SecuritySettings.ldap_server ) ) ); contextFactory.setAuthenticationMechanism( config.get( SecuritySettings.ldap_authentication_mechanism ) ); contextFactory.setReferral( config.get( SecuritySettings.ldap_referral ) );