use of org.apache.accumulo.core.rpc.SaslConnectionParams in project accumulo by apache.
the class ThriftTransportKeyTest method testConnectionCaching.
@Test
public void testConnectionCaching() throws IOException, InterruptedException {
UserGroupInformation user1 = UserGroupInformation.createUserForTesting("user1", new String[0]);
final KerberosToken token = EasyMock.createMock(KerberosToken.class);
final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
// The primary is the first component of the principal
final String primary = "accumulo";
clientConf.withSasl(true, primary);
// A first instance of the SASL cnxn params
SaslConnectionParams saslParams1 = user1.doAs(new PrivilegedExceptionAction<SaslConnectionParams>() {
@Override
public SaslConnectionParams run() throws Exception {
return new SaslConnectionParams(clientConf, token);
}
});
// A second instance of what should be the same SaslConnectionParams
SaslConnectionParams saslParams2 = user1.doAs(new PrivilegedExceptionAction<SaslConnectionParams>() {
@Override
public SaslConnectionParams run() throws Exception {
return new SaslConnectionParams(clientConf, token);
}
});
ThriftTransportKey ttk1 = new ThriftTransportKey(HostAndPort.fromParts("localhost", 9997), 1l, null, saslParams1), ttk2 = new ThriftTransportKey(HostAndPort.fromParts("localhost", 9997), 1l, null, saslParams2);
// Should equals() and hashCode() to make sure we don't throw away thrift cnxns
assertEquals(ttk1, ttk2);
assertEquals(ttk1.hashCode(), ttk2.hashCode());
}
use of org.apache.accumulo.core.rpc.SaslConnectionParams in project accumulo by apache.
the class ThriftTransportKeyTest method testSslAndSaslErrors.
@Test(expected = RuntimeException.class)
public void testSslAndSaslErrors() {
ClientContext clientCtx = createMock(ClientContext.class);
SslConnectionParams sslParams = createMock(SslConnectionParams.class);
SaslConnectionParams saslParams = createMock(SaslConnectionParams.class);
expect(clientCtx.getClientSslParams()).andReturn(sslParams).anyTimes();
expect(clientCtx.getSaslParams()).andReturn(saslParams).anyTimes();
// We don't care to verify the sslparam or saslparam mocks
replay(clientCtx);
try {
new ThriftTransportKey(HostAndPort.fromParts("localhost", 9999), 120 * 1000, clientCtx);
} finally {
verify(clientCtx);
}
}
use of org.apache.accumulo.core.rpc.SaslConnectionParams in project accumulo by apache.
the class ThriftTransportKeyTest method testSaslPrincipalIsSignificant.
@Test
public void testSaslPrincipalIsSignificant() throws IOException, InterruptedException {
UserGroupInformation user1 = UserGroupInformation.createUserForTesting("user1", new String[0]);
final KerberosToken token = EasyMock.createMock(KerberosToken.class);
SaslConnectionParams saslParams1 = user1.doAs(new PrivilegedExceptionAction<SaslConnectionParams>() {
@Override
public SaslConnectionParams run() throws Exception {
final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
// The primary is the first component of the principal
final String primary = "accumulo";
clientConf.withSasl(true, primary);
assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
return new SaslConnectionParams(clientConf, token);
}
});
UserGroupInformation user2 = UserGroupInformation.createUserForTesting("user2", new String[0]);
SaslConnectionParams saslParams2 = user2.doAs(new PrivilegedExceptionAction<SaslConnectionParams>() {
@Override
public SaslConnectionParams run() throws Exception {
final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
// The primary is the first component of the principal
final String primary = "accumulo";
clientConf.withSasl(true, primary);
assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
return new SaslConnectionParams(clientConf, token);
}
});
ThriftTransportKey ttk1 = new ThriftTransportKey(HostAndPort.fromParts("localhost", 9997), 1l, null, saslParams1), ttk2 = new ThriftTransportKey(HostAndPort.fromParts("localhost", 9997), 1l, null, saslParams2);
assertNotEquals(ttk1, ttk2);
assertNotEquals(ttk1.hashCode(), ttk2.hashCode());
}
Aggregations