javax.security.auth.login异常

时间:2011-11-22 13:34:22

标签: java authentication ldap

代码正在尝试针对LDAP服务器进行身份验证。当用户的密码或帐户过期时,它必须抛出错误。

当我尝试使用过期的密码/帐户登录时,会抛出FailedLoginException

FailedLoginException! Password Incorrect/Password Required.

文档说明它应该抛出AccountExpiredExceptionCredentialExpiredException

如何找到密码或帐户是否已过期?

以下是我的代码(简化)。

            //Create login context
            LoginContext lc = null;
            try {
                lc = new LoginContext("applicationPolicyName", new UsernamePasswordHandler(username, password));
            } catch(LoginException le) {
                log.info("LoginContext cannot be created. "+ le.getMessage());
            } catch(SecurityException se) {
                log.info("LoginContext cannot be created. "+ se.getMessage());
            }               
            try {
                lc.login();
            } catch (AccountExpiredException e) {
                log.info("AccountExpiredException!. "+ e.getMessage());
            } catch (CredentialExpiredException e) {
                log.info("CredentialExpiredException!. "+ e.getMessage());
            } catch (FailedLoginException e) {
                log.info("FailedLoginException!. "+ e.getMessage());
            } catch(LoginException le) {
                log.info("Authentication failed. " + le.getMessage());
            }

0 个答案:

没有答案