Search in sources :

Example 6 with ConnectionInfo

use of org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo in project phoenix by apache.

the class SecureUserConnectionsTest method testAlternatingLogins.

@Test
public void testAlternatingLogins() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    final String princ2 = getUserPrincipal(2);
    final File keytab2 = getUserKeytabFile(2);
    UserGroupInformation ugi1 = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
    UserGroupInformation ugi2 = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ2, keytab2.getPath());
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    ugi1.doAs(new PrivilegedExceptionAction<Void>() {

        public Void run() throws Exception {
            String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
            connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
            return null;
        }
    });
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
    ugi2.doAs(new PrivilegedExceptionAction<Void>() {

        public Void run() throws Exception {
            String url = joinUserAuthentication(BASE_URL, princ2, keytab2);
            connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
            return null;
        }
    });
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    ugi1.doAs(new PrivilegedExceptionAction<Void>() {

        public Void run() throws Exception {
            String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
            connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
            return null;
        }
    });
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) File(java.io.File) IOException(java.io.IOException) HashSet(java.util.HashSet) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 7 with ConnectionInfo

use of org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo in project phoenix by apache.

the class SecureUserConnectionsTest method testAlternatingConnectionsWithoutLogin.

@Test
public void testAlternatingConnectionsWithoutLogin() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    final String princ2 = getUserPrincipal(2);
    final File keytab2 = getUserKeytabFile(2);
    final String url1 = joinUserAuthentication(BASE_URL, princ1, keytab1);
    final String url2 = joinUserAuthentication(BASE_URL, princ2, keytab2);
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
    // Because the UGI instances are unique, so are the connections
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(3, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with ConnectionInfo

use of org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo in project phoenix by apache.

the class SecureUserConnectionsTest method testMultipleConnectionsAsSameUser.

@Test
public void testMultipleConnectionsAsSameUser() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    final String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
    UserGroupInformation.loginUserFromKeytab(princ1, keytab1.getPath());
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
    // Because the UGI instances are unique, so are the connections
    connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with ConnectionInfo

use of org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo in project phoenix by apache.

the class SecureUserConnectionsTest method testHostSubstitutionInUrl.

@Test
public void testHostSubstitutionInUrl() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getServicePrincipal(1);
    final File keytab1 = getServiceKeytabFile(1);
    final String princ2 = getServicePrincipal(2);
    final File keytab2 = getServiceKeytabFile(2);
    final String url1 = joinUserAuthentication(BASE_URL, princ1, keytab1);
    final String url2 = joinUserAuthentication(BASE_URL, princ2, keytab2);
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
    // Logging in as the same user again should not duplicate connections
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);
    // Add a second one.
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    // Again, verify this user is not duplicated
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    // Because the UGI instances are unique, so are the connections
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(3, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ConnectionInfo

use of org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo in project phoenix by apache.

the class PhoenixEmbeddedDriverTest method testGetConnectionInfo.

@Test
public void testGetConnectionInfo() throws SQLException {
    String[] urls = new String[] { null, "", "jdbc:phoenix", "jdbc:phoenix;test=true", "jdbc:phoenix:localhost", "localhost", "localhost;", "jdbc:phoenix:localhost:123", "jdbc:phoenix:localhost:123;foo=bar", "localhost:123", "jdbc:phoenix:localhost:123:/hbase", "jdbc:phoenix:localhost:123:/foo-bar", "jdbc:phoenix:localhost:123:/foo-bar;foo=bas", "localhost:123:/foo-bar", "jdbc:phoenix:localhost:/hbase", "jdbc:phoenix:localhost:/foo-bar", "jdbc:phoenix:localhost:/foo-bar;test=true", "localhost:/foo-bar", "jdbc:phoenix:v1,v2,v3", "jdbc:phoenix:v1,v2,v3;", "jdbc:phoenix:v1,v2,v3;test=true", "v1,v2,v3", "jdbc:phoenix:v1,v2,v3:/hbase", "jdbc:phoenix:v1,v2,v3:/hbase;test=true", "v1,v2,v3:/foo-bar", "jdbc:phoenix:v1,v2,v3:123:/hbase", "v1,v2,v3:123:/hbase", "jdbc:phoenix:v1,v2,v3:123:/hbase;test=false", "jdbc:phoenix:v1,v2,v3:123:/hbase:user/principal:/user.keytab;test=false", "jdbc:phoenix:v1,v2,v3:123:/foo-bar:user/principal:/user.keytab;test=false", "jdbc:phoenix:v1,v2,v3:123:user/principal:/user.keytab;test=false", "jdbc:phoenix:v1,v2,v3:user/principal:/user.keytab;test=false", "jdbc:phoenix:v1,v2,v3:/hbase:user/principal:/user.keytab;test=false", "jdbc:phoenix:v1,v2,v3:LongRunningQueries;test=false", "jdbc:phoenix:v1,v2,v3:345:LongRunningQueries;test=false", "jdbc:phoenix:localhost:1234:user:C:\\user.keytab", "jdbc:phoenix:v1,v2,v3:345:/hbase:user1:C:\\Documents and Settings\\user1\\user1.keytab;test=false" };
    ConnectionInfo[] infos = new ConnectionInfo[] { new ConnectionInfo("localhost", 2181, "/hbase"), new ConnectionInfo("localhost", 2181, "/hbase"), new ConnectionInfo("localhost", 2181, "/hbase"), new ConnectionInfo(null, null, null), new ConnectionInfo("localhost", null, null), new ConnectionInfo("localhost", null, null), new ConnectionInfo("localhost", null, null), new ConnectionInfo("localhost", 123, null), new ConnectionInfo("localhost", 123, null), new ConnectionInfo("localhost", 123, null), new ConnectionInfo("localhost", 123, "/hbase"), new ConnectionInfo("localhost", 123, "/foo-bar"), new ConnectionInfo("localhost", 123, "/foo-bar"), new ConnectionInfo("localhost", 123, "/foo-bar"), new ConnectionInfo("localhost", null, "/hbase"), new ConnectionInfo("localhost", null, "/foo-bar"), new ConnectionInfo("localhost", null, "/foo-bar"), new ConnectionInfo("localhost", null, "/foo-bar"), new ConnectionInfo("v1,v2,v3", null, null), new ConnectionInfo("v1,v2,v3", null, null), new ConnectionInfo("v1,v2,v3", null, null), new ConnectionInfo("v1,v2,v3", null, null), new ConnectionInfo("v1,v2,v3", null, "/hbase"), new ConnectionInfo("v1,v2,v3", null, "/hbase"), new ConnectionInfo("v1,v2,v3", null, "/foo-bar"), new ConnectionInfo("v1,v2,v3", 123, "/hbase"), new ConnectionInfo("v1,v2,v3", 123, "/hbase"), new ConnectionInfo("v1,v2,v3", 123, "/hbase"), new ConnectionInfo("v1,v2,v3", 123, "/hbase", "user/principal", "/user.keytab"), new ConnectionInfo("v1,v2,v3", 123, "/foo-bar", "user/principal", "/user.keytab"), new ConnectionInfo("v1,v2,v3", 123, null, "user/principal", "/user.keytab"), new ConnectionInfo("v1,v2,v3", null, null, "user/principal", "/user.keytab"), new ConnectionInfo("v1,v2,v3", null, "/hbase", "user/principal", "/user.keytab"), new ConnectionInfo("v1,v2,v3", null, null, "LongRunningQueries", null), new ConnectionInfo("v1,v2,v3", 345, null, "LongRunningQueries", null), new ConnectionInfo("localhost", 1234, null, "user", "C:\\user.keytab"), new ConnectionInfo("v1,v2,v3", 345, "/hbase", "user1", "C:\\Documents and Settings\\user1\\user1.keytab") };
    assertEquals(urls.length, infos.length);
    for (int i = 0; i < urls.length; i++) {
        try {
            ConnectionInfo info = ConnectionInfo.create(urls[i]);
            assertEquals(infos[i], info);
        } catch (AssertionError e) {
            throw new AssertionError("For \"" + urls[i] + "\": " + e.getMessage());
        }
    }
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) Test(org.junit.Test)

Aggregations

ConnectionInfo (org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo)10 Test (org.junit.Test)9 File (java.io.File)8 HashSet (java.util.HashSet)8 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 IOException (java.io.IOException)1 TransactionManager (org.apache.tephra.TransactionManager)1 TransactionService (org.apache.tephra.distributed.TransactionService)1 TxMetricsCollector (org.apache.tephra.metrics.TxMetricsCollector)1 HDFSTransactionStateStorage (org.apache.tephra.persist.HDFSTransactionStateStorage)1 SnapshotCodecProvider (org.apache.tephra.snapshot.SnapshotCodecProvider)1 DiscoveryService (org.apache.twill.discovery.DiscoveryService)1 ZKDiscoveryService (org.apache.twill.discovery.ZKDiscoveryService)1