Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC strange behavior
    primarykey
    data
    text
    <p>I have a method that handles request with a URI of "/home". This request is generated upon successful log-in procedure. Here is a little code to support my situation:</p> <pre><code>&lt;security:form-login login-processing-url="/static/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t" default-target-url="/home"/&gt; </code></pre> <p>The method body demonstrates what I am attempting to achieve:</p> <pre><code>String userMail = SecurityContextHolder.getContext(). getAuthentication().getName(); logger.info(userMail); Person p = userService.retrieveUserByEmail(userMail); session.setAttribute("person", p); return "user/home"; </code></pre> <p>This bit is important as the person p is used as data source for other requests.</p> <p>Now the problem. I don't know if it is the property of Google Chrome, but for some reason the browser remembers the request you've done before log-in and instead of going through /home request after successful log-in procedure, it generates the previous request bypassing this /home gate, resulting in null pointer exception as person p was never set up, as session wasn't populated by /home request.</p> <p>I know that for other requests I should do validation, but I don't like the idea of letting user generate any request without prior going through /home .</p> <p>Done with text description and now to explain how I get unwanted behaviour in steps:</p> <ol> <li><p>ask for request that you know exist such as: myApp/nameOfSomething/viewThisSomething - you are brought to log-in page as expected(you must be authenticated for request to be accepted)</p></li> <li><p>you enter correct credentials and instead of going to default-target-url="/home" you are automatically making previous request myApp/nameOfSomething/viewThisSomething without populating session with necessary data and resulting in nullpointer exception.</p></li> </ol> <p>What else is interesting is that logger shows the mail, so it might be that they are both executed at the same time but /home request is slower - can that happen?</p> <p>I resolve the situation in other method by checking if null and forcing to go back to /home which works as expected, but I am control freak and don't like when user is doing what he is not intended to do.</p> <p>Thank You for Your time,</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