LdapCustomAuthenticationProvider extends LdapAuthenticationProvider { protected Boolean checkExpiredPassword(Attributes attributes) { return attributes.get(LdapAttributes.PWD_GRACE_LOGIN) != null; } LdapCustomAuthenticationProvider(LdapAuthenticator authenticator,
                                            LdapAuthoritiesPopulator authoritiesPopulator); void setUserDetailsService(UserDetailsService userDetailsService);  }
@Test public void shouldSetExpiredPasswordWhenPwdGraceUseTimeIsActive(){ Attribute pwdGraceUseTime = new BasicAttribute("pwdGraceUseTime"); Attributes attributes = new BasicAttributes(); attributes.put(pwdGraceUseTime); when(ldapUserDetails.getAttributes()).thenReturn(attributes); User userForTest = getUserForTest(); Boolean passExpired = sut.checkExpiredPassword(ldapUserDetails.getAttributes()); userForTest.setPasswordExpired(passExpired); assertThat(passExpired ,is(true)); }
@Test public void shouldNotSetExpiredPasswordWhenPwdGraceUseTimeIsActive(){ Attribute noPwdGrace = new BasicAttribute("noPwdGrace"); Attributes attributes = new BasicAttributes(); attributes.put(noPwdGrace); when(ldapUserDetails.getAttributes()).thenReturn(attributes); User userForTest = getUserForTest(); Boolean passExpired = sut.checkExpiredPassword(ldapUserDetails.getAttributes()); userForTest.setPasswordExpired(passExpired); assertThat(passExpired ,is(false)); }
@Test public void shouldCheckUserPasswordExpiredStatus(){ when(ldapUserDetails.getAttributes()).thenReturn(new BasicAttributes()); final Boolean nonExpiredPassword = sut.checkExpiredPassword(ldapUserDetails.getAttributes()); assertThat(nonExpiredPassword, is(false)); Attribute pwdGraceUseTime = new BasicAttribute("pwdGraceUseTime"); Attributes attributes = new BasicAttributes(); attributes.put(pwdGraceUseTime); when(ldapUserDetails.getAttributes()).thenReturn(attributes); final Boolean expiredPassword = sut.checkExpiredPassword(ldapUserDetails.getAttributes()); assertThat(expiredPassword, is(true)); }