use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class DefaultSecureStoreServiceTest method setup.
@BeforeClass
public static void setup() throws Exception {
SConfiguration sConf = SConfiguration.create();
sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
CConfiguration cConf = createCConf();
final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
waitForService(Constants.Service.DATASET_MANAGER);
secureStore = injector.getInstance(SecureStore.class);
secureStoreManager = injector.getInstance(SecureStoreManager.class);
accessController = injector.getInstance(AccessControllerInstantiator.class).get();
// Wait for the default namespace creation
String user = AuthorizationUtil.getEffectiveMasterUser(cConf);
accessController.grant(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), EnumSet.allOf(StandardPermission.class));
// Starting the Appfabric server will create the default namespace
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return injector.getInstance(NamespaceAdmin.class).exists(NamespaceId.DEFAULT);
}
}, 5, TimeUnit.SECONDS);
accessController.revoke(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), Collections.singleton(StandardPermission.UPDATE));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class ProgramLifecycleServiceAuthorizationTest method setup.
@BeforeClass
public static void setup() throws Exception {
cConf = createCConf();
final Injector injector = AppFabricTestHelper.getInjector(cConf);
accessController = injector.getInstance(AccessControllerInstantiator.class).get();
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
programLifecycleService = injector.getInstance(ProgramLifecycleService.class);
// Wait for the default namespace creation
String user = AuthorizationUtil.getEffectiveMasterUser(cConf);
accessController.grant(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), EnumSet.allOf(StandardPermission.class));
// Starting the Appfabric server will create the default namespace
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return injector.getInstance(NamespaceAdmin.class).exists(NamespaceId.DEFAULT);
}
}, 5, TimeUnit.SECONDS);
accessController.revoke(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), Collections.singleton(StandardPermission.UPDATE));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class DirectRuntimeRequestValidatorTest method testUnauthorized.
@Test(expected = UnauthorizedException.class)
public void testUnauthorized() throws BadRequestException {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").spark("spark").run(RunIds.generate());
RuntimeRequestValidator validator = new DirectRuntimeRequestValidator(cConf, txRunner, new MockProgramRunRecordFetcher(), accessEnforcer, authenticationContext);
Principal principal = new Principal("test", Principal.PrincipalType.USER);
Mockito.when(authenticationContext.getPrincipal()).thenReturn(principal);
Mockito.doThrow(new UnauthorizedException("Unauthorized")).when(accessEnforcer).enforce(programRunId, principal, StandardPermission.GET);
validator.getProgramRunStatus(programRunId, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class GrantPermissionCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Authorizable authorizable = Authorizable.fromString(arguments.get(ArgumentName.ENTITY.toString()));
String principalName = arguments.get("principal-name");
Principal.PrincipalType principalType = Principal.PrincipalType.valueOf(arguments.get("principal-type").toUpperCase());
Principal principal = new Principal(principalName, principalType);
Set<Permission> permissions = PERMISSION_STRING_TO_SET.apply(arguments.get("permissions"));
// permissions is not an optional argument so should never be null
Preconditions.checkNotNull(permissions, "Permissions can never be null in the grant command.");
client.grant(authorizable, principal, permissions);
output.printf("Successfully granted permission(s) '%s' on entity '%s' to %s '%s'\n", Joiner.on(",").join(permissions), authorizable.toString(), principal.getType(), principal.getName());
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class ListPrivilegesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String principalType = arguments.get(ArgumentName.PRINCIPAL_TYPE.toString());
String principalName = arguments.get(ArgumentName.PRINCIPAL_NAME.toString());
Table table = Table.builder().setHeader("Authorizable", "Action").setRows(Lists.newArrayList(client.listGrants(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())))), grantedPermission -> Lists.newArrayList(grantedPermission.getAuthorizable().toString(), grantedPermission.getPermission().name())).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Aggregations