def testAuthenticationProcessingFilterWithBadPassword(self): def start_response(): pass def application(environ, start_response): return ["Success"] environ = {} environ["PATH_INFO"] = "/index.html" inMemoryUserDetailsService = InMemoryUserDetailsService() inMemoryUserDetailsService.user_dict = {"user1": ("good_password", ["role1", "blue"], True)} inMemoryDaoAuthenticationProvider = DaoAuthenticationProvider() inMemoryDaoAuthenticationProvider.user_details_service = inMemoryUserDetailsService inMemoryDaoAuthenticationManager = AuthenticationManager([inMemoryDaoAuthenticationProvider]) authenticationFilter = AuthenticationProcessingFilter() authenticationFilter.auth_manager = inMemoryDaoAuthenticationManager authenticationFilter.alwaysReauthenticate = False token = UsernamePasswordAuthenticationToken("user1", "bad_password", None) self.assertFalse(token.isAuthenticated()) SecurityContextHolder.setContext(SecurityContext()) SecurityContextHolder.getContext().authentication = token filterChainProxy = FilterChainProxy() filterChainProxy.filterInvocationDefinitionSource = [("/.*", [authenticationFilter])] filterChainProxy.application = application self.assertRaises(BadCredentialsException, filterChainProxy, environ, start_response) self.assertFalse(SecurityContextHolder.getContext().authentication.isAuthenticated())
def shaAuthenticationProvider(self): """This authentication provider takes a user details service and links it with a password encoder, to hash passwords before comparing with the user details service.""" provider = DaoAuthenticationProvider() provider.user_details_service = self.shaUserDetailsService() provider.password_encoder = self.shaEncoder() return provider
def shaAuthenticationProvider(self): """This authentication provider takes a user details service and links it with a password encoder, to hash passwords before comparing with the user details service.""" provider = DaoAuthenticationProvider() provider.user_details_service = self.shaUserDetailsService() provider.password_encoder = self.shaEncoder() return provider
def testAuthenticationProcessingFilterWithGoodPassword(self): def start_response(): pass def application(environ, start_response): return ["Success"] environ = {} environ["PATH_INFO"] = "/index.html" inMemoryUserDetailsService = InMemoryUserDetailsService() inMemoryUserDetailsService.user_dict = { "user1": ("good_password", ["role1", "blue"], True) } inMemoryDaoAuthenticationProvider = DaoAuthenticationProvider() inMemoryDaoAuthenticationProvider.user_details_service = inMemoryUserDetailsService inMemoryDaoAuthenticationManager = AuthenticationManager( [inMemoryDaoAuthenticationProvider]) authenticationFilter = AuthenticationProcessingFilter() authenticationFilter.auth_manager = inMemoryDaoAuthenticationManager authenticationFilter.alwaysReauthenticate = False token = UsernamePasswordAuthenticationToken("user1", "good_password", None) self.assertFalse(token.isAuthenticated()) SecurityContextHolder.setContext(SecurityContext()) SecurityContextHolder.getContext().authentication = token filterChainProxy = FilterChainProxy() filterChainProxy.filterInvocationDefinitionSource = [ ("/.*", [authenticationFilter]) ] filterChainProxy.application = application self.assertEquals(["Success"], filterChainProxy(environ, start_response)) self.assertTrue(SecurityContextHolder.getContext().authentication. isAuthenticated()) self.assertEquals(["Success"], filterChainProxy(environ, start_response)) self.assertTrue(SecurityContextHolder.getContext().authentication. isAuthenticated())
def shaAuthenticationProvider(self): provider = DaoAuthenticationProvider() provider.user_details_service = self.shaUserDetailsService() provider.password_encoder = self.shaEncoder() return provider
def shaAuthenticationProvider(self): provider = DaoAuthenticationProvider() provider.user_details_service = self.shaUserDetailsService() provider.password_encoder = self.shaEncoder() return provider