4

I have an app, that should prefill login form with variables grabbed from URL. My security config:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
    .antMatchers("/", "/home").access("hasRole('USER') or hasRole('ADMIN') or hasRole('MANAGER')")
    .antMatchers("/admin/**").access("hasRole('ADMIN') or hasRole('MANAGER')")
    .and().formLogin().loginPage("/login")
    .loginProcessingUrl("/login").usernameParameter("username").passwordParameter("password")
    .and().rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository)
    .tokenValiditySeconds(90*24*60*60).and().csrf().and().exceptionHandling().accessDeniedPage("/Access_Denied");
}

And when I tried to access app with url: "app.com/home" I'm getting app.com/login and of course form is empty So, I need to be able to get user from his identifier passed with such URL: app.com/home?user=test1 and pass this user to my custom login form:

But at the moment I can't get it - how can I get this path variable in code, and where can I get it.

4
  • You can map /login to a controller method handler which should returns your login page then process in that handler to add what you want in the model then retrieve data in your page. Commented Oct 27, 2017 at 12:11
  • Yeah, now all implemented exactly in such way, but user should get on app.com/login page after filter redirecting from app.com?username=test. So the question is how and where to grab this username and save it into the session. Commented Oct 27, 2017 at 13:26
  • May be this could help you : stackoverflow.com/questions/18496125/… Commented Oct 27, 2017 at 15:02
  • Actually I've already implement it with my custom OncePerRequestFilter where I firstly scan path (getting it from request), and if there presented parameters that I'm interested in - I'm getting them and add to Session. And in "/login" mapped method set them to model. So - thanks you - you advice was very helpful ! Commented Oct 28, 2017 at 8:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.