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);
}
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;
}
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;
}
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");
}
}
}
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);
}
Aggregations