1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.rest;
20
21 import java.io.IOException;
22 import java.security.PrivilegedExceptionAction;
23
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.hadoop.classification.InterfaceAudience;
29 import org.apache.hadoop.security.UserGroupInformation;
30
31 import com.sun.jersey.spi.container.servlet.ServletContainer;
32
33
34
35
36
37 @InterfaceAudience.Private
38 public class RESTServletContainer extends ServletContainer {
39 private static final long serialVersionUID = -2474255003443394314L;
40
41
42
43
44
45
46 @Override
47 public void service(final HttpServletRequest request,
48 final HttpServletResponse response) throws ServletException, IOException {
49 UserGroupInformation effectiveUser = UserGroupInformation.createProxyUser(
50 request.getRemoteUser(), RESTServlet.getInstance().getUser());
51 try {
52 effectiveUser.doAs(new PrivilegedExceptionAction<Void>() {
53 @Override
54 public Void run() throws ServletException, IOException {
55 callService(request, response);
56 return null;
57 }
58 });
59 } catch (InterruptedException e) {
60 Thread.currentThread().interrupt();
61 throw new IOException(e);
62 }
63 }
64
65
66
67
68
69 void callService(HttpServletRequest request,
70 HttpServletResponse response) throws ServletException, IOException {
71 super.service(request, response);
72 }
73 }