use of javax.servlet.http.HttpServletRequestWrapper in project nutz by nutzam.
the class WhaleFilter method handleUpload.
@SuppressWarnings("unchecked")
public HttpServletRequest handleUpload(HttpServletRequest req) throws ServletException {
try {
FastUploading fup = new FastUploading();
final Map<String, Object> params = fup.parse(req, (UploadingContext) uc);
final List<TempFile> files = new ArrayList<TempFile>();
Iterator<Entry<String, Object>> it = params.entrySet().iterator();
while (it.hasNext()) {
Object obj = it.next().getValue();
final boolean[] re = new boolean[1];
Lang.each(obj, new Each<Object>() {
public void invoke(int index, Object ele, int length) {
if (ele != null && ele instanceof TempFile) {
files.add((TempFile) ele);
re[0] = true;
}
}
});
if (re[0])
it.remove();
}
req.setAttribute("_files", files);
params.putAll(req.getParameterMap());
return new HttpServletRequestWrapper(req) {
public String getParameter(String name) {
return (String) params.get(name);
}
@SuppressWarnings("rawtypes")
public Map getParameterMap() {
return params;
}
@SuppressWarnings("rawtypes")
public Enumeration getParameterNames() {
return Collections.enumeration(params.keySet());
}
public String[] getParameterValues(String name) {
if (params.containsKey(name))
return new String[] { (String) params.get(name) };
return null;
}
};
} catch (UploadException e) {
throw new ServletException("upload fail", e);
}
}
use of javax.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class HttpSessionSecurityContextRepositoryTests method traverseWrappedRequests.
// SEC-2578
@Test
public void traverseWrappedRequests() {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
SecurityContext context = repo.loadContext(holder);
assertThat(request.getSession(false)).isNull();
// Simulate authentication during the request
context.setAuthentication(testToken);
repo.saveContext(context, new HttpServletRequestWrapper(holder.getRequest()), new HttpServletResponseWrapper(holder.getResponse()));
assertThat(request.getSession(false)).isNotNull();
assertThat(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY)).isEqualTo(context);
}
use of javax.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class DebugFilterTest method doFilterDoesNotWrapWithDebugRequestWrapperAgain.
@Test
public void doFilterDoesNotWrapWithDebugRequestWrapperAgain() throws Exception {
when(request.getAttribute(requestAttr)).thenReturn(Boolean.TRUE);
HttpServletRequest fireWalledRequest = new HttpServletRequestWrapper(new DebugRequestWrapper(this.request));
filter.doFilter(fireWalledRequest, response, filterChain);
verify(fcp).doFilter(fireWalledRequest, response, filterChain);
}
use of javax.servlet.http.HttpServletRequestWrapper in project spring-framework by spring-projects.
the class ServletWebRequestTests method decoratedNativeRequest.
@Test
public void decoratedNativeRequest() {
HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
assertSame(decoratedRequest, request.getNativeRequest());
assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
assertNull(request.getNativeRequest(MultipartRequest.class));
assertSame(decoratedResponse, request.getNativeResponse());
assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
assertNull(request.getNativeResponse(MultipartRequest.class));
}
use of javax.servlet.http.HttpServletRequestWrapper in project hadoop by apache.
the class DelegationTokenAuthenticationFilter method doFilter.
@Override
protected void doFilter(FilterChain filterChain, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
boolean requestCompleted = false;
UserGroupInformation ugi = null;
AuthenticationToken authToken = (AuthenticationToken) request.getUserPrincipal();
if (authToken != null && authToken != AuthenticationToken.ANONYMOUS) {
// if the request was authenticated because of a delegation token,
// then we ignore proxyuser (this is the same as the RPC behavior).
ugi = (UserGroupInformation) request.getAttribute(DelegationTokenAuthenticationHandler.DELEGATION_TOKEN_UGI_ATTRIBUTE);
if (ugi == null) {
String realUser = request.getUserPrincipal().getName();
ugi = UserGroupInformation.createRemoteUser(realUser, handlerAuthMethod);
String doAsUser = getDoAs(request);
if (doAsUser != null) {
ugi = UserGroupInformation.createProxyUser(doAsUser, ugi);
try {
ProxyUsers.authorize(ugi, request.getRemoteAddr());
} catch (AuthorizationException ex) {
HttpExceptionUtils.createServletExceptionResponse(response, HttpServletResponse.SC_FORBIDDEN, ex);
requestCompleted = true;
if (LOG.isDebugEnabled()) {
LOG.debug("Authentication exception: " + ex.getMessage(), ex);
} else {
LOG.warn("Authentication exception: " + ex.getMessage());
}
}
}
}
UGI_TL.set(ugi);
}
if (!requestCompleted) {
final UserGroupInformation ugiF = ugi;
try {
request = new HttpServletRequestWrapper(request) {
@Override
public String getAuthType() {
return (ugiF != null) ? handlerAuthMethod.toString() : null;
}
@Override
public String getRemoteUser() {
return (ugiF != null) ? ugiF.getShortUserName() : null;
}
@Override
public Principal getUserPrincipal() {
return (ugiF != null) ? new Principal() {
@Override
public String getName() {
return ugiF.getUserName();
}
} : null;
}
};
super.doFilter(filterChain, request, response);
} finally {
UGI_TL.remove();
}
}
}
Aggregations