Skip to content

Commit 07287d3

Browse files
author
Daniel Colgrove
committed
Made SuccessHandling aware of the loginUri (uri configurable) and will strip the loginUri to prevent a redirect back to the login page.
This fixes BroadleafCommerce#1271 This is related to BroadleafCommerce/QA#335
1 parent 94218b8 commit 07287d3

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

admin/broadleaf-open-admin-platform/src/main/java/org/broadleafcommerce/openadmin/security/BroadleafAdminAuthenticationSuccessHandler.java

+35-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class BroadleafAdminAuthenticationSuccessHandler extends SimpleUrlAuthent
4343

4444
private RequestCache requestCache = new HttpSessionRequestCache();
4545

46+
private String loginUri = "/login"; //default login uri but can be overridden in admin security config
47+
4648
private static final String successUrlParameter = "successUrl=";
4749

4850
@Resource(name = "blAdminSecurityRemoteService")
@@ -89,8 +91,39 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
8991
targetUrl = targetUrl.substring(successUrlPosistion, nextParamPosistion);
9092
}
9193
}
92-
93-
logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
94+
95+
// Remove the login URI so we don't continuously redirect to the login page
96+
targetUrl = removeLoginSegment(targetUrl);
97+
98+
if (logger.isDebugEnabled()) {
99+
logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
100+
}
94101
getRedirectStrategy().sendRedirect(request, response, targetUrl);
95102
}
103+
104+
/**
105+
* Given the instance attribute loginUri, removes the loginUri from the passed url when present
106+
* @param uri
107+
* @return String
108+
*/
109+
private String removeLoginSegment(String url) {
110+
if ((url == null) || url.equals("")) {
111+
return "/";
112+
}
113+
int lastSlashPos = url.lastIndexOf(loginUri);
114+
if (lastSlashPos >= 0) {
115+
return url.substring(0, lastSlashPos);
116+
}
117+
else {
118+
return url;
119+
}
120+
}
121+
122+
public String getLoginUri() {
123+
return loginUri;
124+
}
125+
126+
public void setLoginUri(String loginUri) {
127+
this.loginUri = loginUri;
128+
}
96129
}

0 commit comments

Comments
 (0)