@Test public void testGetProxyUgi() throws IOException { conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs: ServletContext context = mock(ServletContext.class); String realUser = "TheDoctor"; String user = "TheNurse"; conf.set(DFSConfigKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); conf.set(DefaultImpersonationProvider.getTestProvider(). getProxySuperuserGroupConfKey(realUser), "*"); conf.set(DefaultImpersonationProvider.getTestProvider(). getProxySuperuserIpConfKey(realUser), "*"); ProxyUsers.refreshSuperUserGroupsConfiguration(conf); UserGroupInformation.setConfiguration(conf); UserGroupInformation ugi; HttpServletRequest request; request = getMockRequest(null, null, user); try { JspHelper.getUGI(context, request, conf); Assert.fail("bad request allowed"); } catch (IOException ioe) { Assert.assertEquals( "Security enabled but user not authenticated by filter", ioe.getMessage()); } request = getMockRequest(null, realUser, user); try { JspHelper.getUGI(context, request, conf); Assert.fail("bad request allowed"); } catch (IOException ioe) { Assert.assertEquals( "Security enabled but user not authenticated by filter", ioe.getMessage()); } request = getMockRequest(realUser, null, user); ugi = JspHelper.getUGI(context, request, conf); Assert.assertNotNull(ugi.getRealUser()); Assert.assertEquals(ugi.getRealUser().getShortUserName(), realUser); Assert.assertEquals(ugi.getShortUserName(), user); checkUgiFromAuth(ugi); request = getMockRequest(realUser, realUser, user); ugi = JspHelper.getUGI(context, request, conf); Assert.assertNotNull(ugi.getRealUser()); Assert.assertEquals(ugi.getRealUser().getShortUserName(), realUser); Assert.assertEquals(ugi.getShortUserName(), user); checkUgiFromAuth(ugi); request = getMockRequest(realUser, user, user); try { JspHelper.getUGI(context, request, conf); Assert.fail("bad request allowed"); } catch (IOException ioe) { Assert.assertEquals( "Usernames not matched: name="+user+" != expected="+realUser, ioe.getMessage()); } try { request = getMockRequest(user, null, realUser); JspHelper.getUGI(context, request, conf); Assert.fail("bad proxy request allowed"); } catch (AuthorizationException ae) { Assert.assertEquals( "User: " + user + " is not allowed to impersonate " + realUser, ae.getMessage()); } try { request = getMockRequest(user, user, realUser); JspHelper.getUGI(context, request, conf); Assert.fail("bad proxy request allowed"); } catch (AuthorizationException ae) { Assert.assertEquals( "User: " + user + " is not allowed to impersonate " + realUser, ae.getMessage()); } }
public static UserGroupInformation getUGI(HttpServletRequest request, Configuration conf) throws IOException { return getUGI(null, request, conf); }
JspHelper { public static UserGroupInformation getUGI(HttpServletRequest request, Configuration conf) throws IOException { return getUGI(null, request, conf); } }
JspHelper { public static UserGroupInformation getUGI(HttpServletRequest request, Configuration conf) throws IOException { return getUGI(null, request, conf); } private  JspHelper(); }
JspHelper { public static UserGroupInformation getUGI(HttpServletRequest request, Configuration conf) throws IOException { return getUGI(null, request, conf); } private  JspHelper(); static DatanodeInfo bestNode(LocatedBlocks blks, Configuration conf); static String validatePath(String p); static Long validateLong(String value); static String getDefaultWebUserName(Configuration conf); static UserGroupInformation getUGI(HttpServletRequest request,
      Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf,
      final AuthenticationMethod secureAuthMethod,
      final boolean tryUgiParameter); static String getRemoteAddr(HttpServletRequest request); static void checkUsername(final String expected, final String name
      ); static String getDelegationTokenUrlParam(String tokenString); static String getUrlParam(String name, String val, String paramSeparator); static String getUrlParam(String name, String val, boolean firstParam); static String getUrlParam(String name, String val); }
JspHelper { public static UserGroupInformation getUGI(HttpServletRequest request, Configuration conf) throws IOException { return getUGI(null, request, conf); } private  JspHelper(); static DatanodeInfo bestNode(LocatedBlocks blks, Configuration conf); static String validatePath(String p); static Long validateLong(String value); static String getDefaultWebUserName(Configuration conf); static UserGroupInformation getUGI(HttpServletRequest request,
      Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf,
      final AuthenticationMethod secureAuthMethod,
      final boolean tryUgiParameter); static String getRemoteAddr(HttpServletRequest request); static void checkUsername(final String expected, final String name
      ); static String getDelegationTokenUrlParam(String tokenString); static String getUrlParam(String name, String val, String paramSeparator); static String getUrlParam(String name, String val, boolean firstParam); static String getUrlParam(String name, String val); static final String CURRENT_CONF; static final String DELEGATION_PARAMETER_NAME; static final String NAMENODE_ADDRESS; }