1 17 package org.alfresco.repo.webdav; 18 19 import java.net.MalformedURLException ; 20 import java.net.URL ; 21 22 import javax.servlet.http.HttpServletResponse ; 23 24 29 public abstract class HierarchicalMethod extends WebDAVMethod 30 { 31 33 protected String m_strDestinationPath; 34 protected boolean m_overwrite = false; 35 36 39 public HierarchicalMethod() 40 { 41 } 42 43 48 public final String getDestinationPath() 49 { 50 return m_strDestinationPath; 51 } 52 53 58 public final boolean hasOverWrite() 59 { 60 return m_overwrite; 61 } 62 63 68 protected void parseRequestHeaders() throws WebDAVServerException 69 { 70 72 String strDestination = m_request.getHeader(WebDAV.HEADER_DESTINATION); 73 74 if (logger.isDebugEnabled()) 75 logger.debug("Parsing Destination header: " + strDestination); 76 77 if (strDestination != null && strDestination.length() > 0) 78 { 79 int offset = -1; 80 81 if (strDestination.startsWith("http://")) 82 { 83 86 checkDestinationPath(strDestination); 87 88 90 offset = 7; 91 } 92 else if (strDestination.startsWith("https://")) 93 { 94 97 checkDestinationPath(strDestination); 98 99 101 offset = 8; 102 } 103 104 106 if (offset != -1) 107 { 108 offset = strDestination.indexOf(WebDAV.PathSeperator, offset); 109 if (offset != -1) 110 { 111 String strPath = strDestination.substring(offset); 112 String servletPath = m_request.getServletPath(); 113 114 offset = strPath.indexOf(servletPath); 115 if (offset != -1) 116 strPath = strPath.substring(offset + servletPath.length()); 117 118 m_strDestinationPath = WebDAV.decodeURL(strPath); 119 } 120 } 121 } 122 123 125 if (m_strDestinationPath == null) 126 { 127 logger.warn("Failed to parse the Destination header: " + strDestination); 128 throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST); 129 } 130 131 133 String strOverwrite = m_request.getHeader(WebDAV.HEADER_OVERWRITE); 134 if (strOverwrite != null && strOverwrite.equals(WebDAV.T)) 135 { 136 m_overwrite = true; 137 } 138 } 139 140 145 protected void parseRequestBody() throws WebDAVServerException 146 { 147 } 152 153 160 protected final void checkDestinationPath(String path) throws WebDAVServerException 161 { 162 try 163 { 164 166 URL url = new URL (path); 167 168 170 boolean localPath = true; 171 172 if (url.getPort() != -1 && url.getPort() != m_request.getLocalPort()) 173 { 174 176 if (logger.isDebugEnabled()) 177 logger.debug("Destination path, different server port"); 178 179 localPath = false; 180 } 181 else if (url.getHost().equals(m_request.getLocalName()) == false 182 && url.getHost().equals(m_request.getLocalAddr()) == false) 183 { 184 186 if (logger.isDebugEnabled()) 187 logger.debug("Destination path, different server name/address"); 188 189 localPath = false; 190 } 191 else if (url.getPath().indexOf(m_request.getServletPath()) == -1) 192 { 193 195 if (logger.isDebugEnabled()) 196 logger.debug("Destination path, different serlet path"); 197 198 localPath = false; 199 } 200 201 204 if (localPath != true) 205 throw new WebDAVServerException(HttpServletResponse.SC_BAD_GATEWAY); 206 } 207 catch (MalformedURLException ex) 208 { 209 211 if (logger.isDebugEnabled()) 212 logger.debug("Bad destination path, " + path); 213 214 throw new WebDAVServerException(HttpServletResponse.SC_BAD_GATEWAY); 215 } 216 } 217 } 218 | Popular Tags |