Search in sources :

Example 1 with GrpcServer

use of alluxio.grpc.GrpcServer in project alluxio by Alluxio.

the class GrpcSecurityTest method testAuthenticationRevoked.

@Test
public void testAuthenticationRevoked() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    mConfiguration.set(PropertyKey.AUTHENTICATION_INACTIVE_CHANNEL_REAUTHENTICATE_PERIOD, "250ms");
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannel channel = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject()).build();
        Assert.assertTrue(channel.isHealthy());
        /*
       * Sleeping will ensure that authentication sessions for the channel will expire on the
       * server. This should have propagated back to the client and its health status should reflect
       * that.
       *
       * Sleep more than authentication revocation timeout.
       */
        Thread.sleep(500);
        Assert.assertFalse(channel.isHealthy());
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) GrpcServer(alluxio.grpc.GrpcServer) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test)

Example 2 with GrpcServer

use of alluxio.grpc.GrpcServer in project alluxio by Alluxio.

the class GrpcSecurityTest method testSimpleAuthentication.

@Test
public void testSimpleAuthentication() throws Exception {
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject());
        channelBuilder.build();
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Example 3 with GrpcServer

use of alluxio.grpc.GrpcServer in project alluxio by Alluxio.

the class GrpcSecurityTest method testDisabledAuthentication.

@Test
public void testDisabledAuthentication() throws Exception {
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
        channelBuilder.disableAuthentication().build();
    } finally {
        server.shutdown();
    }
}
Also used : GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Example 4 with GrpcServer

use of alluxio.grpc.GrpcServer in project alluxio by Alluxio.

the class GrpcSecurityTest method testCustomAuthentication.

@Test
public void testCustomAuthentication() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName());
    GrpcServer server = createServer(AuthType.CUSTOM);
    try {
        server.start();
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
        channelBuilder.setSubject(createSubject(ExactlyMatchAuthenticationProvider.USERNAME, ExactlyMatchAuthenticationProvider.PASSWORD)).build();
    } finally {
        server.shutdown();
    }
}
Also used : GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Example 5 with GrpcServer

use of alluxio.grpc.GrpcServer in project alluxio by Alluxio.

the class GrpcSecurityTest method testAuthenticationClosed.

@Test
public void testAuthenticationClosed() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannel channel = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject()).build();
        // Grab internal channel-Id.
        GrpcConnection connection = Whitebox.getInternalState(channel, "mConnection");
        UUID channelId = connection.getChannelKey().getChannelId();
        // Assert that authentication server has a login info for the channel.
        Assert.assertNotNull(server.getAuthenticationServer().getUserInfoForChannel(channelId));
        // Shutdown channel.
        channel.shutdown();
        // Assert that authentication server doesn't contain login info for the channel anymore.
        // Wait in a loop. Because closing the authentication will propagate asynchronously.
        CommonUtils.waitFor("login state removed", () -> {
            try {
                server.getAuthenticationServer().getUserInfoForChannel(channelId);
                return false;
            } catch (UnauthenticatedException exc) {
                return true;
            }
        }, WaitForOptions.defaults().setTimeoutMs(S_AUTHENTICATION_PROPOGATE_TIMEOUT));
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) GrpcConnection(alluxio.grpc.GrpcConnection) GrpcServer(alluxio.grpc.GrpcServer) UUID(java.util.UUID) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test)

Aggregations

GrpcServer (alluxio.grpc.GrpcServer)8 Test (org.junit.Test)8 GrpcChannelBuilder (alluxio.grpc.GrpcChannelBuilder)6 UserState (alluxio.security.user.UserState)3 GrpcChannel (alluxio.grpc.GrpcChannel)2 UnauthenticatedException (alluxio.exception.status.UnauthenticatedException)1 GrpcConnection (alluxio.grpc.GrpcConnection)1 UUID (java.util.UUID)1