在尝试使用AD用户和密码进行记录时,是否可以使用ActiveDirectoryLdapAuthenticationProvider查看登录请求中发生的事件的日志?
我将convertSubErrorCodesToExceptions设置为true但我没有收到任何消息。当我尝试登录时,我得到的是重定向到登录失败页面,但我不知道发生了什么。
<beans:bean id="ldapActiveDirectoryAuthProvider"
class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<beans:constructor-arg value="domain" />
<beans:constructor-arg value="ldap://site/"/>
<beans:property name="userDetailsContextMapper" ref="tdrUserDetailsContextMapper"/>
<beans:property name="useAuthenticationRequestCredentials" value="true"/>
<beans:property name="convertSubErrorCodesToExceptions" value="true" />
</beans:bean>
<beans:bean id="tdrUserDetailsContextMapper" class="com.test9.security9.service.CustomUserDetailsContextMapper"/>
这是我的自定义映射器类
public class CustomUserDetailsContextMapper implements UserDetailsContextMapper{
// private static final long serialVersionUID = 3962976258168853984L;
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authority) {
String role="admin";
System.out.println("TEST");
if(username.equals("usuario"))role="admin";
else role="user";
List<SimpleGrantedAuthority> authList = getAuthorities(role);
return new User(username, "", true, true, true, true, authList);
}
private List<SimpleGrantedAuthority> getAuthorities(String role) {
List<SimpleGrantedAuthority> authList = new ArrayList<SimpleGrantedAuthority>();
authList.add(new SimpleGrantedAuthority("ROLE_USER"));
//you can also add different roles here
//for example, the user is also an admin of the site, then you can add ROLE_ADMIN
//so that he can view pages that are ROLE_ADMIN specific
if (role != null && role.trim().length() > 0) {
if (role.equals("admin")) {
authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
}
}
return authList;
}
@Override
public void mapUserToContext(UserDetails arg0, DirContextAdapter arg1) {
// TODO Auto-generated method stub
}
}
有些东西不对,因为我没有打印开头的TEST消息。