Search in sources :

Example 1 with ConnectionInfo

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

the class SecureUserConnectionsTest method testMultipleInvocationsBySameUserAreEquivalent.

@Test
public void testMultipleInvocationsBySameUserAreEquivalent() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
    PrivilegedExceptionAction<Void> callable = 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;
        }
    };
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) File(java.io.File) HashSet(java.util.HashSet) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 2 with ConnectionInfo

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

the class SecureUserConnectionsTest method testAlternatingDestructiveLogins.

@Test
public void testAlternatingDestructiveLogins() 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);
    UserGroupInformation.loginUserFromKeytab(princ1, keytab1.getPath());
    // 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);
    UserGroupInformation.loginUserFromKeytab(princ2, keytab2.getPath());
    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
    UserGroupInformation.loginUserFromKeytab(princ1, keytab1.getPath());
    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 3 with ConnectionInfo

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

the class SecureUserConnectionsTest method testMultipleConnectionsAsSameUserWithoutLogin.

@Test
public void testMultipleConnectionsAsSameUserWithoutLogin() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    final String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
    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 4 with ConnectionInfo

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

the class BaseTest method setupTxManager.

protected static void setupTxManager() throws SQLException, IOException {
    ConnectionInfo connInfo = ConnectionInfo.create(getUrl());
    zkClient = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(connInfo.getZookeeperConnectionString()).setSessionTimeout(config.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT)).build(), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
    zkClient.startAndWait();
    DiscoveryService discovery = new ZKDiscoveryService(zkClient);
    txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
    txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
    txService.startAndWait();
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) HDFSTransactionStateStorage(org.apache.tephra.persist.HDFSTransactionStateStorage) TransactionService(org.apache.tephra.distributed.TransactionService) TransactionManager(org.apache.tephra.TransactionManager) TxMetricsCollector(org.apache.tephra.metrics.TxMetricsCollector) ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) DiscoveryService(org.apache.twill.discovery.DiscoveryService) ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) SnapshotCodecProvider(org.apache.tephra.snapshot.SnapshotCodecProvider)

Example 5 with ConnectionInfo

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

the class SecureUserConnectionsTest method testMultipleUniqueUGIInstancesAreDisjoint.

@Test
public void testMultipleUniqueUGIInstancesAreDisjoint() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
    PrivilegedExceptionAction<Void> callable = 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;
        }
    };
    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    // A second, but equivalent, call from the same "real" user but a different UGI instance
    // is expected functionality (programmer error).
    UserGroupInformation ugiCopy = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
    ugiCopy.doAs(callable);
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) File(java.io.File) HashSet(java.util.HashSet) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) 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