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