Note that there are some explanatory texts on larger screens.

plurals
  1. PONull being passed to Spring Security UserDetailsService
    primarykey
    data
    text
    <p>I am trying to add login to my webapp using spring security.</p> <p>This is the first time I am trying to add spring-security 3.2 using pure code config (I have used it several times before with the xml config and the standard <code>UserDetailsService</code> implementation).</p> <p>I have also seen other similar questions around moving to 3.2 but all relate to csrf stuff - which I have currently disabled just to rule those changes out.</p> <p>My config looks like this:</p> <pre><code>@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsServiceImpl userDetailsServiceImpl; @Override protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .antMatchers("/resources/**").permitAll() .antMatchers("/dashboard").permitAll() .antMatchers("/sign-up").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/") .loginProcessingUrl("/loginprocess") .failureUrl("/?loginFailure=true") .permitAll() .and() .logout() .logoutUrl("/logout") .permitAll(); } @Override protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth .userDetailsService(userDetailsServiceImpl) .passwordEncoder(bCryptPasswordEncoder()); } @Bean public BCryptPasswordEncoder bCryptPasswordEncoder(){ return new BCryptPasswordEncoder(); } </code></pre> <p>My login form looks like this:</p> <pre><code>&lt;form class="form-signin" action="loginprocess" method="POST"&gt; &lt;h3 class="form-signin-heading"&gt;Already Registered?&lt;/h3&gt; &lt;input type="text" class="form-control" name='j_username' placeholder="User name"&gt; &lt;input type="password" class="form-control" name='j_password' placeholder="Password"&gt;&lt;br/&gt; &lt;input class="btn btn-lg btn-primary" name="submit" type="submit" value='Sign in' &gt; &lt;a class="btn btn-lg btn-primary" href="#" &gt;Sign up&lt;/a&gt; &lt;/form&gt; </code></pre> <p>Finally, I try to log in and whilst debugging and working through the code, in my implementation of the UserDetailsService:</p> <pre><code>@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { username = username.toLowerCase(); </code></pre> <p>I see that the username string being passed in here is always null - being as this is all being invoked by the underlying spring mechanism I am struggling to see what is happening to the values in my submitted login form.</p> <p>I have looked earlier on and walked through the spring code including the <code>UsernamePasswordAuthenticationFilter</code> class and it seems that the obtainUsername(request) call is just getting null from the request.</p> <p>Can anyone advise what might be wrong or where a good place to start looking would be? where does the username/password get set in the request object by spring?</p> <hr> <p><strong>UPDATE</strong></p> <p>I have also tried changing just the action url of the form and posting to a normal MVC controller - debugging that, the posted data is present and correct in the parameterMap - so it seems like it is something in the security chain that is removing my posted data from the request?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload