1 17 package org.alfresco.web.app.servlet; 18 19 import java.io.IOException ; 20 import java.text.MessageFormat ; 21 import java.util.StringTokenizer ; 22 23 import javax.faces.application.NavigationHandler; 24 import javax.faces.context.FacesContext; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.alfresco.repo.webdav.WebDAVServlet; 30 import org.alfresco.service.ServiceRegistry; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.cmr.repository.StoreRef; 33 import org.alfresco.service.cmr.security.AccessStatus; 34 import org.alfresco.service.cmr.security.PermissionService; 35 import org.alfresco.web.app.Application; 36 import org.alfresco.web.bean.BrowseBean; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 58 public class ExternalAccessServlet extends BaseServlet 59 { 60 private static final long serialVersionUID = -4118907921337237802L; 61 62 private static Log logger = LogFactory.getLog(ExternalAccessServlet.class); 63 64 private final static String OUTCOME_DOCDETAILS = "showDocDetails"; 65 private final static String OUTCOME_SPACEDETAILS = "showSpaceDetails"; 66 private final static String OUTCOME_BROWSE = "browse"; 67 private final static String OUTCOME_LOGOUT = "logout"; 68 69 private static final String ARG_TEMPLATE = "template"; 70 71 74 protected void service(HttpServletRequest req, HttpServletResponse res) 75 throws ServletException , IOException 76 { 77 String uri = req.getRequestURI(); 78 79 if (logger.isDebugEnabled()) 80 logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : "")); 81 82 AuthenticationStatus status = servletAuthenticate(req, res); 83 if (status == AuthenticationStatus.Failure) 84 { 85 return; 86 } 87 88 StringTokenizer t = new StringTokenizer (uri, "/"); 89 int count = t.countTokens(); 90 if (count < 3) 91 { 92 throw new IllegalArgumentException ("Externally addressable URL did not contain all required args: " + uri); 93 } 94 t.nextToken(); t.nextToken(); 97 String outcome = t.nextToken(); 98 99 String [] args = new String [count - 3]; 101 for (int i=0; i<count - 3; i++) 102 { 103 args[i] = t.nextToken(); 104 } 105 106 if (logger.isDebugEnabled()) 107 logger.debug("External outcome found: " + outcome); 108 109 FacesContext fc = FacesHelper.getFacesContext(req, res, getServletContext()); 111 BrowseBean browseBean = (BrowseBean)FacesHelper.getManagedBean(fc, "BrowseBean"); 112 113 ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext()); 115 PermissionService permissionService = serviceRegistry.getPermissionService(); 116 117 if (OUTCOME_DOCDETAILS.equals(outcome)) 119 { 120 NodeRef nodeRef = null; 121 122 if (args[0].equals(WebDAVServlet.WEBDAV_PREFIX)) 123 { 124 nodeRef = resolveWebDAVPath(fc, args); 125 } 126 else if (args.length == 3) 127 { 128 StoreRef storeRef = new StoreRef(args[0], args[1]); 129 nodeRef = new NodeRef(storeRef, args[2]); 130 } 131 132 if (nodeRef != null) 133 { 134 if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) 136 { 137 if (logger.isDebugEnabled()) 138 logger.debug("User does not have permissions to READ NodeRef: " + nodeRef.toString()); 139 redirectToLoginPage(req, res, getServletContext()); 140 return; 141 } 142 143 browseBean.setupContentAction(nodeRef.getId(), true); 145 } 146 147 NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); 149 navigationHandler.handleNavigation(fc, null, outcome); 150 } 151 else if (OUTCOME_SPACEDETAILS.equals(outcome)) 152 { 153 NodeRef nodeRef = null; 154 155 if (args[0].equals(WebDAVServlet.WEBDAV_PREFIX)) 156 { 157 nodeRef = resolveWebDAVPath(fc, args); 158 } 159 else if (args.length == 3) 160 { 161 StoreRef storeRef = new StoreRef(args[0], args[1]); 162 nodeRef = new NodeRef(storeRef, args[2]); 163 } 164 165 if (nodeRef != null) 166 { 167 if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) 169 { 170 if (logger.isDebugEnabled()) 171 logger.debug("User does not have permissions to READ NodeRef: " + nodeRef.toString()); 172 redirectToLoginPage(req, res, getServletContext()); 173 return; 174 } 175 176 browseBean.setupSpaceAction(nodeRef.getId(), true); 178 } 179 180 NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); 182 navigationHandler.handleNavigation(fc, null, outcome); 183 } 184 else if (OUTCOME_BROWSE.equals(outcome)) 185 { 186 if (args != null && args.length >= 3) 187 { 188 NodeRef nodeRef = null; 189 int offset = 0; 190 191 offset = args.length - 3; 192 StoreRef storeRef = new StoreRef(args[0+offset], args[1+offset]); 193 nodeRef = new NodeRef(storeRef, args[2+offset]); 194 195 if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) 197 { 198 if (logger.isDebugEnabled()) 199 logger.debug("User does not have permissions to READ NodeRef: " + nodeRef.toString()); 200 redirectToLoginPage(req, res, getServletContext()); 201 return; 202 } 203 204 browseBean.updateUILocation(nodeRef); 207 208 browseBean.externalAccessRefresh(); 210 211 if (args[0].equals(ARG_TEMPLATE)) 213 { 214 browseBean.setDashboardView(true); 215 } 216 217 } 219 else 220 { 221 NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); 223 navigationHandler.handleNavigation(fc, null, outcome); 224 } 225 } 226 else if (OUTCOME_LOGOUT.equals(outcome)) 227 { 228 req.getSession().invalidate(); 230 res.sendRedirect(req.getContextPath() + FACES_SERVLET + Application.getLoginPage(getServletContext())); 231 return; 232 } 233 234 String viewId = fc.getViewRoot().getViewId(); 236 getServletContext().getRequestDispatcher(FACES_SERVLET + viewId).forward(req, res); 237 } 238 239 248 public final static String generateExternalURL(String outcome, String args) 249 { 250 if (args == null) 251 { 252 return MessageFormat.format(EXTERNAL_URL, new Object [] {outcome} ); 253 } 254 else 255 { 256 return MessageFormat.format(EXTERNAL_URL_ARGS, new Object [] {outcome, args} ); 257 } 258 } 259 260 private static final String EXTERNAL_URL = "/navigate/{0}"; 262 private static final String EXTERNAL_URL_ARGS = "/navigate/{0}/{1}"; 263 } 264 | Popular Tags |