Skip to content

Commit

Permalink
fix: Fix Redirecting to Page Not Found when page not accessible - Mee…
Browse files Browse the repository at this point in the history
…ds-io/MIPs#165

Prior to this change, when requesting a page by a user having access to its site, a blank page is displayed instead of redirecting to 'Page Not Found'. This change will ensure to redirect to 'Page Not Found' when the page isn't accessible for the currently authenticated user, else if not authenticated, redirect to login page.
  • Loading branch information
boubaker committed Nov 4, 2024
1 parent 07e4459 commit cccb3fb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.exoplatform.portal.application;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -159,41 +160,34 @@ protected boolean processRequest(ControllerContext controllerContext, // NOSONAR
requestSiteName,
requestPath,
requestLocale);
String metaPortal = portalConfigService.getMetaPortal();
try {
PortalConfig persistentPortalConfig = context.getDynamicPortalConfig();
if (context.getUserPortalConfig() == null) {
if (persistentPortalConfig == null
|| StringUtils.equals(persistentPortalConfig.getName(), portalConfigService.getGlobalPortal())) {
return false;
} else if (request.getRemoteUser() == null) {
} else if (context.getRemoteUser() == null) {
context.requestAuthenticationLogin();
return true;
} else {
String metaPageNotFound = "/portal/" + portalConfigService.getMetaPortal() + "/page-not-found";
if (!StringUtils.equals(request.getRequestURI(), metaPageNotFound)) {
if (StringUtils.equals(request.getRequestURI(), PORTAL_PUBLIC_PAGE_NOT_FOUND)) {
// In case page-not-found can't be displayed in 'public' or 'meta'
// sites
// If logged in => redirect to /
// If Anonymous => redirect to Login page
if (StringUtils.isNotBlank(request.getRemoteUser())) {
context.sendRedirect("/");
} else {
context.requestAuthenticationLogin();
}
} else {
context.sendRedirect(metaPageNotFound);
}
} else {
context.sendRedirect(PORTAL_PUBLIC_PAGE_NOT_FOUND);
}
sendToNotFoundPage(context, metaPortal);
return true;
}
} else if (persistentPortalConfig != null
&& StringUtils.equals(persistentPortalConfig.getName(), portalConfigService.getGlobalPortal())) {
return false;
} else {
processRequest(context, app);
if (context.getUiPage() == null) {
if (context.getRemoteUser() == null) {
context.requestAuthenticationLogin();
} else {
sendToNotFoundPage(context, metaPortal);
}
}
return true;
}
return true;
} finally {
context.onRequestEnd();
}
Expand Down Expand Up @@ -346,6 +340,27 @@ protected Locale getRequestLocale(ControllerContext controllerContext) {
}
}

private void sendToNotFoundPage(PortalRequestContext context, String metaPortal) throws IOException, Exception {
String metaPageNotFound = "/portal/" + metaPortal + "/page-not-found";
if (!StringUtils.equals(context.getRequest().getRequestURI(), metaPageNotFound)) {
if (StringUtils.equals(context.getRequest().getRequestURI(), PORTAL_PUBLIC_PAGE_NOT_FOUND)) {
// In case page-not-found can't be displayed in 'public' or 'meta'
// sites
// If logged in => redirect to /
// If Anonymous => redirect to Login page
if (StringUtils.isNotBlank(context.getRemoteUser())) {
context.sendRedirect("/");
} else {
context.requestAuthenticationLogin();
}
} else {
context.sendRedirect(metaPageNotFound);
}
} else {
context.sendRedirect(PORTAL_PUBLIC_PAGE_NOT_FOUND);
}
}

private void createPortalRequestInstance(PortalRequestContext context) {
try {
PortalRequestImpl.createInstance(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,9 @@ private List<UIPortlet> getCurrentPortlets() {
uiWorkingWorkspace.findComponentOfType(uiPortlets, UIPortlet.class);
} else {
UIPage currentPage = getCurrentPage();
if (!requestContext.isMaximizePortlet() && !currentPage.isShowMaxWindow()) {
if (currentPage == null) {
return Collections.emptyList();
} else if (!requestContext.isMaximizePortlet() && !currentPage.isShowMaxWindow()) {
getCurrentSite().findComponentOfType(uiPortlets, UIPortlet.class);
} else {
currentPage.findComponentOfType(uiPortlets, UIPortlet.class);
Expand Down

0 comments on commit cccb3fb

Please sign in to comment.