📄 authenticateddispatchaction.java
字号:
/*
* Make sure the current navigation context is correct.
* If not, then check the user can switch to the correct
* and switch it.
*/
CoreUtil.checkNavigationContext(this, mapping, form, request, response);
PropertyProfile profile = null;
if (request.getSession().getAttribute(Constants.SESSION_LOCKED) == null) {
profile = (PropertyProfile) request.getSession().getAttribute(Constants.SELECTED_PROFILE);
if (profile == null) {
request.getSession().setAttribute(Constants.ORIGINAL_REQUEST, Util.getOriginalRequest(request));
return mapping.findForward("selectPropertyProfile");
}
sessionInfo = CoreServlet.getServlet().getLogonController().getSessionInfo(request);
doCheckPermissions(mapping, currentUser);
return super.execute(mapping, form, request, response);
}
}
}
} catch (ActionDeniedException npgpe) {
if (log.isDebugEnabled())
log.debug("User " + npgpe.getPrincipal().getPrincipalName()
+ " attempted to access page they do have have permission for. Resource type = "
+ npgpe.getResourceType()
+ ". Now attempting to find the first valid item in the current menu tree to display.", npgpe);
MenuTree menuTree = NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE);
ActionForward fwd = menuTree.getFirstAvailableActionForward(menuTree.rebuildMenus(request));
if (fwd == null) {
SessionInfo info = this.getSessionInfo();
if (info.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
info.setNavigationContext(SessionInfo.USER_CONSOLE_CONTEXT);
CoreUtil.resetMainNavigation(request.getSession());
menuTree = NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE);
fwd = menuTree.getFirstAvailableActionForward(menuTree.rebuildMenus(request));
if (fwd != null) {
if (log.isDebugEnabled())
log.debug("Redirecting / Forwarding to " + fwd);
return fwd;
}
} else if (info.getNavigationContext() == SessionInfo.USER_CONSOLE_CONTEXT) {
info.setNavigationContext(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT);
CoreUtil.resetMainNavigation(request.getSession());
menuTree = NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE);
fwd = menuTree.getFirstAvailableActionForward(menuTree.rebuildMenus(request));
if (fwd != null) {
if (log.isDebugEnabled())
log.debug("Redirecting / Forwarding to " + fwd);
return fwd;
}
}
throw new Exception("Use does not have any permission for using any navigation context.");
}
if (log.isDebugEnabled())
log.debug("Redirecting / Forwarding to " + fwd);
return fwd;
} catch (InvalidTicketException ex) {
// Not logged in or expired
} catch (ServletException ex) {
throw ex;
}
// catch (Exception ex) {
// log.error("An internal error has occured.", ex);
// throw new ServletException(ex);
// }
return gotoLogon(mapping, form, request, response);
} catch (Throwable t) {
log.error("Failed to process authenticated request.", t);
throw t instanceof Exception ? (Exception) t : new Exception(t);
}
}
protected void doCheckPermissions(ActionMapping mapping, User currentUser) throws Exception {
// Check the user has the permissions to access this
// page
boolean ok = true;
if (resourceType != null && permissions != null) {
ok = CoreServlet.getServlet().getPolicyDatabase().isResourcePermissionAllowed(resourceType,
permissions, currentUser, false);
}
if (!ok && requiresResourcesOfType != null) {
ok = CoreServlet.getServlet().getPolicyDatabase().isPrincipalGrantedResourcesOfType(currentUser,
requiresResourcesOfType, null);
}
if (!ok) {
throw new ActionDeniedException(mapping, "You do not have permission to perform this action.",
currentUser, resourceType);
}
}
/**
* Logon is required. By default this will direct to the logon page.
* Subclasses may overide this method to go somewhere different.
*
* @param mapping mapping
* @param form form
* @param request request
* @param response response
* @return forward
* @throws Exception
*/
protected ActionForward gotoLogon(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
request.getSession().setAttribute(Constants.ORIGINAL_REQUEST, Util.getOriginalRequest(request));
return mapping.findForward("logon");
}
/**
* Get the {@link SessionInfo} for this session. This will only be
* available after {@link #execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)}
* has been called.
* <p>
* There are many places where the session info object is required. The
* usual way is to use {@link LogonController#getSessionInfo(HttpServletRequest)}.
* Whereever possible that method should be replaced with a call to this method.
*
* @return session info for request
*/
public SessionInfo getSessionInfo() {
return sessionInfo;
}
public ResourceType getResourceType() {
return resourceType;
}
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
return cleanUpAndReturnToReferer(mapping, form, request, response);
}
public ActionForward cleanUpAndReturnToReferer(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
HttpSession session = request.getSession();
String toRemove = null;
for (Enumeration e = session.getAttributeNames(); toRemove == null && e.hasMoreElements();) {
String n = (String) e.nextElement();
if (session.getAttribute(n) == form) {
toRemove = n;
}
}
if (toRemove != null) {
request.getSession().removeAttribute(toRemove);
}
request.getSession().removeAttribute(Constants.EDITING_ITEM);
if(((CoreForm) form).getReferer() == null) {
log.warn("Original referer was null, forwarding to home");
return mapping.findForward("home");
}
else {
ActionForward fwd = new ActionForward(((CoreForm) form).getReferer(), true);
return fwd;
}
}
void sendAuthorizationError(HttpServletResponse response) throws IOException {
response.setHeader("WWW-Authenticate", "Basic realm=\"SSL-Explorer\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -