Search in sources :

Example 1 with SaslConnectionParams

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());
}
Also used : KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) SaslConnectionParams(org.apache.accumulo.core.rpc.SaslConnectionParams) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 2 with SaslConnectionParams

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);
    }
}
Also used : SaslConnectionParams(org.apache.accumulo.core.rpc.SaslConnectionParams) SslConnectionParams(org.apache.accumulo.core.rpc.SslConnectionParams) Test(org.junit.Test)

Example 3 with SaslConnectionParams

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());
}
Also used : KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) SaslConnectionParams(org.apache.accumulo.core.rpc.SaslConnectionParams) IOException(java.io.IOException) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

SaslConnectionParams (org.apache.accumulo.core.rpc.SaslConnectionParams)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)2 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 SslConnectionParams (org.apache.accumulo.core.rpc.SslConnectionParams)1