use of io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer in project cdap by caskdata.
the class TetheringServerHandlerTest method setUp.
@Before
public void setUp() throws Exception {
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
cConf.setBoolean(Constants.Tethering.TETHERING_SERVER_ENABLED, true);
cConf.setInt(Constants.Tethering.CONNECTION_TIMEOUT_SECONDS, 1);
List<Permission> tetheringPermissions = Arrays.asList(InstancePermission.TETHER);
InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
inMemoryAccessController.grant(Authorizable.fromEntityId(InstanceId.SELF), MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(tetheringPermissions)));
ContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(new AuthenticationTestContext(), inMemoryAccessController);
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
service = new CommonNettyHttpServiceBuilder(CConfiguration.create(), getClass().getSimpleName()).setHttpHandlers(new TetheringServerHandler(cConf, tetheringStore, messagingService, contextAccessEnforcer), new TetheringHandler(cConf, tetheringStore, messagingService)).build();
service.start();
config = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(service.getBindAddress().getHostName()).setPort(service.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
}
use of io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer in project cdap by caskdata.
the class MonitorHandlerAuthorizationTest method createMonitorHandler.
private static MonitorHandler createMonitorHandler(Authorizable authorizable, List<Permission> requiredPermissions) {
Map<String, MasterServiceManager> masterServiceManagerMap = new HashMap<>();
MasterServiceManager mockMasterServiceManager = mock(MasterServiceManager.class);
when(mockMasterServiceManager.getInstances()).thenReturn(1);
when(mockMasterServiceManager.isServiceEnabled()).thenReturn(true);
when(mockMasterServiceManager.getMinInstances()).thenReturn(1);
when(mockMasterServiceManager.getMaxInstances()).thenReturn(1);
when(mockMasterServiceManager.setInstances(any(Integer.class))).thenReturn(true);
masterServiceManagerMap.put(SERVICE_NAME, mockMasterServiceManager);
ServiceStore mockServiceStore = mock(ServiceStore.class);
InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
inMemoryAccessController.grant(authorizable, MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(requiredPermissions)));
AuthenticationContext authenticationContext = new AuthenticationTestContext();
DefaultContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(authenticationContext, inMemoryAccessController);
return new MonitorHandler(masterServiceManagerMap, mockServiceStore, contextAccessEnforcer);
}
use of io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer in project cdap by caskdata.
the class TetheringClientHandlerTest method setUp.
@Before
public void setUp() throws Exception {
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
CConfiguration conf = CConfiguration.create();
serverHandler = new MockTetheringServerHandler();
serverService = new CommonNettyHttpServiceBuilder(conf, getClass().getSimpleName() + "_server").setHttpHandlers(serverHandler).build();
serverService.start();
serverConfig = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(serverService.getBindAddress().getHostName()).setPort(serverService.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
cConf.setInt(Constants.Tethering.CONNECTION_INTERVAL, 1);
cConf.setInt(Constants.Tethering.CONNECTION_TIMEOUT_SECONDS, 5);
cConf.set(Constants.INSTANCE_NAME, CLIENT_INSTANCE);
List<Permission> tetheringPermissions = Arrays.asList(InstancePermission.TETHER);
InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
inMemoryAccessController.grant(Authorizable.fromEntityId(InstanceId.SELF), MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(tetheringPermissions)));
ContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(new AuthenticationTestContext(), inMemoryAccessController);
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
MessagingService messagingService = injector.getInstance(MessagingService.class);
clientService = new CommonNettyHttpServiceBuilder(conf, getClass().getSimpleName() + "_client").setHttpHandlers(new TetheringClientHandler(tetheringStore, contextAccessEnforcer), new TetheringHandler(cConf, tetheringStore, messagingService)).build();
clientService.start();
clientConfig = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(clientService.getBindAddress().getHostName()).setPort(clientService.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
tetheringAgentService = new TetheringAgentService(cConf, injector.getInstance(TransactionRunner.class), tetheringStore, injector.getInstance(MessagingService.class), injector.getInstance(RemoteAuthenticator.class));
Assert.assertEquals(Service.State.RUNNING, tetheringAgentService.startAndWait());
}
Aggregations