2727
2828import javax .servlet .ServletContext ;
2929import javax .servlet .ServletException ;
30- import javax .servlet .http .HttpServlet ;
3130import javax .servlet .http .HttpServletRequest ;
3231import javax .servlet .http .HttpServletResponse ;
3332
3433import org .apache .commons .text .StringEscapeUtils ;
34+ import org .apache .hadoop .hdfs .server .namenode .DfsServlet ;
3535import org .slf4j .Logger ;
3636import org .slf4j .LoggerFactory ;
3737import org .apache .hadoop .classification .InterfaceAudience ;
6464 * </ul>
6565 */
6666@ InterfaceAudience .Private
67- public class GetJournalEditServlet extends HttpServlet {
67+ public class GetJournalEditServlet extends DfsServlet {
6868
6969 private static final long serialVersionUID = -4635891628211723009L ;
7070 private static final Logger LOG =
@@ -77,17 +77,11 @@ public class GetJournalEditServlet extends HttpServlet {
7777
7878 protected boolean isValidRequestor (HttpServletRequest request , Configuration conf )
7979 throws IOException {
80- String remotePrincipal = request .getUserPrincipal ().getName ();
81- String remoteShortName = request .getRemoteUser ();
82- if (remotePrincipal == null ) { // This really shouldn't happen...
83- LOG .warn ("Received null remoteUser while authorizing access to " +
84- "GetJournalEditServlet" );
85- return false ;
86- }
80+ UserGroupInformation ugi = getUGI (request , conf );
8781
8882 if (LOG .isDebugEnabled ()) {
89- LOG .debug ("Validating request made by " + remotePrincipal +
90- " / " + remoteShortName + ". This user is: " +
83+ LOG .debug ("Validating request made by " + ugi . getUserName () +
84+ " / " + ugi . getShortUserName () + ". This user is: " +
9185 UserGroupInformation .getLoginUser ());
9286 }
9387
@@ -115,26 +109,26 @@ protected boolean isValidRequestor(HttpServletRequest request, Configuration con
115109 for (String v : validRequestors ) {
116110 if (LOG .isDebugEnabled ())
117111 LOG .debug ("isValidRequestor is comparing to valid requestor: " + v );
118- if (v != null && v .equals (remotePrincipal )) {
112+ if (v != null && v .equals (ugi . getUserName () )) {
119113 if (LOG .isDebugEnabled ())
120- LOG .debug ("isValidRequestor is allowing: " + remotePrincipal );
114+ LOG .debug ("isValidRequestor is allowing: " + ugi . getUserName () );
121115 return true ;
122116 }
123117 }
124118
125119 // Additionally, we compare the short name of the requestor to this JN's
126120 // username, because we want to allow requests from other JNs during
127121 // recovery, but we can't enumerate the full list of JNs.
128- if (remoteShortName .equals (
122+ if (ugi . getShortUserName () .equals (
129123 UserGroupInformation .getLoginUser ().getShortUserName ())) {
130124 if (LOG .isDebugEnabled ())
131125 LOG .debug ("isValidRequestor is allowing other JN principal: " +
132- remotePrincipal );
126+ ugi . getUserName () );
133127 return true ;
134128 }
135129
136130 if (LOG .isDebugEnabled ())
137- LOG .debug ("isValidRequestor is rejecting: " + remotePrincipal );
131+ LOG .debug ("isValidRequestor is rejecting: " + ugi . getUserName () );
138132 return false ;
139133 }
140134
0 commit comments