1 21 package org.jahia.admin.access; 22 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Enumeration ; 26 import java.util.List ; 27 import java.util.Vector ; 28 29 import javax.servlet.ServletException ; 30 import javax.servlet.ServletOutputStream ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import javax.servlet.http.HttpSession ; 34 35 import org.jahia.bin.Jahia; 36 import org.jahia.bin.JahiaAdministration; 37 import org.jahia.data.JahiaData; 38 import org.jahia.exceptions.JahiaException; 39 import org.jahia.params.ParamBean; 40 import org.jahia.registries.ServicesRegistry; 41 import org.jahia.resourcebundle.JahiaResourceBundle; 42 import org.jahia.services.pages.ContentPage; 43 import org.jahia.services.pages.JahiaPage; 44 import org.jahia.services.sites.JahiaSite; 45 import org.jahia.services.sites.JahiaSitesService; 46 import org.jahia.services.usermanager.JahiaGroupManagerService; 47 import org.jahia.services.usermanager.JahiaUser; 48 import org.jahia.services.usermanager.JahiaUserManagerService; 49 import org.jahia.utils.JahiaTools; 50 import org.jahia.security.license.License; 51 52 61 public class ViewAccess 62 { 63 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 64 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 65 66 private static final Integer ITEMS_PER_PAGE = new Integer (10); 67 68 private List missingFields = new ArrayList (); 69 private List validationErrors = new ArrayList (); 70 71 private static JahiaUserManagerService uMgr; 72 private static JahiaGroupManagerService gMgr; 73 74 private JahiaSite site; 75 private JahiaUser user; 76 77 private License coreLicense; 78 79 80 81 89 public ViewAccess( HttpServletRequest request, 90 HttpServletResponse response, 91 HttpSession session ) 92 throws Throwable 93 { 94 ServicesRegistry sReg = ServicesRegistry.getInstance(); 96 if (sReg != null) { 97 uMgr = sReg.getJahiaUserManagerService(); 98 gMgr = sReg.getJahiaGroupManagerService(); 99 } 100 101 site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 103 user = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); 104 105 if(site==null) { 106 JahiaSitesService sitesService = sReg.getJahiaSitesService(); 107 site = sitesService.getSite( 0 ); 108 session.setAttribute( ParamBean.SESSION_SITE, site ); 109 } 110 111 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 112 ParamBean jParams = null; 113 if (jData != null) { 114 jParams = jData.params(); 115 } 116 coreLicense = Jahia.getCoreLicense(); 117 if ( coreLicense == null ){ 118 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.invalidLicense.label", 120 jParams, jParams.getLocale()); 121 request.setAttribute("jahiaDisplayMessage", dspMsg); 122 JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); 124 return; 125 } 126 127 userRequestDispatcher( request, response, session); 129 } 131 132 133 141 142 153 154 155 156 164 private void userRequestDispatcher( HttpServletRequest request, 165 HttpServletResponse response, 166 HttpSession session ) 167 throws Throwable 168 { 169 displayAccess( request, response, session, request.getParameter("sub")); 170 } 172 173 174 183 protected void displayAccess( HttpServletRequest request, 184 HttpServletResponse response, 185 HttpSession session, 186 String type) 187 throws IOException , ServletException 188 { 189 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 190 ParamBean jParams = null; 191 if (jData != null) { 192 jParams = jData.params (); 193 } 194 if (type.equals("excel")){ 197 response.setContentType( "application/ms-excel" ); 198 response.setHeader("Content-Disposition","attachment; filename=\"user_access.xls\""); 199 } else { 200 response.setContentType( "text/plain" ); 201 } 202 ServletOutputStream result = response.getOutputStream(); 206 207 208 try { 209 String output = JahiaTools.html2text(drawRightsUserList(jParams)); 210 result.println( output ); 211 } catch ( Throwable t ){ 212 } finally { 214 result.close(); 215 } 216 217 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", 219 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 220 jParams, jParams.getLocale())); 221 } 223 224 private String drawRightsUserList(ParamBean jParams) 225 throws JahiaException { 226 227 StringBuffer output = new StringBuffer (); 228 229 Vector theUserList = ServicesRegistry.getInstance().getJahiaSiteUserManagerService().getMembers(site.getID()); 231 232 JahiaPage theHomePage = site.getHomePage(); 234 235 if (theHomePage != null) { 237 238 output.append("path"); 239 240 Enumeration theUserList0 = theUserList.elements(); 241 Enumeration theUserList1 = theUserList.elements(); 242 while (theUserList0.hasMoreElements()) { 243 JahiaUser theUser = (JahiaUser) theUserList0.nextElement(); 244 output.append("\t").append(theUser.getUsername()); 245 } 246 247 output.append("\n").append(theHomePage.getTitle()); 248 249 output.append(getPageRights(theUserList1, theHomePage)); 251 output.append(drawChildPages( theHomePage, theUserList, jParams )); 252 } 253 return output.toString(); 254 } 255 256 private String getPageRights( Enumeration theUserList, JahiaPage thePage ) 257 throws JahiaException { 258 259 StringBuffer output = new StringBuffer (); 260 261 while (theUserList.hasMoreElements()) { 263 JahiaUser theUser = (JahiaUser) theUserList.nextElement(); 264 output.append("\t"); 265 if (thePage.checkReadAccess(theUser)) { 266 output.append("r "); 267 } 268 if (thePage.checkWriteAccess(theUser)) { 269 output.append("w "); 270 } 271 if (thePage.checkAdminAccess(theUser)) { 272 output.append("a"); 273 } 274 } 275 return output.append("\n").toString(); 276 } 277 278 private String drawChildPages( JahiaPage parentPage, Vector theUserList, ParamBean jParams) 279 throws JahiaException { 280 StringBuffer output = new StringBuffer (); 281 282 if (parentPage != null) { 283 Enumeration pageChilds = parentPage.getChilds(user); 285 286 while (pageChilds.hasMoreElements()) { 288 JahiaPage nextPage = (JahiaPage) pageChilds.nextElement(); 289 if (nextPage != null) { 290 Enumeration theUserList1 = theUserList.elements(); 291 Enumeration thePath = nextPage.getContentPagePath(ParamBean.EDIT, user); 293 while (thePath.hasMoreElements()) { 294 ContentPage thePage = (ContentPage) thePath.nextElement(); 295 output.append(thePage.getTitle(jParams)); 296 if (thePath.hasMoreElements()) { 297 output.append(" : "); 298 } 299 } 300 301 output.append(getPageRights(theUserList1, nextPage)); 303 output.append(drawChildPages( nextPage, theUserList, jParams )); 304 } 305 } 306 } 307 308 return output.toString(); 310 } 311 312 313 } | Popular Tags |