Error crashes when you try to log in
@Configuration @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired @Qualifier("customUserDetailsService") UserDetailsService userDetailsService; @Autowired PersistentTokenRepository tokenRepository; @Autowired public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService); auth.authenticationProvider(authenticationProvider()); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/admin*/**") .access("hasRole('ADMIN')") .and().formLogin().loginPage("/admin/login") .loginProcessingUrl("/admin/login").usernameParameter("ssoId").passwordParameter("password").and() .rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository) .tokenValiditySeconds(604800).and().csrf().and().exceptionHandling().accessDeniedPage("/Access_Denied"); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/admin/login", "/admin/logout"); } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public DaoAuthenticationProvider authenticationProvider() { DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); authenticationProvider.setUserDetailsService(userDetailsService); authenticationProvider.setPasswordEncoder(passwordEncoder()); return authenticationProvider; } @Bean public PersistentTokenBasedRememberMeServices getPersistentTokenBasedRememberMeServices() { PersistentTokenBasedRememberMeServices tokenBasedservice = new PersistentTokenBasedRememberMeServices( "remember-me", userDetailsService, tokenRepository); return tokenBasedservice; } @Bean public AuthenticationTrustResolver getAuthenticationTrustResolver() { return new AuthenticationTrustResolverImpl(); } } and here is my form:
<form action="/admin/login" method="post" class="form-horizontal"> <c:if test="${param.error != null}"> <div class="alert alert-danger"> <p>Invalid username and password.</p> </div> </c:if> <c:if test="${param.logout != null}"> <div class="alert alert-success"> <p>You have been logged out successfully.</p> </div> </c:if> <div class="input-group input-sm"> <label class="input-group-addon" for="username"><i class="fa fa-user"></i></label> <input type="text" class="form-control" id="username" name="ssoId" placeholder="Enter Username" required> </div> <div class="input-group input-sm"> <label class="input-group-addon" for="password"><i class="fa fa-lock"></i></label> <input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required> </div> <div class="input-group input-sm"> <div class="checkbox"> <label><input type="checkbox" id="rememberme" name="remember-me"> Remember Me</label> </div> </div> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> <div class="form-actions"> <input type="submit" class="btn btn-block btn-primary btn-default" value="Log in"> </div> </form> in the controller:
@RequestMapping(value = "/admin/login", method = {RequestMethod.GET}) public ModelAndView loginPage() { return new ModelAndView("security/login"); } if in controller add
@RequestMapping(value = "/admin/login", method = {RequestMethod.POST}) public ModelAndView loginPagePost() { return new ModelAndView("security/login"); } then there is no error, but there is no login either
if you comment out the configure method (WebSecurity web) and remove the rights for the admin, then everything works out. that's why it seems to me that the problem is in the configure method (WebSecurity web)