📄 jahiaadministration.java
字号:
sReg = ServicesRegistry.getInstance(); if (sReg != null) { uMgr = sReg.getJahiaUserManagerService(); gMgr = sReg.getJahiaGroupManagerService(); } // check form validity... if(uMgr != null) { theUser = uMgr.lookupUser( SUPERADMIN_SITE_ID, jahiaLoginUsername ); if ( theUser == null ){ JahiaConsole.println("JahiaAdministration", " user not found "); } theGroup = gMgr.getAdministratorGroup( SUPERADMIN_SITE_ID ); if(theUser != null) { if(theUser.verifyPassword( jahiaLoginPassword )) { if(theGroup.isMember( theUser )) { loginError = false; session.setAttribute( CLASS_NAME + "adminUsername", theUser.getUsername() ); JahiaConsole.println("JahiaAdministration", "Login granted: " + jahiaLoginUsername + " entered correct password."); } else { request.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "User " + jahiaLoginUsername + " is not an administrator."); JahiaException je = new JahiaException( "JahiaAdministration", "Login Error: User " + jahiaLoginUsername + " is not an administrator.", JahiaException.SECURITY_ERROR, JahiaException.WARNING); } } else { request.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "This login/password combination is not valid."); JahiaException je = new JahiaException( "JahiaAdministration", "Login Error: User " + jahiaLoginUsername + " entered bad password.", JahiaException.SECURITY_ERROR, JahiaException.WARNING); } } } if(!loginError) { // access granted... // i lookup user on the superadmin group. so... only a super admin can arrive on this set attribute :o) session.setAttribute(CLASS_NAME + "isSuperAdmin", Boolean.TRUE); session.setAttribute(CLASS_NAME + "manageSiteID", new Integer(0)); session.setAttribute(CLASS_NAME + "accessGranted", Boolean.TRUE); session.setAttribute(CLASS_NAME + "jahiaLoginUsername", jahiaLoginUsername); session.setAttribute(CLASS_NAME + "jahiaLoginPassword", jahiaLoginPassword); session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE); session.setAttribute(ParamBean.SESSION_USER, theUser ); displayMenu( request, response, session ); } else { // access failed... session.setAttribute(CLASS_NAME + "isSuperAdmin", Boolean.FALSE); session.setAttribute(CLASS_NAME + "accessGranted", Boolean.FALSE); session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE); request.setAttribute(CLASS_NAME + "jahiaLoginUsername", jahiaLoginUsername); displayLogin( request, response, session ); } } // end processLogin //------------------------------------------------------------------------- /** * Display the administration menu, using doRedirect(). * @author Alexandre Kraft * @author Khue Nguyen * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ public static void displayMenu( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { boolean profileCapability = false; Vector grantedSites = new Vector(); JahiaUser theUser = null; JahiaConsole.println("JahiaAdministration.displayMenu","started "); JahiaSite theSite = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); if(theSite == null) { JahiaConsole.println("JahiaAdministration.displayMenu","session site is null ! "); } else { // try to get site from cache try { theSite = sReg.getJahiaSitesService().getSiteByKey( theSite.getSiteKey() ); } catch (Exception e) { theSite = null; } } // get sites where the user has an admin access... try { theUser = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); if ( theUser != null ){ grantedSites = ServicesRegistry.getInstance() .getJahiaGroupManagerService() .getAdminGrantedSites( theUser ); } } catch (Exception e) { } if ( grantedSites == null ){ JahiaConsole.println("JahiaAdministration.displayMenu","can not admin any site at all !!! "); grantedSites = new Vector(); } if ( theSite == null && (grantedSites.size()>0) ){ theSite = (JahiaSite)grantedSites.get(0); } // check if the user is created on this site... if(theSite!=null) { if(theUser.getSiteID()==theSite.getID()) { profileCapability = true; } session.setAttribute( CLASS_NAME + "manageSiteID", new Integer( theSite.getID() ) ); session.setAttribute( ParamBean.SESSION_SITE, theSite ); } if( theSite != null ){ try { initAdminJahiaData(request,response,session); } catch ( JahiaException je ){ JahiaErrorDisplay.DisplayException (request, response, context, Jahia.getPrivateSettings(), je); return; } } request.setAttribute( "site", theSite ); request.setAttribute( "sitesList", grantedSites ); request.setAttribute( "siteID", (Integer) session.getAttribute( CLASS_NAME + "manageSiteID" )); request.setAttribute( "isSuperAdmin", (Boolean) session.getAttribute( CLASS_NAME + "isSuperAdmin" )); request.setAttribute( "configJahia", (Boolean) session.getAttribute( CLASS_NAME + "configJahia" )); request.setAttribute( "profileCapability", (Boolean) new Boolean(profileCapability) ); doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); } // end displayMenu //------------------------------------------------------------------------- /** * Change the site you want to administrate. After, display the menu again. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ public static void changeSite( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { String newSiteID = (String) request.getParameter("changesite").trim(); int siteID = Integer.parseInt( newSiteID ); // check if the user has really admin access to this site... JahiaUser theUser = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); JahiaGroup group = ServicesRegistry.getInstance().getJahiaGroupManagerService().getAdministratorGroup( siteID ); JahiaSite currentSite = null; if(group != null && !group.isMember( theUser )) { //System.out.println(" --> no admin access on this site <--"); currentSite = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); siteID = currentSite.getID(); } else { try { currentSite = ServicesRegistry.getInstance().getJahiaSitesService().getSite(siteID); session.setAttribute( ParamBean.SESSION_SITE , currentSite); } catch ( JahiaException je ) { request.setAttribute("jahiaDisplayMessage", "An error occured while processing your request"); } } // set the new site id to administrate... request.setAttribute( "site", currentSite ); session.setAttribute( CLASS_NAME + "manageSiteID", new Integer( siteID ) ); displayMenu( request, response, session ); } // end changeSite //------------------------------------------------------------------------- /** * Change the management mode, between sites and server. After, display the menu again. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ public static void switchModeAction( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { JahiaConsole.println("JahiaAdministration", "switchModeAction started"); String mode = (String) request.getParameter("mode").trim(); if(mode.equals("server")) { // check if the user has really superadmin access... JahiaUser theUser = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); JahiaGroup theGroup = gMgr.getAdministratorGroup( SUPERADMIN_SITE_ID ); if(theGroup != null && theGroup.isMember( theUser )) { session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE); } } else { session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE); } displayMenu( request, response, session ); } // end switchModeAction //------------------------------------------------------------------------- /** * Checks if a login session passed from Jahia is valid for silent login to JahiaAdministration * @author Mikha雔 Janson * @author Alexandre Kraft * * @param session the HttpSession object * @return <code>true</code> if the user can access to administration, <code>false</code> otherwise. */ private static boolean isValidLoginSession( HttpSession session ) { JahiaConsole.println("JahiaAdministration", "isValidatingLoginSession started"); boolean isValid = false; boolean isSuperAdmin = false; try { // get references to user manager and group manager... sReg = ServicesRegistry.getInstance(); if (sReg != null) { uMgr = sReg.getJahiaUserManagerService(); gMgr = sReg.getJahiaGroupManagerService(); } JahiaUser theUser = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); JahiaSite theSite = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); if ( theSite != null ){ JahiaGroup theGroup = gMgr.getAdministratorGroup( theSite.getID() ); if(theGroup.isMember( theUser ))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -