Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUI-170 - Not redirecting to requested page after redirected to login… #130

Merged
merged 2 commits into from
Dec 9, 2020

Conversation

mseaton
Copy link
Member

@mseaton mseaton commented Dec 8, 2020

… page

This adds a new request filter that sets the redirect url on the session to the currently requested url if the user is not authenticated and it is not already set.

… page

This adds a new request filter that sets the redirect url on the session to the currently requested url if the user is not authenticated and it is not already set.
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me and fixes some rather annoying behaviour.

Comment on lines 52 to 54
if (log.isDebugEnabled()) {
log.debug("Set " + OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR + " = " + redirectUrl);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (log.isDebugEnabled()) {
log.debug("Set " + OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR + " = " + redirectUrl);
}
log.debug("Set {} = {}", OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR, redirectUrl);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

}
}
catch (Exception e) {
// Ignore errors here to prevent any failures from disrupting service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe log exceptions, at least initially?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't hurt

String requestURI = httpReq.getRequestURI();
if (!Context.isAuthenticated()) {
if ("GET".equalsIgnoreCase(httpReq.getMethod()) && !requestURI.contains("login.")) {
if (req.getAttribute(OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR) == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check actually work? I can see we use it elsewhere, but it seems like this should be something like:

req.getSession(false).getAttribute(OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR) == null

When I try naïvely to call:

req.getSession().setAttribute("MyAttribute", "SomeValue");

And then do:

req.getAttribute("MyAttribute")

The response is still null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry, yeah, good catch. I was initially setting a request attribute and then changed it when I recognized it was supposed to be a session attribute, but didn't change this.

… page

Follow-up tweaks following code review.
Copy link
Member Author

@mseaton mseaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ibacher - great suggestions. Those are pushed above.

String requestURI = httpReq.getRequestURI();
if (!Context.isAuthenticated()) {
if ("GET".equalsIgnoreCase(httpReq.getMethod()) && !requestURI.contains("login.")) {
if (req.getAttribute(OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR) == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry, yeah, good catch. I was initially setting a request attribute and then changed it when I recognized it was supposed to be a session attribute, but didn't change this.

Comment on lines 52 to 54
if (log.isDebugEnabled()) {
log.debug("Set " + OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR + " = " + redirectUrl);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

}
}
catch (Exception e) {
// Ignore errors here to prevent any failures from disrupting service
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't hurt

@dkayiwa dkayiwa merged commit d09aedb into master Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants