private LdapContextFactory ensureContextFactory() { if (this.ldapContextFactory == null) { if (log.isDebugEnabled()) { log.debug("No LdapContextFactory specified - creating a default instance."); } DefaultLdapContextFactory defaultFactory = new DefaultLdapContextFactory(); defaultFactory.setPrincipalSuffix(this.principalSuffix); defaultFactory.setSearchBase(this.searchBase); defaultFactory.setUrl(this.url); defaultFactory.setSystemUsername(this.systemUsername); defaultFactory.setSystemPassword(this.systemPassword); this.ldapContextFactory = defaultFactory; } return this.ldapContextFactory; }
/** * This is the only test that does not fake the JNDI environment. It is provided for 100% test coverage. * * @throws javax.naming.NamingException thrown because the host is always broken. */ @Test(expected = NamingException.class) public void testGetLdapContext() throws NamingException { factory = new DefaultLdapContextFactory(); //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"); }
validateAuthenticationInfo(env); return createLdapContext(env);
@Test(expected = AuthenticationException.class) public void testEmptyByteArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new byte[0]); }
public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext(systemUsername, systemPassword); }
@Before public void setUp() { factory = new DefaultLdapContextFactory() { //Fake a JNDI DefaultLdapContextFactory for the tests: @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { return createNiceMock(LdapContext.class); } }; }
@Test(expected = AuthenticationException.class) public void testEmptyNullCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", null); }
/** * Deprecated - use {@link #getLdapContext(Object, Object)} instead. This will be removed before Apache Shiro 2.0. * * @param username the username to use when creating the connection. * @param password the password to use when creating the connection. * @return a {@code LdapContext} bound using the given username and password. * @throws javax.naming.NamingException if there is an error creating the context. * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than * String principals and credentials can be used. Shiro no longer calls this method - it will be * removed before the 2.0 release. */ @Deprecated public LdapContext getLdapContext(String username, String password) throws NamingException { if (username != null && principalSuffix != null) { username += principalSuffix; } return getLdapContext((Object) username, password); }
private LdapContextFactory ensureContextFactory() { if (this.ldapContextFactory == null) { if (log.isDebugEnabled()) { log.debug("No LdapContextFactory specified - creating a default instance."); } DefaultLdapContextFactory defaultFactory = new DefaultLdapContextFactory(); defaultFactory.setPrincipalSuffix(this.principalSuffix); defaultFactory.setSearchBase(this.searchBase); defaultFactory.setUrl(this.url); defaultFactory.setSystemUsername(this.systemUsername); defaultFactory.setSystemPassword(this.systemPassword); this.ldapContextFactory = defaultFactory; } return this.ldapContextFactory; }
@Test(expected = AuthenticationException.class) public void testEmptyStringCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", ""); }
@Test(expected = IllegalStateException.class) public void testGetLdapContextWithoutUrl() throws NamingException { factory.getLdapContext((Object) "foo", "bar"); }
validateAuthenticationInfo(env); return createLdapContext(env);
private LdapContextFactory ensureContextFactory() { if (this.ldapContextFactory == null) { if (log.isDebugEnabled()) { log.debug("No LdapContextFactory specified - creating a default instance."); } DefaultLdapContextFactory defaultFactory = new DefaultLdapContextFactory(); defaultFactory.setPrincipalSuffix(this.principalSuffix); defaultFactory.setSearchBase(this.searchBase); defaultFactory.setUrl(this.url); defaultFactory.setSystemUsername(this.systemUsername); defaultFactory.setSystemPassword(this.systemPassword); this.ldapContextFactory = defaultFactory; } return this.ldapContextFactory; }
@Test(expected = AuthenticationException.class) public void testEmptyCharArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new char[0]); }
public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext(systemUsername, systemPassword); }
/** * Deprecated - use {@link #getLdapContext(Object, Object)} instead. This will be removed before Apache Shiro 2.0. * * @param username the username to use when creating the connection. * @param password the password to use when creating the connection. * @return a {@code LdapContext} bound using the given username and password. * @throws javax.naming.NamingException if there is an error creating the context. * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than * String principals and credentials can be used. Shiro no longer calls this method - it will be * removed before the 2.0 release. */ @Deprecated public LdapContext getLdapContext(String username, String password) throws NamingException { if (username != null && principalSuffix != null) { username += principalSuffix; } return getLdapContext((Object) username, password); }
public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext(systemUsername, systemPassword); }
/** * Deprecated - use {@link #getLdapContext(Object, Object)} instead. This will be removed before Apache Shiro 2.0. * * @param username the username to use when creating the connection. * @param password the password to use when creating the connection. * @return a {@code LdapContext} bound using the given username and password. * @throws javax.naming.NamingException if there is an error creating the context. * @deprecated the {@link #getLdapContext(Object, Object)} method should be used in all cases to ensure more than * String principals and credentials can be used. Shiro no longer calls this method - it will be * removed before the 2.0 release. */ @Deprecated public LdapContext getLdapContext(String username, String password) throws NamingException { if (username != null && principalSuffix != null) { username += principalSuffix; } return getLdapContext((Object) username, password); }