How to connect to Ldap server using java?
Please find my below code and Help me connect to LDAP.
My code below :
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://192.168.0.214:389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=Users,DC=estsecondary,DC=com");
environment.put(Context.SECURITY_CREDENTIALS, "*****8");
try {
LdapContext ctx = new InitialLdapContext(environment, null);
}catch (AuthenticationNotSupportedException exception) {
System.out.println("The authentication is not supported by the server");
} catch (AuthenticationException exception){
System.out.println("Incorrect password or username");
}catch (NamingException exception){
System.out.println("Error when trying to create the context");
}
But I'm not able to connect. I'm getting "The authentication is not supported by the server".Please find my LDAP structure below.
enter image description here
java ldap
add a comment |
Please find my below code and Help me connect to LDAP.
My code below :
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://192.168.0.214:389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=Users,DC=estsecondary,DC=com");
environment.put(Context.SECURITY_CREDENTIALS, "*****8");
try {
LdapContext ctx = new InitialLdapContext(environment, null);
}catch (AuthenticationNotSupportedException exception) {
System.out.println("The authentication is not supported by the server");
} catch (AuthenticationException exception){
System.out.println("Incorrect password or username");
}catch (NamingException exception){
System.out.println("Error when trying to create the context");
}
But I'm not able to connect. I'm getting "The authentication is not supported by the server".Please find my LDAP structure below.
enter image description here
java ldap
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14
add a comment |
Please find my below code and Help me connect to LDAP.
My code below :
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://192.168.0.214:389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=Users,DC=estsecondary,DC=com");
environment.put(Context.SECURITY_CREDENTIALS, "*****8");
try {
LdapContext ctx = new InitialLdapContext(environment, null);
}catch (AuthenticationNotSupportedException exception) {
System.out.println("The authentication is not supported by the server");
} catch (AuthenticationException exception){
System.out.println("Incorrect password or username");
}catch (NamingException exception){
System.out.println("Error when trying to create the context");
}
But I'm not able to connect. I'm getting "The authentication is not supported by the server".Please find my LDAP structure below.
enter image description here
java ldap
Please find my below code and Help me connect to LDAP.
My code below :
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://192.168.0.214:389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=Users,DC=estsecondary,DC=com");
environment.put(Context.SECURITY_CREDENTIALS, "*****8");
try {
LdapContext ctx = new InitialLdapContext(environment, null);
}catch (AuthenticationNotSupportedException exception) {
System.out.println("The authentication is not supported by the server");
} catch (AuthenticationException exception){
System.out.println("Incorrect password or username");
}catch (NamingException exception){
System.out.println("Error when trying to create the context");
}
But I'm not able to connect. I'm getting "The authentication is not supported by the server".Please find my LDAP structure below.
enter image description here
java ldap
java ldap
edited Nov 20 '18 at 11:28
Dang Nguyen
660421
660421
asked Nov 20 '18 at 10:01
Darsh GaonDarsh Gaon
11
11
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14
add a comment |
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14
add a comment |
1 Answer
1
active
oldest
votes
You comment this:
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
I assume that is the exception message. It is telling you that the connection has been refused because you are trying to send the BindSimple authentication credentials over an unencrypted connection.
You are using port 386 which is (by default) a non SSL port. If you want to use this port, you could possibly tell JNDI to do TLS negotiation before you attempt to authenticate. There is some example code in the JNDI documentation.
Another alternative may be to change the URL to
ldaps://192.168.0.214:636
and use SSL for the initial connection.
In either case, you will need to provide the appropriate keys / certs in a keystore.
A final alternative would be to configure the LDAP server to accept BindSimple credentials over an insecure connection. But that is ... insecure ... and you would potentially be putting your infrastructure at risk by doing this. Don't.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390478%2fhow-to-connect-to-ldap-server-using-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You comment this:
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
I assume that is the exception message. It is telling you that the connection has been refused because you are trying to send the BindSimple authentication credentials over an unencrypted connection.
You are using port 386 which is (by default) a non SSL port. If you want to use this port, you could possibly tell JNDI to do TLS negotiation before you attempt to authenticate. There is some example code in the JNDI documentation.
Another alternative may be to change the URL to
ldaps://192.168.0.214:636
and use SSL for the initial connection.
In either case, you will need to provide the appropriate keys / certs in a keystore.
A final alternative would be to configure the LDAP server to accept BindSimple credentials over an insecure connection. But that is ... insecure ... and you would potentially be putting your infrastructure at risk by doing this. Don't.
add a comment |
You comment this:
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
I assume that is the exception message. It is telling you that the connection has been refused because you are trying to send the BindSimple authentication credentials over an unencrypted connection.
You are using port 386 which is (by default) a non SSL port. If you want to use this port, you could possibly tell JNDI to do TLS negotiation before you attempt to authenticate. There is some example code in the JNDI documentation.
Another alternative may be to change the URL to
ldaps://192.168.0.214:636
and use SSL for the initial connection.
In either case, you will need to provide the appropriate keys / certs in a keystore.
A final alternative would be to configure the LDAP server to accept BindSimple credentials over an insecure connection. But that is ... insecure ... and you would potentially be putting your infrastructure at risk by doing this. Don't.
add a comment |
You comment this:
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
I assume that is the exception message. It is telling you that the connection has been refused because you are trying to send the BindSimple authentication credentials over an unencrypted connection.
You are using port 386 which is (by default) a non SSL port. If you want to use this port, you could possibly tell JNDI to do TLS negotiation before you attempt to authenticate. There is some example code in the JNDI documentation.
Another alternative may be to change the URL to
ldaps://192.168.0.214:636
and use SSL for the initial connection.
In either case, you will need to provide the appropriate keys / certs in a keystore.
A final alternative would be to configure the LDAP server to accept BindSimple credentials over an insecure connection. But that is ... insecure ... and you would potentially be putting your infrastructure at risk by doing this. Don't.
You comment this:
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
I assume that is the exception message. It is telling you that the connection has been refused because you are trying to send the BindSimple authentication credentials over an unencrypted connection.
You are using port 386 which is (by default) a non SSL port. If you want to use this port, you could possibly tell JNDI to do TLS negotiation before you attempt to authenticate. There is some example code in the JNDI documentation.
Another alternative may be to change the URL to
ldaps://192.168.0.214:636
and use SSL for the initial connection.
In either case, you will need to provide the appropriate keys / certs in a keystore.
A final alternative would be to configure the LDAP server to accept BindSimple credentials over an insecure connection. But that is ... insecure ... and you would potentially be putting your infrastructure at risk by doing this. Don't.
edited Nov 20 '18 at 11:06
answered Nov 20 '18 at 11:00
Stephen CStephen C
516k69564921
516k69564921
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390478%2fhow-to-connect-to-ldap-server-using-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you include the stacktrace from the exception you're catching on line 12?
– Jeroen Steenbeeke
Nov 20 '18 at 10:04
It seems that the authentication type is not supported by the server. There are three authentication types, including 'none'. Here is more information about authentication types: docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
– gil.fernandes
Nov 20 '18 at 10:07
The authentication is not supported by the server[LDAP: error code 8 - BindSimple: Transport encryption required.]
– Darsh Gaon
Nov 20 '18 at 10:07
Can you add e.printStackTrace(); before System.out.println("The authentication is not supported by the server"); and share the error stack?
– Sheetal Mohan Sharma
Nov 20 '18 at 10:14