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);
}
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);
}
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());
}
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();
}
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);
}
Aggregations