use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class KyloRestLoginModuleTest method test.
/**
* Verify logging in by querying a REST API.
*/
@Test
public void test() throws Exception {
// Mock REST client
final User user = new User();
user.setEnabled(true);
user.setGroups(ImmutableSet.of("designers", "operators"));
user.setSystemName("dladmin");
final JerseyRestClient client = Mockito.mock(JerseyRestClient.class);
Mockito.when(client.get(any(Invocation.Builder.class), eq(User.class))).thenReturn(user);
// Mock callback handler
final CallbackHandler callbackHandler = callbacks -> Arrays.stream(callbacks).forEach(callback -> {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName("dladmin");
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword("thinkbig".toCharArray());
}
});
// Mock login module
final KyloRestLoginModule module = new KyloRestLoginModule() {
@Nonnull
@Override
JerseyRestClient getClient(@Nonnull LoginJerseyClientConfig config) {
return client;
}
};
// Test login
final Subject subject = new Subject();
Map<String, Object> options = new HashMap<>();
options.put(KyloRestLoginModule.REST_CLIENT_CONFIG, new LoginJerseyClientConfig());
options.put(KyloRestLoginModule.SERVICES_LOGOUT, false);
module.initialize(subject, callbackHandler, Collections.emptyMap(), options);
Assert.assertTrue(module.login());
Assert.assertTrue(module.commit());
// Verify subject
final Principal[] principals = subject.getPrincipals().toArray(new Principal[0]);
Assert.assertEquals(3, principals.length);
Arrays.sort(principals, Comparator.comparing(Principal::getName));
Assert.assertEquals("designers", principals[0].getName());
Assert.assertEquals("dladmin", principals[1].getName());
Assert.assertEquals("operators", principals[2].getName());
}
use of com.thinkbiganalytics.rest.JerseyRestClient in project kylo by Teradata.
the class JerseySparkShellRestClient method getClient.
/**
* Gets or creates a Jersey REST client for the specified Spark Shell process.
*
* @param process the Spark Shell process
* @return the Jersey REST client
*/
@Nonnull
private JerseyRestClient getClient(@Nonnull final SparkShellProcess process) {
return clients.computeIfAbsent(process, target -> {
final JerseyClientConfig config = new JerseyClientConfig();
config.setHost(target.getHostname());
config.setPort(target.getPort());
return new JerseyRestClient(config);
});
}
Aggregations