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