Steps to reproduce:
1. Create an empty grails application
2. Start console and enter the following script (need to have LDAP server up and running)
import javax.naming.*
import javax.naming.ldap.*
try {
LdapContext context = new InitialLdapContext((Hashtable) [
(Context.INITIAL_CONTEXT_FACTORY): "com.sun.jndi.ldap.LdapCtxFactory",
(Context.PROVIDER_URL) : "ldap://localhost:389", // change to your LDAP server address
(Context.SECURITY_AUTHENTICATION): "simple",
(Context.SECURITY_PRINCIPAL) : "DOMAIN
invalid",
(Context.SECURITY_CREDENTIALS) : "invalid",
(Context.REFERRAL) : "follow",
(Context.BATCHSIZE) : "30"
], (Control[]) []);
println context.getDefaultInitCtx()
context.reconnect()
} catch (AuthenticationException e) {
println "NOT lOGGED IN"
}
Current result:
- this scripts shows that context.getDefaultInitCtx() returns org.springframework.mock.jndi.SimpleNamingContext
- an exception of type javax.naming.NotContextException with message "Not an instance of LdapContext" is thrown
Expected result:
- the script prints "NOT LOGGED IN" because instantiation of InitialLdapContext throws an AuthenticationException.
Remarks:
Tested against Active Directory LDAP.