-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RestrictedHttpServletRequest to enhance security by limiting re…
…quest modifications
- Loading branch information
1 parent
1ccdc8e
commit 1ad5092
Showing
4 changed files
with
262 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 233 additions & 0 deletions
233
presto-spi/src/main/java/com/facebook/presto/spi/security/RestrictedHttpServletRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.spi.security; | ||
|
||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.security.Principal; | ||
import java.util.Enumeration; | ||
import java.util.Map; | ||
|
||
public class RestrictedHttpServletRequest | ||
extends HttpServletRequestWrapper | ||
{ | ||
/** | ||
* Constructs a request object wrapping the given request. | ||
* | ||
* @param request | ||
* @throws IllegalArgumentException if the request is null | ||
*/ | ||
public RestrictedHttpServletRequest(HttpServletRequest request) | ||
{ | ||
super(request); | ||
} | ||
|
||
@Override | ||
public BufferedReader getReader() throws IOException | ||
{ | ||
throw new UnsupportedOperationException("Reading the request body via getReader is not supported."); | ||
} | ||
|
||
@Override | ||
public javax.servlet.ServletInputStream getInputStream() throws IOException | ||
{ | ||
throw new UnsupportedOperationException("Reading the request body via getInputStream is not supported."); | ||
} | ||
|
||
@Override | ||
public void setAttribute(String name, Object o) | ||
{ | ||
throw new UnsupportedOperationException("Modifying request attributes is not supported."); | ||
} | ||
|
||
@Override | ||
public void removeAttribute(String name) | ||
{ | ||
throw new UnsupportedOperationException("Modifying request attributes is not supported."); | ||
} | ||
|
||
// Delegate all other methods to the wrapped request | ||
@Override | ||
public String getAuthType() | ||
{ | ||
return super.getAuthType(); | ||
} | ||
|
||
@Override | ||
public Cookie[] getCookies() | ||
{ | ||
return super.getCookies(); | ||
} | ||
|
||
@Override | ||
public long getDateHeader(String name) | ||
{ | ||
return super.getDateHeader(name); | ||
} | ||
|
||
@Override | ||
public String getHeader(String name) | ||
{ | ||
return super.getHeader(name); | ||
} | ||
|
||
@Override | ||
public Enumeration<String> getHeaders(String name) | ||
{ | ||
return super.getHeaders(name); | ||
} | ||
|
||
@Override | ||
public Enumeration<String> getHeaderNames() | ||
{ | ||
return super.getHeaderNames(); | ||
} | ||
|
||
@Override | ||
public int getIntHeader(String name) | ||
{ | ||
return super.getIntHeader(name); | ||
} | ||
|
||
@Override | ||
public String getMethod() | ||
{ | ||
return super.getMethod(); | ||
} | ||
|
||
@Override | ||
public String getPathInfo() | ||
{ | ||
return super.getPathInfo(); | ||
} | ||
|
||
@Override | ||
public String getPathTranslated() | ||
{ | ||
return super.getPathTranslated(); | ||
} | ||
|
||
@Override | ||
public String getContextPath() | ||
{ | ||
return super.getContextPath(); | ||
} | ||
|
||
@Override | ||
public String getQueryString() | ||
{ | ||
return super.getQueryString(); | ||
} | ||
|
||
@Override | ||
public String getRemoteUser() | ||
{ | ||
return super.getRemoteUser(); | ||
} | ||
|
||
@Override | ||
public boolean isUserInRole(String role) | ||
{ | ||
return super.isUserInRole(role); | ||
} | ||
|
||
@Override | ||
public Principal getUserPrincipal() | ||
{ | ||
return super.getUserPrincipal(); | ||
} | ||
|
||
@Override | ||
public String getRequestedSessionId() | ||
{ | ||
return super.getRequestedSessionId(); | ||
} | ||
|
||
@Override | ||
public String getRequestURI() | ||
{ | ||
return super.getRequestURI(); | ||
} | ||
|
||
@Override | ||
public StringBuffer getRequestURL() | ||
{ | ||
return super.getRequestURL(); | ||
} | ||
|
||
@Override | ||
public String getServletPath() | ||
{ | ||
return super.getServletPath(); | ||
} | ||
|
||
@Override | ||
public HttpSession getSession(boolean create) | ||
{ | ||
return super.getSession(create); | ||
} | ||
|
||
@Override | ||
public HttpSession getSession() | ||
{ | ||
return super.getSession(); | ||
} | ||
|
||
@Override | ||
public String changeSessionId() | ||
{ | ||
return super.changeSessionId(); | ||
} | ||
|
||
@Override | ||
public boolean isRequestedSessionIdValid() | ||
{ | ||
return super.isRequestedSessionIdValid(); | ||
} | ||
|
||
@Override | ||
public boolean isRequestedSessionIdFromCookie() | ||
{ | ||
return super.isRequestedSessionIdFromCookie(); | ||
} | ||
|
||
@Override | ||
public boolean isRequestedSessionIdFromURL() | ||
{ | ||
return super.isRequestedSessionIdFromURL(); | ||
} | ||
|
||
@Override | ||
public boolean isRequestedSessionIdFromUrl() | ||
{ | ||
return super.isRequestedSessionIdFromUrl(); | ||
} | ||
|
||
@Override | ||
public Map<String, String[]> getParameterMap() | ||
{ | ||
return super.getParameterMap(); | ||
} | ||
|
||
@Override | ||
public String[] getParameterValues(String name) | ||
{ | ||
return super.getParameterValues(name); | ||
} | ||
} |