Olá
Estou tentando realizar uma autenticação SSL no Acitve Directory já possuo o certificado(.cer) tentei
registrar no keytool da seguinte forma:
keytool -import -alias certificadoLDAP -file c:\certificadoLDAP.cer -keystore certificadoLDAPcacerts
Quando tento chamar em minha classe Java dá o seguinte erro:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target]
Segue abaixo o código que estou utilizando:
public static String alterarSenha(String login, String senhaAntiga,String senhaNova) {
String msgErro = new String();
try {
char SEP = File.separatorChar;
String keystore = System.getProperty("java.home") + SEP + "lib" + SEP + "security" + SEP + "cacerts";
System.setProperty("javax.net.ssl.trustStore", keystore);
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
//System.setProperty("javax.net.debug", "all");
Hashtable<String, String> env = new Hashtable<String, String>(5);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"CN=" + usuarioServico + ",CN=Users," + dominio);
env.put(Context.SECURITY_CREDENTIALS, senhaServico);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://fenix:636/" + dominio); // 636 é a porta do ldaps
env.put(Context.SECURITY_PROTOCOL, "ssl");
//String entryDN = "cn=usuario,ou=Usuarios,dc=dominio,dc=com,dc=br";
// A password deve estar em unicode e entre aspas duplas
String oldQuotedPassword = "\"" + senhaAntiga + "\"";
byte[] oldUnicodePassword = oldQuotedPassword.getBytes("UTF-16LE");
String newQuotedPassword = "\"" + senhaNova + "\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");
ModificationItem[] mods = new ModificationItem[2];
mods[1] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute("unicodePwd", oldUnicodePassword));
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,new BasicAttribute("unicodePwd", newUnicodePassword));
// Troca a senha
DirContext ctx = new InitialDirContext(env);
//ctx.modifyAttributes(entryDN, mods);
} catch (NamingException ex){
String erroLDAP = ex.getExplanation();
if (erroLDAP != null && erroLDAP.length() > 103){
erroLDAP = erroLDAP.substring(100, 103);
if (erroLDAP.equalsIgnoreCase("525")){
msgErro = "Usuário inválido!";
}else if (erroLDAP.equalsIgnoreCase("52e")){
//msgErro = "Credenciais Inválidas";
msgErro = "Senha Inválida!";
}else if (erroLDAP.equalsIgnoreCase("530")){
msgErro = "Usuário temporariamente bloqueado!";
}else if (erroLDAP.equalsIgnoreCase("532")){
msgErro = "Senha expirada!";
}else if (erroLDAP.equalsIgnoreCase("533")){
msgErro = "Conta de usuário desabilitada!";
}else if (erroLDAP.equalsIgnoreCase("701")){
msgErro = "Conta expirada!";
}else if (erroLDAP.equalsIgnoreCase("773")){
//msgErro = "user must reset password";
msgErro = "O usuário deve reiniciar sua senha!";
}else{
msgErro = "Não foi possível conectar no servidor LDAP.";
ex.printStackTrace();
}
}else{
msgErro = "Não foi possível conectar no servidor LDAP.";
ex.printStackTrace();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
Se alguém poder me dar uma luz agradeço desde já…
Valeu!