问题描述
我的 Spring Boot 应用程序存在以下问题
我想达到什么目的?
我必须进行 ldap 查询才能搜索成功登录。在这样做之前,我需要使用某些值实例化一个 Properties 类,并在查询期间将此实例传递给该方法。我必须注入 BlindSSLFactory 类,以便在 ldap 查询期间绕过我们特定用例的 SSL 检查。
props.put("java.naming.ldap.factory.socket",BlindSSLSocketFactory.class.getName());
什么不起作用?
如果我从eclipse运行项目,一切正常并且类被注入到属性中,没有任何问题。但是,当我将项目导出为 jar 文件并在外部运行时,我发现未正确创建 Properties 实例。我进行了远程调试,在将此类添加为键值时,它基本上会抛出异常并且不会添加它,尽管填充其他值没有任何问题。
InitialDirContext context = null;
try {
Properties props = new Properties();
//use this line if you wanna discard ssl certificate validation
props.put("java.naming.ldap.factory.socket",BlindSSLSocketFactory.class.getName());
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL,ldapServerUrl);
props.put(Context.Security_PRINCIPAL,username);
props.put(Context.Security_CREDENTIALS,password);
context = new InitialDirContext(props);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_ScopE);
NamingEnumeration<SearchResult> results = context.search(
toDC(SettingsResolver.getInstance().getSetting(
"ldap.server.domain.name")),String.format(
"(& (userPrincipalName=%s)(objectClass=user))",this.username),controls);
return results.hasMore();
} catch (NamingException namingException) {
logger.error(
"Exception occurred while authenticating to LDAP Server: ",namingException);
throw namingException;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)