ktm*_*124 5 java ldap spring-ldap
我阅读了Spring LDAP参考文档,但无法确定针对LDAP服务器的用户身份验证是否自动化.
通过"自动化",我的意思是如果你在你的用户提供userDn和密码,它会在bean实例化时自动发生ContextSource.也就是说,程序员永远不必打电话LdapTemplate.authenticate(...)- 它发生在"幕后".
所以我想知道
谢谢,
ktm
编辑:我在我写的一些代码的上下文中问这个问题.以下ContextSource是我的beans文件中的一个上下文源,用户可以选择使用它.它用于在运行时配置userDn和密码(出于安全原因).我想知道LDAP应用程序是否实际使用我在运行时在身份验证中收集的userDn/password.(验证是否在我的代码执行之前?它是否忽略我的代码配置的userDn/password字段?)
public class RuntimeContext extends LdapContextSource {
public RuntimeContext() {
super();
if (!resolveAuthInfo()) {
System.out.println("Failed to resolve auth info. Exiting...");
System.exit(1);
}
}
public boolean resolveAuthInfo()
{
String myUserDn, myPassword;
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.print("userDn: ");
myUserDn = br.readLine();
System.out.print("password: ");
myPassword = br.readLine();
} catch (IOException e) {
return false;
}
super.setUserDn(myUserDn);
super.setPassword(myPassword);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道 LDAP 应用程序是否实际上会使用我在身份验证运行时收集的 userDn/密码。
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html
它将使用您在运行时收集的用户名和密码。根据您配置 bean 的方式,LDAP 身份验证将使用 Spring 中的两个路径之一:
BindAuthenticator)PasswordComparisonAuthenticator)这些身份验证器在 的上下文中调用,LdapAuthenticationProvider可以在安全命名空间配置中将其配置为身份验证器:
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="usernamePasswordUserDetailsService">
<password-encoder ref="passwordEncoder">
<salt-source ref="saltSource"/>
</password-encoder>
</authentication-provider>
<authentication-provider ref="ldapAuthenticationProvider"/>
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
当UsernamePasswordAuthenticationFilter调用时(通过 /auth/login 页面):
<http auto-config="true">
<form-login login-page="/auth/login"
login-processing-url="/auth/j_security_check"/>
<logout invalidate-session="true" logout-url="/auth/logout"/>
</http>
Run Code Online (Sandbox Code Playgroud)
使用用户名和密码创建令牌。响应LdapAuthenticationProvider该令牌类型:
public class LdapAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {
...
public boolean supports(Class<?> authentication) {
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
}
}
Run Code Online (Sandbox Code Playgroud)
并使用您存储在中的信息LdapContextSource进行身份验证。
| 归档时间: |
|
| 查看次数: |
2552 次 |
| 最近记录: |