Spring ActiveDirectoryLdapAuthenticationProvider日志和convertSubErrorCodesToExceptions

Spring ActiveDirectoryLdapAuthenticationProvider日志和convertSubErrorCodesToExceptions,spring,spring-security,active-directory,ldap,Spring,Spring Security,Active Directory,Ldap,在尝试使用AD用户和密码登录时,是否有方法使用ActiveDirectoryLdapAuthenticationProvider查看登录请求中发生的情况的日志 我将convertSubErrorCodesToExceptions设置为true,但没有收到任何消息。当我尝试登录时,我得到的只是重定向到登录失败页面,但我不知道发生了什么 <beans:bean id="ldapActiveDirectoryAuthProvider" class="org.spring

在尝试使用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


    }
}

有些地方不正确,因为没有打印开头的测试消息。

为什么会出现在日志中?这是发送到system.out的,不是您的日志记录…我说的是convertSubErrorCodesToExceptions错误消息,出于某种原因,直到我创建了一个自定义ActiveDirectoryLdapAuthenticationProvider类,它们才显示出来。该方法只是一个触发器,告诉您某些代码会导致异常。可能是带有消息的AuthenticationException,这些异常由ExceptionTranslationFilter处理,它仅在启用调试时记录这些异常。