📄 jahiaadministration.java
字号:
{ // check if the user is a super admin or not... JahiaGroup superAdminGroup = gMgr.getAdministratorGroup( SUPERADMIN_SITE_ID ); if(superAdminGroup.isMember( theUser )) { isSuperAdmin = true; } session.setAttribute( CLASS_NAME + "isSuperAdmin", new Boolean(isSuperAdmin) ); session.setAttribute( CLASS_NAME + "manageSiteID", new Integer(theSite.getID()) ); session.setAttribute( CLASS_NAME + "accessGranted", Boolean.TRUE); session.setAttribute( CLASS_NAME + "adminUsername", theUser.getUsername() ); session.setAttribute( CLASS_NAME + "jahiaLoginUsername", theUser.getUsername() ); JahiaConsole.println("JahiaAdministration", "Silent login granted: user " + theUser.getUsername() + " has valid login session."); isValid = true; } else { JahiaConsole.println("JahiaAdministration", "Couldn't validate login session for: " + theUser.getUsername()); } } else if ( theUser.hashCode()==0 ){ session.setAttribute( CLASS_NAME + "isSuperAdmin", new Boolean(true) ); session.setAttribute( CLASS_NAME + "manageSiteID", new Integer(0) ); session.setAttribute( CLASS_NAME + "accessGranted", Boolean.TRUE); session.setAttribute( CLASS_NAME + "adminUsername", theUser.getUsername() ); session.setAttribute( CLASS_NAME + "jahiaLoginUsername", theUser.getUsername() ); } } catch(Exception e) { } return isValid; } // end isValidLoginSession //------------------------------------------------------------------------- /** * Handles engine calls within JahiaAdministration Servlet * * @param HttpServletRequest request * @param HttpServletResponse response * @return boolean true if the request is effectively a engine call. * @author Khue NGuyen */ protected boolean handleEngines(HttpServletRequest request, HttpServletResponse response) throws JahiaException { String pathInfo = request.getPathInfo(); if ( pathInfo == null ) return false; if ( pathInfo.indexOf("engineName") == -1 ) return false; // start the chrono... long startTime = JahiaChrono.getInstance().start(); // get the main http method... String requestMethod = request.getMethod(); int intRequestMethod = 0; if (requestMethod.equals(GET_REQUEST)) { intRequestMethod = ParamBean.GET_METHOD; } else if(requestMethod.equals (POST_REQUEST)) { intRequestMethod = ParamBean.POST_METHOD; } JahiaConsole.println(CLASS_NAME+"handleEngines()","------------------------------------------------------- NEW "+requestMethod+" REQUEST ---"); // create the parambean (jParams)... ParamBean jParams = null; try { jParams = new ParamBean( request, response, context, jSettings, startTime, intRequestMethod); if (jParams == null) { throw new JahiaException(CLASS_NAME+".handleEngine", "ParamBean is null", JahiaException.ERROR, JahiaException.CRITICAL ); } OperationManager operations = new OperationManager(); operations.handleOperations (jParams, jSettings); // display time if (jParams.getUser()!=null) { JahiaConsole.finalPrintln(CLASS_NAME, "Served " + jParams.getEngine() + " engine for user " +jParams.getUser().getUsername()+ " from ["+ jParams.getRequest().getRemoteAddr() + "] in ["+JahiaChrono.getInstance().read( jParams.getStartTime() )+"ms]"); } jParams = null; // PAGE NOT FOUND EXCEPTION } catch (JahiaPageNotFoundException ex) { JahiaConsole.finalPrintln (CLASS_NAME, ex.getJahiaErrorMsg()); JahiaErrorDisplay.DisplayException (request, response, getServletContext(), jSettings, ex); } // SECURITY EXCEPTION catch (JahiaSecurityException ex) { JahiaConsole.finalPrintln (CLASS_NAME, "A Security error occured -> request ignored."); JahiaErrorDisplay.DisplayException (request, response, getServletContext(), jSettings, ex); } // SESSION EXPIRATION catch (JahiaSessionExpirationException ex) { JahiaConsole.finalPrintln (CLASS_NAME, "Null session -> session expiration -> request ignored."); JahiaErrorDisplay.DisplayException (request, response, getServletContext(), jSettings, ex); } // OPERATION NOT ALLOWED catch (JahiaOperationNotAllowedException ex) { JahiaConsole.finalPrintln (CLASS_NAME, ex.getJahiaErrorMsg()); JahiaErrorDisplay.DisplayException (request, response, getServletContext(), jSettings, ex); } // SERVICE EXCEPTIONS catch (ServiceNotFoundException ex) { JahiaConsole.finalPrintln (CLASS_NAME, ex.getJahiaErrorMsg()); JahiaErrorDisplay.DisplayException (request, response, getServletContext(), jSettings, ex); } // ALL OTHER JAHIA EXCEPTIONS catch (JahiaException je) { JahiaConsole.println(CLASS_NAME, "Error in " + requestMethod + " method -> BAILING OUT" ); // should redirect to an error page here JahiaErrorDisplay.DisplayException(request, response, getServletContext(), jSettings, je); } return true; } //------------------------------------------------------------------------- /** * Returns a relative qualified request URL , i.e /JahiaAdministration. * * @param HttpServletRequest request * @author Khue NGuyen */ private String getServletURI(HttpServletRequest request, HttpServletResponse response){ if ( request == null ) return ""; String pathInfo = request.getPathInfo(); String tempServletURI = ""; if ( pathInfo == null ){ tempServletURI = response.encodeURL ( request.getRequestURI() ); } else { tempServletURI = response.encodeURL( request.getRequestURI().substring(0,request.getRequestURI().indexOf(pathInfo)) ); } return tempServletURI; } //------------------------------------------------------------------------- /** * Init a milimalistic JahiaData that is necessary to work with taglibs and * engines within JahiaAdministration servlet. * The JahiaData only contains the current site and the user, * that is the current identified admin. The page is null and * fields set and containers set are not build. * The JahiaData is then stored in the request as the attribute : * "org.jahia.data.JahiaData" * "org.jahia.data.JahiaData" * * @param HttpServletRequest request * @param HttpServletResponse response * @param HttpSession session * * @author Khue NGuyen */ static private void initAdminJahiaData( HttpServletRequest request, HttpServletResponse response, HttpSession session) throws JahiaException, IOException, ServletException { JahiaConsole.println( CLASS_NAME+".initAdminJahiaData", "started"); JahiaUser user = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); JahiaSite site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); if ( site == null ){ // This can occurs when all sites has been deleted ... // create a fake site for JSP using taglibs JahiaSite fakeSite = new JahiaSite( -1, "", "", "", false, -1, "", null, new Properties() ); site = fakeSite; } JahiaPage page = null; Integer I = (Integer) session.getAttribute( ParamBean.SESSION_LAST_REQUESTED_PAGE_ID ); if ( I != null ){ try { page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(I.intValue(),null); if ( page.getJahiaID() != site.getID() ) page = site.getHomePage(); // site has changed , we cannot use the old page } catch ( Throwable t) { //t.printStackTrace(); } } else { page = site.getHomePage(); } // start the chrono... long startTime = JahiaChrono.getInstance().start(); // get the main http method... String requestMethod = request.getMethod(); int intRequestMethod = 0; if (requestMethod.equals(GET_REQUEST)) { intRequestMethod = ParamBean.GET_METHOD; } else if(requestMethod.equals (POST_REQUEST)) { intRequestMethod = ParamBean.POST_METHOD; } AdminParamBean jParams = new AdminParamBean ( request, response, context, jSettings, startTime, intRequestMethod, site, user, null ); if ( page != null ){ try { page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(page.getID(),jParams); } catch ( Throwable t) { t.printStackTrace(); } } JahiaData jData = new JahiaData((ParamBean)jParams,false); jData.params().changePage(page); if ( jData == null ) JahiaConsole.println( CLASS_NAME+".initAdminJahiaData", "jahiaData is null !!"); request.setAttribute("org.jahia.data.JahiaData",jData); }} // end JahiaAdministration
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -