/** * 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 { return getLdapContext((Object) username, password); }
/** * This implementation delegates to {@link #getLdapContext(Object, Object)} using the * {@link #getSystemUsername() systemUsername} and {@link #getSystemPassword() systemPassword} properties as * arguments. * * @return the system LdapContext * @throws NamingException if there is a problem connecting to the LDAP directory */ public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext((Object)getSystemUsername(), getSystemPassword()); }
@Test(expected = IllegalStateException.class) public void testGetLdapContextWithoutUrl() throws NamingException { factory.getLdapContext((Object) "foo", "bar"); }
@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 testEmptyByteArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new byte[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"); }
/** * 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 { return getLdapContext((Object) username, password); }
/** * This implementation delegates to {@link #getLdapContext(Object, Object)} using the * {@link #getSystemUsername() systemUsername} and {@link #getSystemPassword() systemPassword} properties as * arguments. * * @return the system LdapContext * @throws NamingException if there is a problem connecting to the LDAP directory */ public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext((Object)getSystemUsername(), getSystemPassword()); }
/** * 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 { return getLdapContext((Object) username, password); }
/** * This implementation delegates to {@link #getLdapContext(Object, Object)} using the * {@link #getSystemUsername() systemUsername} and {@link #getSystemPassword() systemPassword} properties as * arguments. * * @return the system LdapContext * @throws NamingException if there is a problem connecting to the LDAP directory */ public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext((Object)getSystemUsername(), getSystemPassword()); }