@Test public void authenticateWithNamingException() { UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( "ben", "benspassword"); LdapAuthenticator mockAuthenticator = mock(LdapAuthenticator.class); CommunicationException expectedCause = new CommunicationException( new javax.naming.CommunicationException()); when(mockAuthenticator.authenticate(authRequest)).thenThrow(expectedCause); LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider( mockAuthenticator); try { ldapProvider.authenticate(authRequest); fail("Expected Exception"); } catch (InternalAuthenticationServiceException success) { assertThat(success.getCause()).isSameAs(expectedCause); } }
@Test public void contextEnvironmentPropertiesUsed() throws Exception { Hashtable<String, Object> env = new Hashtable<>(); env.put("java.naming.ldap.factory.socket", "unknown.package.NonExistingSocketFactory"); provider.setContextEnvironmentProperties(env); try { provider.authenticate(joe); fail("CommunicationException was expected with a root cause of ClassNotFoundException"); } catch (org.springframework.ldap.CommunicationException expected) { assertThat(expected.getRootCause()).isInstanceOf(ClassNotFoundException.class); } }
return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex);
return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex);
return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex);
return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex);