LDAP:清空 binddn“”,身份验证类型从 none 变得简单
LDAP: Empty binddn“” and Authentication type becomes simple from none
正在 Spring MVC 和 JPA 中开发具有 Spring 安全性的应用程序。现在通过 LDAP 集成 OUD(Oracle 统一目录)。用户身份验证时,OUD 日志文件中来自 LDAP 的响应是
CONNECT conn=909681 from ******* to *******:1636 protocol=LDAPS
Bind REQ conn=909681 op=0 msgID=1 type=SIMPLE dn="" version=3
BindRES conn=909681 op=0 msgID=1 result=1 message="The directory
server could not find a network group for the bind dn "" because the
client connection does not match the connection criteria for any
network groups."
DISCONNECT conn=909681 reason="Client Disconnect"
security.xml 文件
中应用程序和 LDAP 之间的映射
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldaps://192.168.0.182:1636/o=company"/>
<property name="userDn" value="cn=userid,ou=groups,o=company"/>
<property name="password" value="password"/>
</bean>
<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" >
<constructor-arg>
<bean class="in.web.service.impl.CustomLdapBindAuthenticator">
<constructor-arg ref="contextSource"/>
<property name="userDnPatterns">
<list>
<value>cn={0},ou=groups</value>
</list>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="in.web.service.impl.CustomLdapUserAuthoritiesPopulator">
</bean>
</constructor-arg>
</bean>
CustomLdapBindAuthenticator 中的代码
public LdapUserDetails search(String cn) throws Exception {
Hashtable env = new Hashtable();
String sp = "com.sun.jndi.ldap.LdapCtxFactory";
env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
String [] urls = contextSource.getUrls();
for(String url: urls){
System.out.println("ldapurls="+url);
}
env.put(Context.PROVIDER_URL, urls[0]);
DirContext dctx = new InitialDirContext(env);
String base = "ou=groups,o=company";
System.out.println("BASE DN="+base);
SearchControls sc = new SearchControls();
String[] attributeFilter = {"cn", "fullName", "mail", "l", "mobile"};
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(&(cn="+cn+")(objectClass=*))";
NamingEnumeration results = dctx.search(base, filter, sc);
LdapUserDetails user = new LdapUserDetails();
while (results.hasMore()) {
SearchResult sr = (SearchResult) results.next();
Attributes attrs = sr.getAttributes();
user.setCn(getAttribute(attrs, "cn"));
user.setFullName(getAttribute(attrs, "fullName"));
user.setMail(getAttribute(attrs, "mail"));
user.setMobile(getAttribute(attrs, "mobile"));
user.setLocation(getAttribute(attrs, "l"));
}
dctx.close();
return user;
}
请问。帮我解决问题
- 我没有提到身份验证这么简单。从我在日志文件中获取 type=simple 的地方
- 为什么我得到 dn=""
提前致谢
似乎没有 network group 允许您的源 IP 访问该目录。由于没有匹配的网络组,您会在错误字符串中看到一个空 DN。管理网络组有两种方式:
ODSM Web 管理 GUI:'Configuration' 选项卡,常规配置 => 网络组
LDAP到配置目录(默认端口4444):cn=network groups,cn=config
此外,这可能是您删除私人信息时引入的问题,ID 不会是 cn=userid,o=company,ou=groups 而是 cn=userid,ou=groups,o=company (然后仅当用户位于名为 groups 的 OU 中时。我通常会在 OU 中看到名为组的 group 对象和 OU 中的用户对象命名为 users 或 employees 或 people.)
ETA:简单是 Spring LDAP 中使用的默认身份验证机制。您需要设置 DirContextAuthenticationStrategy 才能使用其他机制。
正在 Spring MVC 和 JPA 中开发具有 Spring 安全性的应用程序。现在通过 LDAP 集成 OUD(Oracle 统一目录)。用户身份验证时,OUD 日志文件中来自 LDAP 的响应是
CONNECT conn=909681 from ******* to *******:1636 protocol=LDAPS
Bind REQ conn=909681 op=0 msgID=1 type=SIMPLE dn="" version=3
BindRES conn=909681 op=0 msgID=1 result=1 message="The directory server could not find a network group for the bind dn "" because the client connection does not match the connection criteria for any network groups."
DISCONNECT conn=909681 reason="Client Disconnect"
security.xml 文件
中应用程序和 LDAP 之间的映射<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldaps://192.168.0.182:1636/o=company"/>
<property name="userDn" value="cn=userid,ou=groups,o=company"/>
<property name="password" value="password"/>
</bean>
<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" >
<constructor-arg>
<bean class="in.web.service.impl.CustomLdapBindAuthenticator">
<constructor-arg ref="contextSource"/>
<property name="userDnPatterns">
<list>
<value>cn={0},ou=groups</value>
</list>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="in.web.service.impl.CustomLdapUserAuthoritiesPopulator">
</bean>
</constructor-arg>
</bean>
CustomLdapBindAuthenticator 中的代码
public LdapUserDetails search(String cn) throws Exception {
Hashtable env = new Hashtable();
String sp = "com.sun.jndi.ldap.LdapCtxFactory";
env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
String [] urls = contextSource.getUrls();
for(String url: urls){
System.out.println("ldapurls="+url);
}
env.put(Context.PROVIDER_URL, urls[0]);
DirContext dctx = new InitialDirContext(env);
String base = "ou=groups,o=company";
System.out.println("BASE DN="+base);
SearchControls sc = new SearchControls();
String[] attributeFilter = {"cn", "fullName", "mail", "l", "mobile"};
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(&(cn="+cn+")(objectClass=*))";
NamingEnumeration results = dctx.search(base, filter, sc);
LdapUserDetails user = new LdapUserDetails();
while (results.hasMore()) {
SearchResult sr = (SearchResult) results.next();
Attributes attrs = sr.getAttributes();
user.setCn(getAttribute(attrs, "cn"));
user.setFullName(getAttribute(attrs, "fullName"));
user.setMail(getAttribute(attrs, "mail"));
user.setMobile(getAttribute(attrs, "mobile"));
user.setLocation(getAttribute(attrs, "l"));
}
dctx.close();
return user;
}
请问。帮我解决问题
- 我没有提到身份验证这么简单。从我在日志文件中获取 type=simple 的地方
- 为什么我得到 dn="" 提前致谢
似乎没有 network group 允许您的源 IP 访问该目录。由于没有匹配的网络组,您会在错误字符串中看到一个空 DN。管理网络组有两种方式:
ODSM Web 管理 GUI:'Configuration' 选项卡,常规配置 => 网络组
LDAP到配置目录(默认端口4444):cn=network groups,cn=config
此外,这可能是您删除私人信息时引入的问题,ID 不会是 cn=userid,o=company,ou=groups 而是 cn=userid,ou=groups,o=company (然后仅当用户位于名为 groups 的 OU 中时。我通常会在 OU 中看到名为组的 group 对象和 OU 中的用户对象命名为 users 或 employees 或 people.)
ETA:简单是 Spring LDAP 中使用的默认身份验证机制。您需要设置 DirContextAuthenticationStrategy 才能使用其他机制。