private static final Logger log = LoggerFactory.getLogger(UIPageActionListener.class);
public static class ChangeNodeActionListener extends EventListener<UIPortalApplication> {
public void execute(Event<UIPortalApplication> event) throws Exception {
PortalRequestContext pcontext = PortalRequestContext.getCurrentInstance();
UserPortal userPortal = pcontext.getUserPortalConfig().getUserPortal();
UIPortalApplication uiPortalApp = event.getSource();
UIPortal showedUIPortal = uiPortalApp.getCurrentSite();
UserNodeFilterConfig.Builder builder = UserNodeFilterConfig.builder();
builder.withReadCheck();
PageNodeEvent<UIPortalApplication> pageNodeEvent = (PageNodeEvent<UIPortalApplication>) event;
String nodePath = pageNodeEvent.getTargetNodeUri();
UserNode targetNode = null;
SiteKey siteKey = pageNodeEvent.getSiteKey();
if (siteKey != null) {
if (pcontext.getRemoteUser() == null
&& (siteKey.getType().equals(SiteType.GROUP) || siteKey.getType().equals(SiteType.USER))) {
NavigationService service = uiPortalApp.getApplicationComponent(NavigationService.class);
NavigationContext navContext = service.loadNavigation(siteKey);
if (navContext != null) {
uiPortalApp.setLastRequestNavData(null);
pcontext.requestAuthenticationLogin();
return;
}
}
UserNavigation navigation = userPortal.getNavigation(siteKey);
if (navigation != null) {
targetNode = userPortal.resolvePath(navigation, builder.build(), nodePath);
if (targetNode == null) {
// If unauthenticated users have no permission on PORTAL node and URL is valid, they will be required to
// login
if (pcontext.getRemoteUser() == null && siteKey.getType().equals(SiteType.PORTAL)) {
targetNode = userPortal.resolvePath(navigation, null, nodePath);
if (targetNode != null) {
uiPortalApp.setLastRequestNavData(null);
pcontext.requestAuthenticationLogin();
return;
}
} else {
// If path to node is invalid, get the default node instead of.
targetNode = userPortal.getDefaultPath(navigation, builder.build());
}
}
}
if (targetNode != null) {
// let's check if this node can be shown at this time
long now = System.currentTimeMillis();
long startPublicationTime = targetNode.getStartPublicationTime();
long endPublicationTime = targetNode.getEndPublicationTime();
boolean restrictOutsidePublicationWindow = targetNode.isRestrictOutsidePublicationWindow();
if (shouldRestrictAccess(restrictOutsidePublicationWindow, now, startPublicationTime, endPublicationTime)) {
if (log.isInfoEnabled()) {
log.info("User "
+pcontext.getRemoteUser()
+" has tried to access a node ("
+targetNode.getURI()
+") which is outside of the publishing window and is restricted.");
}
targetNode = userPortal.getDefaultPath(navigation, builder.build());
}
}
}
if (targetNode == null) {
targetNode = userPortal.getDefaultPath(builder.build());
if (targetNode == null) {
if (showedUIPortal != null) {
UIPageBody uiPageBody = showedUIPortal.findFirstComponentOfType(UIPageBody.class);
uiPageBody.setUIComponent(null);
}