use of com.hortonworks.streamline.streams.security.catalog.AclEntry in project streamline by hortonworks.
the class SecurityCatalogService method getAcl.
public AclEntry getAcl(Long aclEntryId) {
AclEntry aclEntry = new AclEntry();
aclEntry.setId(aclEntryId);
return this.dao.get(new StorableKey(AclEntry.NAMESPACE, aclEntry.getPrimaryKey()));
}
use of com.hortonworks.streamline.streams.security.catalog.AclEntry in project streamline by hortonworks.
the class SecurityCatalogServiceTest method checkUserPermissions.
@Test
public void checkUserPermissions() throws Exception {
SecurityCatalogService catalogService = new SecurityCatalogService(null);
AclEntry userAclEntry = new AclEntry();
userAclEntry.setSidType(AclEntry.SidType.USER);
userAclEntry.setSidId(1L);
userAclEntry.setObjectId(1L);
userAclEntry.setObjectNamespace("topology");
userAclEntry.setPermissions(EnumSet.of(Permission.WRITE));
AclEntry roleAclEntry = new AclEntry();
roleAclEntry.setSidType(AclEntry.SidType.ROLE);
roleAclEntry.setSidId(1L);
roleAclEntry.setObjectId(1L);
roleAclEntry.setObjectNamespace("topology");
roleAclEntry.setPermissions(EnumSet.of(Permission.READ));
Role role = new Role();
role.setId(1L);
role.setName("ROLE_FOO");
List<QueryParam> qps1 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, USER.toString(), AclEntry.SID_ID, "1");
List<QueryParam> qps2 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
User user = new User();
user.setRoles(Sets.newHashSet("ROLE_FOO"));
new Expectations(catalogService) {
{
catalogService.getUser(anyLong);
result = user;
catalogService.listAcls(qps1);
result = Arrays.asList(userAclEntry);
catalogService.getAllUserRoles(user);
result = Sets.newHashSet(role);
catalogService.listAcls(qps2);
result = Arrays.asList(roleAclEntry);
catalogService.getRole(1L);
result = role;
}
};
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.READ)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.READ)));
assertFalse(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.DELETE)));
}
use of com.hortonworks.streamline.streams.security.catalog.AclEntry in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method addAcl.
@Override
public void addAcl(AuthenticationContext ctx, String targetEntityNamespace, Long targetEntityId, boolean owner, boolean grant, EnumSet<Permission> permissions) {
validateAuthenticationContext(ctx);
String userName = SecurityUtil.getUserName(ctx);
User user = catalogService.getUser(userName);
if (user == null || user.getId() == null) {
String msg = String.format("No such user '%s'", userName);
LOG.warn(msg);
throw new AuthorizationException(msg);
}
AclEntry aclEntry = new AclEntry();
aclEntry.setObjectId(targetEntityId);
aclEntry.setObjectNamespace(targetEntityNamespace);
aclEntry.setSidId(user.getId());
aclEntry.setSidType(AclEntry.SidType.USER);
aclEntry.setOwner(owner);
aclEntry.setGrant(grant);
aclEntry.setPermissions(permissions);
catalogService.addAcl(aclEntry);
}
use of com.hortonworks.streamline.streams.security.catalog.AclEntry in project streamline by hortonworks.
the class SecurityCatalogResource method addOrUpdateAcl.
@PUT
@Path("/acls/{id}")
@Timed
public Response addOrUpdateAcl(@PathParam("id") Long aclId, AclEntry aclEntry, @Context SecurityContext securityContext) {
mayBeFillSidId(aclEntry);
checkAclOp(aclEntry, securityContext, this::shouldAllowAclAddOrUpdate);
AclEntry newAclEntry = catalogService.addOrUpdateAcl(aclId, aclEntry);
return WSUtils.respondEntity(newAclEntry, OK);
}
use of com.hortonworks.streamline.streams.security.catalog.AclEntry in project streamline by hortonworks.
the class SecurityCatalogResource method addAcl.
@POST
@Path("/acls")
@Timed
public Response addAcl(AclEntry aclEntry, @Context SecurityContext securityContext) {
mayBeFillSidId(aclEntry);
checkAclOp(aclEntry, securityContext, this::shouldAllowAclAddOrUpdate);
AclEntry createdAcl = catalogService.addAcl(aclEntry);
return WSUtils.respondEntity(createdAcl, CREATED);
}
Aggregations