HopsX509Authenticator { public void authenticateConnection(UserGroupInformation user, X509Certificate clientCertificate, InetAddress remoteAddress) throws HopsX509AuthenticationException { authenticateConnection(user, clientCertificate, remoteAddress, null); } HopsX509Authenticator(Configuration conf); void authenticateConnection(UserGroupInformation user, X509Certificate clientCertificate,
      InetAddress remoteAddress); void authenticateConnection(UserGroupInformation user, X509Certificate clientCertificate,
      InetAddress remoteAddress, String protocolName); boolean isTrustedConnection(InetAddress remoteAddress, String cnFQDN); boolean isTrustedConnection(InetAddress remoteAddress, String cnFQDN, String username, String locality);  }
@Test public void TestAuthenticatedNormalUser() throws Exception { String o = "application_id"; X509Certificate clientCertificate = generateX509Certificate("CN=bob, O=" + o); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("bob"); InetAddress remoteAddress = InetAddress.getLocalHost(); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); Assert.assertEquals(o, ugi.getApplicationId()); }
@Test public void TestAuthenticatedNormalUserWebHDFS() throws Exception { String o = "application_id"; X509Certificate clientCertificate = generateX509Certificate("CN=bob, O=" + o); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("bob"); InetAddress remoteAddress = InetAddress.getLocalHost(); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress, "WebHDFS"); Assert.assertNull(ugi.getApplicationId()); }
@Test public void TestNotAuthenticatedNormalUser() throws Exception { X509Certificate clientCertificate = generateX509Certificate("CN=bob"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("trudy"); InetAddress remoteAddress = InetAddress.getLocalHost(); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); expectedException.expect(HopsX509AuthenticationException.class); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); }
@Test public void TestAuthenticatedSuperUser() throws Exception { InetAddress remoteAddress = InetAddress.getLocalHost(); String o = "application_id"; X509Certificate clientCertificate = generateX509Certificate("CN=" + remoteAddress.getCanonicalHostName() + ", O=" + o + ", L=alice"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("alice"); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); Assert.assertEquals(o, ugi.getApplicationId()); }
@Test public void TestNotAuthenticatedSuperUser() throws Exception { InetAddress remoteAddress = InetAddress.getLocalHost(); X509Certificate clientCertificate = generateX509Certificate("CN=i_hope_this_is_not_routable,L=real_super"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("chuck"); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); expectedException.expect(HopsX509AuthenticationException.class); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); }
@Test public void TestNotAuthenticatedSuperUserWithResolvableCN() throws Exception { InetAddress remoteAddress = InetAddress.getLocalHost(); X509Certificate clientCertificate = generateX509Certificate("CN=" + remoteAddress.getCanonicalHostName() + ", L=real_super"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("chuck"); HopsX509Authenticator authenticator = authFactory.getAuthenticator(); expectedException.expect(HopsX509AuthenticationException.class); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); }
@Test public void TestFQDNCache() throws Exception { InetAddress remoteAddress = InetAddress.getLocalHost(); X509Certificate clientCertificate = generateX509Certificate("CN=" + remoteAddress.getCanonicalHostName() + ",L=alice"); UserGroupInformation ugi = UserGroupInformation.createRemoteUser("alice"); CustomHopsX509Authenticator authenticator = new CustomHopsX509Authenticator(conf); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); Assert.assertFalse(authenticator.iscached); authenticator.authenticateConnection(ugi, clientCertificate, remoteAddress); Assert.assertTrue(authenticator.iscached); }