Search in sources :

Example 1 with Credentials

use of io.pravega.shared.security.auth.Credentials in project pravega by pravega.

the class ControllerImpl method getClientWithCredentials.

private ControllerServiceStub getClientWithCredentials(ControllerImplConfig config) {
    ControllerServiceStub client = ControllerServiceGrpc.newStub(this.channel);
    try {
        Credentials credentials = config.getClientConfig().getCredentials();
        if (credentials != null) {
            PravegaCredentialsWrapper wrapper = new PravegaCredentialsWrapper(credentials);
            client = client.withCallCredentials(MoreCallCredentials.from(wrapper));
        }
    } catch (Exception e) {
        log.error("Error while setting credentials to controller client", e);
        closeChannel();
        throw e;
    }
    return client;
}
Also used : ControllerServiceStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceStub) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) Credentials(io.pravega.shared.security.auth.Credentials) NoSuchScopeException(io.pravega.client.stream.NoSuchScopeException) SSLException(javax.net.ssl.SSLException) PingFailedException(io.pravega.client.stream.PingFailedException) StatusRuntimeException(io.grpc.StatusRuntimeException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) CompletionException(java.util.concurrent.CompletionException) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 2 with Credentials

use of io.pravega.shared.security.auth.Credentials in project pravega by pravega.

the class CredentialsExtractorTest method testLoadsCredentialsObjOfARegisteredTypeFromPropertiesIfLoadDynamicIsTrue.

@Test
public void testLoadsCredentialsObjOfARegisteredTypeFromPropertiesIfLoadDynamicIsTrue() {
    Properties properties = new Properties();
    properties.setProperty("pravega.client.auth.loadDynamic", "true");
    properties.setProperty("pravega.client.auth.method", "Bearer");
    ClientConfig clientConfig = ClientConfig.builder().extractCredentials(properties, null).build();
    Credentials credentials = clientConfig.getCredentials();
    assertNotNull("Credentials is null", credentials);
    assertNotNull(DynamicallyLoadedCreds.class.getName(), credentials.getClass());
    assertEquals("Expected a different authentication type", "Bearer", credentials.getAuthenticationType());
}
Also used : Properties(java.util.Properties) Credentials(io.pravega.shared.security.auth.Credentials) Test(org.junit.Test)

Example 3 with Credentials

use of io.pravega.shared.security.auth.Credentials in project pravega by pravega.

the class CredentialsExtractorTest method testLoadsLegacyCredentialsUsingNewInterfacePackage.

/**
 * The intent of this test is to verify whether an existing Credentials implementation works if the
 * service definition is made using the new interface: `META-INF/services/io.pravega.shared.security.auth.Credentials`.
 * In effect, it verifies that the existing plugin works with a modified service definition based on the new
 * interface.
 */
@Test
public void testLoadsLegacyCredentialsUsingNewInterfacePackage() {
    Map<String, String> authEnvVariables = new HashMap<>();
    authEnvVariables.put("pravega_client_auth_loadDynamic", "true");
    authEnvVariables.put("pravega_client_auth_method", LegacyCredentials1.AUTHENTICATION_METHOD);
    ClientConfig clientConfig = ClientConfig.builder().extractCredentials(null, authEnvVariables).build();
    Credentials credentials = clientConfig.getCredentials();
    assertNotNull("Credentials is null", credentials);
    assertNotNull(LegacyCredentials1.class.getName(), credentials.getClass());
    assertEquals("Expected a different authentication type", LegacyCredentials1.AUTHENTICATION_METHOD, credentials.getAuthenticationType());
}
Also used : HashMap(java.util.HashMap) Credentials(io.pravega.shared.security.auth.Credentials) Test(org.junit.Test)

Example 4 with Credentials

use of io.pravega.shared.security.auth.Credentials in project pravega by pravega.

the class CredentialsExtractorTest method testExtractsCredentialsFromEnvVariables.

@Test
public void testExtractsCredentialsFromEnvVariables() {
    Map<String, String> authEnvVariables = new HashMap<>();
    authEnvVariables.put("pravega_client_auth_method", "amethod");
    authEnvVariables.put("pravega_client_auth_token", "atoken");
    ClientConfig clientConfig = ClientConfig.builder().extractCredentials(null, authEnvVariables).build();
    Credentials credentials = clientConfig.getCredentials();
    assertNotNull(credentials);
    assertNotNull("io.pravega.client.ClientConfig$ClientConfigBuilder$1", credentials.getClass());
    assertEquals("amethod", credentials.getAuthenticationType());
    assertEquals("atoken", credentials.getAuthenticationToken());
}
Also used : HashMap(java.util.HashMap) Credentials(io.pravega.shared.security.auth.Credentials) Test(org.junit.Test)

Example 5 with Credentials

use of io.pravega.shared.security.auth.Credentials in project pravega by pravega.

the class CredentialsExtractorTest method testExplicitlySpecifiedCredentialsAreNotOverridden.

@Test
public void testExplicitlySpecifiedCredentialsAreNotOverridden() {
    Properties properties = new Properties();
    properties.setProperty("pravega.client.auth.method", "amethod");
    properties.setProperty("pravega.client.auth.token", "atoken");
    Map<String, String> authEnvVariables = new HashMap<>();
    authEnvVariables.put("pravega_client_auth_method", "amethod");
    authEnvVariables.put("pravega_client_auth_token", "atoken");
    ClientConfig clientConfig = ClientConfig.builder().credentials(new Credentials() {

        @Override
        public String getAuthenticationType() {
            return "typeSpecifiedViaExplicitObject";
        }

        @Override
        public String getAuthenticationToken() {
            return "tokenSpecifiedViaExplicitObject";
        }
    }).extractCredentials(properties, authEnvVariables).build();
    assertEquals("Explicitly set credentials should not be overridden", "typeSpecifiedViaExplicitObject", clientConfig.getCredentials().getAuthenticationType());
    assertEquals("Explicitly set credentials should not be overridden", "tokenSpecifiedViaExplicitObject", clientConfig.getCredentials().getAuthenticationToken());
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) Credentials(io.pravega.shared.security.auth.Credentials) Test(org.junit.Test)

Aggregations

Credentials (io.pravega.shared.security.auth.Credentials)14 Test (org.junit.Test)9 HashMap (java.util.HashMap)6 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)4 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)4 Properties (java.util.Properties)4 PravegaCredentialsWrapper (io.pravega.client.control.impl.PravegaCredentialsWrapper)3 ControllerServiceBlockingStub (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub)2 ControllerServiceStub (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceStub)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)1 NoSuchScopeException (io.pravega.client.stream.NoSuchScopeException)1 PingFailedException (io.pravega.client.stream.PingFailedException)1 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)1 TxnFailedException (io.pravega.client.stream.TxnFailedException)1 ControllerServiceGrpc (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc)1 CompletionException (java.util.concurrent.CompletionException)1 SSLException (javax.net.ssl.SSLException)1