use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.
the class ArtifactLocalizerServiceTest method setupArtifactLocalizerService.
private ArtifactLocalizerService setupArtifactLocalizerService(CConfiguration cConf) {
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
ArtifactLocalizerService artifactLocalizerService = new ArtifactLocalizerService(cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
}));
// start the service
artifactLocalizerService.startAndWait();
return artifactLocalizerService;
}
use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.
the class OAuthMacroEvaluatorTest method init.
@BeforeClass
public static void init() throws Exception {
httpService = NettyHttpService.builder("OAuthTest").setHttpHandlers(new OAuthHandler(ImmutableMap.of(PROVIDER, ImmutableMap.of(CREDENTIAL_ID, new OAuthInfo("accessToken", "bearer"))))).build();
httpService.start();
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
String discoveryName = ServiceDiscoverable.getName(NamespaceId.SYSTEM.getNamespace(), Constants.PIPELINEID, ProgramType.SERVICE, Constants.STUDIO_SERVICE_NAME);
discoveryService.register(new Discoverable(discoveryName, httpService.getBindAddress()));
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
serviceDiscoverer = new AbstractServiceDiscoverer(NamespaceId.DEFAULT.app("testapp").spark("testspark")) {
@Override
protected RemoteClientFactory getRemoteClientFactory() {
return remoteClientFactory;
}
};
}
use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.
the class DefaultMasterEnvironmentRunnableContextTest method setup.
@BeforeClass
public static void setup() throws Exception {
DiscoveryService discoveryService = new InMemoryDiscoveryService();
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
RemoteClientFactory remoteClientFactory = new RemoteClientFactory((DiscoveryServiceClient) discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
context = new DefaultMasterEnvironmentRunnableContext(locationFactory, remoteClientFactory);
httpService = NettyHttpService.builder(Constants.Service.APP_FABRIC_HTTP).setHttpHandlers(new MockHttpHandler()).build();
httpService.start();
cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService)));
}
use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.
the class RemoteConfiguratorTest method init.
@BeforeClass
public static void init() throws Exception {
cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 0);
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
MasterEnvironments.setMasterEnvironment(new TestMasterEnvironment(discoveryService));
NamespaceAdmin namespaceAdmin = new InMemoryNamespaceAdmin();
namespaceAdmin.create(NamespaceMeta.SYSTEM);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
}, new NoOpMetricsCollectionService()), new ArtifactHttpHandlerInternal(new TestArtifactRepository(cConf), namespaceAdmin), new ArtifactLocalizerHttpHandlerInternal(new ArtifactLocalizer(cConf, remoteClientFactory, ((namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
})))).setPort(cConf.getInt(Constants.ArtifactLocalizer.PORT)).setChannelPipelineModifier(new ChannelPipelineModifier() {
@Override
public void modify(ChannelPipeline pipeline) {
pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
}
}).build();
httpService.start();
discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
discoveryService.register(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService));
metricsCollectionService = new NoOpMetricsCollectionService();
}
use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.
the class UGIProviderTest method testRemoteUGIProvider.
@Test
public void testRemoteUGIProvider() throws Exception {
// Starts a mock server to handle remote UGI requests
final NettyHttpService httpService = NettyHttpService.builder("remoteUGITest").setHttpHandlers(new UGIProviderTestHandler()).build();
httpService.start();
setKeytabDir(localKeytabDirPath.getAbsolutePath());
OwnerAdmin ownerAdmin = getOwnerAdmin();
// add an owner for stream
ownerAdmin.add(aliceEntity, aliceKerberosPrincipalId);
try {
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
RemoteUGIProvider ugiProvider = new RemoteUGIProvider(cConf, locationFactory, ownerAdmin, remoteClientFactory);
ImpersonationRequest aliceImpRequest = new ImpersonationRequest(aliceEntity, ImpersonatedOpType.OTHER);
UGIWithPrincipal aliceUGIWithPrincipal = ugiProvider.getConfiguredUGI(aliceImpRequest);
// Shouldn't be a kerberos UGI
Assert.assertFalse(aliceUGIWithPrincipal.getUGI().hasKerberosCredentials());
// Validate the credentials
Token<? extends TokenIdentifier> token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("entity"));
Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
Assert.assertEquals(new Text("entity"), token.getKind());
Assert.assertEquals(new Text("service"), token.getService());
token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("opType"));
Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
Assert.assertEquals(new Text("opType"), token.getKind());
Assert.assertEquals(new Text("service"), token.getService());
// Fetch it again, it should return the same UGI due to caching
Assert.assertSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
// Invalid the cache and fetch it again. A different UGI should be returned
ugiProvider.invalidCache();
Assert.assertNotSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
} finally {
httpService.stop();
}
// cleanup
ownerAdmin.delete(aliceEntity);
}
Aggregations