Search in sources :

Example 6 with DefaultCredentials

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

the class ClientConfigTest method serializable.

@Test
public void serializable() {
    JavaSerializer<ClientConfig> s = new JavaSerializer<>();
    ClientConfig expected = ClientConfig.builder().credentials(new DefaultCredentials(PASSWORD, USERNAME)).controllerURI(URI.create("tcp://localhost:9090")).trustStore("truststore.jks").validateHostName(false).build();
    ClientConfig actual = s.deserialize(s.serialize(expected));
    assertEquals(expected, actual);
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) Test(org.junit.Test)

Example 7 with DefaultCredentials

use of io.pravega.shared.security.auth.DefaultCredentials 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 8 with DefaultCredentials

use of io.pravega.shared.security.auth.DefaultCredentials 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 9 with DefaultCredentials

use of io.pravega.shared.security.auth.DefaultCredentials 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)

Example 10 with DefaultCredentials

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

the class ReadWithReadPermissionsTest method readsFromADifferentScopeTest.

@Test
public void readsFromADifferentScopeTest() {
    String marketDataWriter = "writer";
    String marketDataReader = "reader";
    String password = "test-password";
    String marketDataScope = "marketdata";
    String computeScope = "compute";
    String stream1 = "stream1";
    final Map<String, String> passwordInputFileEntries = new HashMap<>();
    passwordInputFileEntries.put(marketDataWriter, String.join(";", // Allows user to create the "marketdata" scope, for this test
    "prn::/,READ_UPDATE", // Allows user to create stream (and other scope children)
    "prn::/scope:marketdata,READ_UPDATE", // Provides user all access to child objects of the "marketdata" scope
    "prn::/scope:marketdata/*,READ_UPDATE"));
    passwordInputFileEntries.put(marketDataReader, String.join(";", // Allows use to create the "compute" home scope
    "prn::/,READ_UPDATE", // Allows user to create reader-group under its home scope
    "prn::/scope:compute,READ_UPDATE", // Provides user all access to child objects of the "compute" scope
    "prn::/scope:compute/*,READ_UPDATE", // Provides use read access to the "marketdata/stream1" stream.
    "prn::/scope:marketdata/stream:stream1,READ"));
    // Setup and run the servers
    @Cleanup final ClusterWrapper cluster = ClusterWrapper.builder().authEnabled(true).tokenSigningKeyBasis("secret").tokenTtlInSeconds(600).rgWritesWithReadPermEnabled(false).passwordAuthHandlerEntries(TestUtils.preparePasswordInputFileEntries(passwordInputFileEntries, password)).build();
    cluster.start();
    // Prepare a client config for the `marketDataWriter`, whose home scope is "marketdata"
    final ClientConfig writerClientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials(password, marketDataWriter)).build();
    // Create scope/stream `marketdata/stream1`
    TestUtils.createScopeAndStreams(writerClientConfig, marketDataScope, Arrays.asList(stream1));
    // Write a message to stream `marketdata/stream1`
    TestUtils.writeDataToStream(marketDataScope, stream1, "test message", writerClientConfig);
    // Prepare a client config for `marketDataReader`, whose home scope is "compute"
    ClientConfig readerClientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials(password, marketDataReader)).build();
    // Create scope `compute` (without any streams)
    TestUtils.createScopeAndStreams(readerClientConfig, computeScope, new ArrayList<>());
    // Create a reader group config that enables a user to read data from `marketdata/stream1`
    ReaderGroupConfig readerGroupConfig = ReaderGroupConfig.builder().stream(Stream.of(marketDataScope, stream1)).disableAutomaticCheckpoints().build();
    // Create a reader-group for user `marketDataReader` in `compute` scope, which is its home scope.
    @Cleanup ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(computeScope, readerClientConfig);
    readerGroupManager.createReaderGroup("testRg", readerGroupConfig);
    @Cleanup EventStreamClientFactory readerClientFactory = EventStreamClientFactory.withScope(computeScope, readerClientConfig);
    @Cleanup EventStreamReader<String> reader = readerClientFactory.createReader("readerId", "testRg", new JavaSerializer<String>(), ReaderConfig.builder().initialAllocationDelay(0).build());
    String readMessage = reader.readNextEvent(5000).getEvent();
    assertEquals("test message", readMessage);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) Cleanup(lombok.Cleanup) DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClientConfig(io.pravega.client.ClientConfig) Test(org.junit.Test)

Aggregations

DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)27 ClientConfig (io.pravega.client.ClientConfig)17 Test (org.junit.Test)14 Cleanup (lombok.Cleanup)12 ClusterWrapper (io.pravega.test.integration.demo.ClusterWrapper)9 HashMap (java.util.HashMap)5 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)4 StreamManager (io.pravega.client.admin.StreamManager)4 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)4 Stream (io.pravega.client.stream.Stream)4 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)4 Credentials (io.pravega.shared.security.auth.Credentials)4 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)3 NettyChannelBuilder (io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder)3 AdminCommandState (io.pravega.cli.admin.AdminCommandState)3 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)3 PravegaCredentialsWrapper (io.pravega.client.control.impl.PravegaCredentialsWrapper)3 URI (java.net.URI)3 Properties (java.util.Properties)3 ImmutableMap (com.google.common.collect.ImmutableMap)2