NGrinderAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { @SuppressWarnings("deprecation") @Override protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) { Authentication authentication2 = SecurityContextHolder.getContext().getAuthentication(); if (authentication2 != null) { return; } String message = messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"); if (authentication.getCredentials() == null) { LOG.debug("Authentication failed: no credentials provided"); throw new BadCredentialsException(message); } String presentedPassword = authentication.getCredentials().toString(); SecuredUser user = ((SecuredUser) userDetails); boolean authorized = false; for (OnLoginRunnable each : getPluginManager().getEnabledModulesByClass(OnLoginRunnable.class, asList(defaultLdapLoginPlugin, defaultLoginPlugin))) { if (each.getClass().getName().equals(user.getAuthProviderClass())) { authorized = each.validateUser(user.getUsername(), presentedPassword, user.getPassword(), passwordEncoder, user.getUsername()); break; } } if (!authorized) { LOG.info("{} is not logined by {}", user.getUsername(), user.getAuthProviderClass()); throw new BadCredentialsException(message); } LOG.info("{} is logined by {}", user.getUsername(), user.getAuthProviderClass()); if (user.getUser().getId() == null) { addNewUserIntoLocal(user); LOG.info("{} is saved by password {}", user.getUser().getUserId(), user.getUser().getPassword()); } else { userService.saveWithoutPasswordEncoding(user.getUser()); } } NGrinderAuthenticationProvider(PluginManager pluginManager, DefaultLoginPlugin defaultLoginPlugin, DefaultLdapLoginPlugin defaultLdapLoginPlugin,
										  @Lazy ShaPasswordEncoder passwordEncoder, UserDetailsService userDetailsService, UserService userService); @Transactional void addNewUserIntoLocal(SecuredUser securedUser);  }
@Test public void testAdditionalAuthenticationChecks() { UserDetails user = userDetailService.loadUserByUsername(getTestUser().getUserId()); Authentication oriAuth = SecurityContextHolder.getContext().getAuthentication(); SecurityContextImpl context = new SecurityContextImpl(); SecurityContextHolder.setContext(context); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", null); try { provider.additionalAuthenticationChecks(user, token); fail(); } catch (BadCredentialsException ignored) { } token = new UsernamePasswordAuthenticationToken("TEST_USER", "123"); provider.additionalAuthenticationChecks(user, token); context.setAuthentication(oriAuth); }