Search in sources :

Example 6 with Credentials

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

the class CredentialsExtractorTest method testLoadsCredentialsObjOfARegisteredTypeFromEnvVariablesIfLoadDynamicIsTrue.

@Test
public void testLoadsCredentialsObjOfARegisteredTypeFromEnvVariablesIfLoadDynamicIsTrue() {
    Map<String, String> authEnvVariables = new HashMap<>();
    authEnvVariables.put("pravega_client_auth_loadDynamic", "true");
    authEnvVariables.put("pravega_client_auth_method", "Bearer");
    ClientConfig clientConfig = ClientConfig.builder().extractCredentials(null, authEnvVariables).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 : HashMap(java.util.HashMap) Credentials(io.pravega.shared.security.auth.Credentials) Test(org.junit.Test)

Example 7 with Credentials

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

the class CredentialsExtractorTest method testLoadsLegacyCredentialsUsingOldInterfacePackage.

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

Example 8 with Credentials

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

the class ControllerGrpcAuthFocusedTest method prepareBlockingCallStubStrict.

private ControllerServiceBlockingStub prepareBlockingCallStubStrict(String username, String password) {
    Exceptions.checkNotNullOrEmpty(username, "username");
    Exceptions.checkNotNullOrEmpty(password, "password");
    ControllerServiceBlockingStub stub = ControllerServiceGrpc.newBlockingStub(inProcessChannelStrict);
    // Set call credentials
    Credentials credentials = new DefaultCredentials(password, username);
    if (credentials != null) {
        PravegaCredentialsWrapper wrapper = new PravegaCredentialsWrapper(credentials);
        stub = stub.withCallCredentials(MoreCallCredentials.from(wrapper));
    }
    return stub;
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) PravegaCredentialsWrapper(io.pravega.client.control.impl.PravegaCredentialsWrapper) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) Credentials(io.pravega.shared.security.auth.Credentials)

Example 9 with Credentials

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

the class ControllerGrpcAuthFocusedTest method prepareBlockingCallStub.

private ControllerServiceBlockingStub prepareBlockingCallStub(String username, String password) {
    Exceptions.checkNotNullOrEmpty(username, "username");
    Exceptions.checkNotNullOrEmpty(password, "password");
    ControllerServiceBlockingStub stub = ControllerServiceGrpc.newBlockingStub(inProcessChannel);
    // Set call credentials
    Credentials credentials = new DefaultCredentials(password, username);
    if (credentials != null) {
        PravegaCredentialsWrapper wrapper = new PravegaCredentialsWrapper(credentials);
        stub = stub.withCallCredentials(MoreCallCredentials.from(wrapper));
    }
    return stub;
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) PravegaCredentialsWrapper(io.pravega.client.control.impl.PravegaCredentialsWrapper) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) Credentials(io.pravega.shared.security.auth.Credentials)

Example 10 with Credentials

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

the class InProcPravegaCluster method setAuthSystemProperties.

private void setAuthSystemProperties() {
    if (authPropertiesAlreadySet()) {
        log.debug("Auth params already specified via system properties or environment variables.");
    } else {
        if (!Strings.isNullOrEmpty(this.userName)) {
            Credentials credentials = new DefaultCredentials(this.passwd, this.userName);
            System.setProperty("pravega.client.auth.loadDynamic", "false");
            System.setProperty("pravega.client.auth.method", credentials.getAuthenticationType());
            System.setProperty("pravega.client.auth.token", credentials.getAuthenticationToken());
            log.debug("Done setting auth params via system properties.");
        } else {
            log.debug("Cannot set auth params as username is null or empty");
        }
    }
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) Credentials(io.pravega.shared.security.auth.Credentials)

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