use of io.hops.hopsworks.persistence.entity.kafka.TopicAcls in project hopsworks by logicalclocks.
the class KafkaController method removeAclFromTopic.
public void removeAclFromTopic(String topicName, Integer aclId) throws KafkaException {
TopicAcls ta = topicAclsFacade.find(aclId);
if (ta == null) {
throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_NOT_FOUND, Level.FINE, "topic: " + topicName);
}
if (!ta.getProjectTopics().getTopicName().equals(topicName)) {
throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_NOT_FOR_TOPIC, Level.FINE, "topic: " + topicName);
}
topicAclsFacade.remove(ta);
}
use of io.hops.hopsworks.persistence.entity.kafka.TopicAcls in project hopsworks by logicalclocks.
the class KafkaController method addAclsToTopic.
private Pair<TopicAcls, Response.Status> addAclsToTopic(String topicName, Integer projectId, String selectedProjectName, String userEmail, String permissionType, String operationType, String host, String role) throws ProjectException, KafkaException, UserException {
if (Strings.isNullOrEmpty(topicName) || userEmail == null) {
throw new IllegalArgumentException("Topic and userEmail must be provided.");
}
// get the project id
Project topicOwnerProject = Optional.ofNullable(projectFacade.find(projectId)).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + projectId));
if (!topicOwnerProject.getName().equals(selectedProjectName)) {
if (projectFacade.findByName(selectedProjectName) == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "The specified project " + "for the topic" + topicName + " was not found");
}
}
ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(topicOwnerProject, topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "Topic: " + topicName));
// should not be able to create multiple ACLs at the same time
if (userEmail.equals("*")) {
throw new KafkaException(RESTCodes.KafkaErrorCode.ACL_FOR_ANY_USER, Level.FINE, "topic: " + topicName);
}
// fetch the user name from database
Users user = Optional.ofNullable(userFacade.findByEmail(userEmail)).orElseThrow(() -> new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE, "user: " + userEmail));
String principalName = KafkaConst.buildPrincipalName(selectedProjectName, user.getUsername());
Optional<TopicAcls> optionalAcl = topicAclsFacade.getTopicAcls(topicName, principalName, permissionType, operationType, host, role);
if (optionalAcl.isPresent()) {
return Pair.of(optionalAcl.get(), Response.Status.OK);
}
TopicAcls acl = topicAclsFacade.addAclsToTopic(pt, user, permissionType, operationType, host, role, principalName);
return Pair.of(acl, Response.Status.CREATED);
}
use of io.hops.hopsworks.persistence.entity.kafka.TopicAcls in project hopsworks by logicalclocks.
the class TopicAclsFacade method addAclsToTopic.
public TopicAcls addAclsToTopic(ProjectTopics pt, Users user, String permissionType, String operationType, String host, String role, String principalName) {
TopicAcls ta = new TopicAcls(pt, user, permissionType, operationType, host, role, principalName);
save(ta);
em.flush();
return ta;
}
use of io.hops.hopsworks.persistence.entity.kafka.TopicAcls in project hopsworks by logicalclocks.
the class KafkaResource method addAclsToTopic.
@ApiOperation(value = "Add a new ACL for a specified topic.")
@POST
@Path("/topics/{topic}/acls")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response addAclsToTopic(@Context UriInfo uriInfo, @PathParam("topic") String topicName, AclDTO aclDto, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
Pair<TopicAcls, Response.Status> aclTuple = kafkaController.addAclsToTopic(topicName, project.getId(), aclDto);
AclDTO dto = aclBuilder.build(uriInfo, aclTuple.getLeft());
return Response.status(aclTuple.getRight()).entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.kafka.TopicAcls in project hopsworks by logicalclocks.
the class AclBuilder method getAclByTopicAndId.
public AclDTO getAclByTopicAndId(UriInfo uriInfo, Project project, String topicName, Integer aclId) throws KafkaException {
AclDTO dto = new AclDTO();
URI uri = getAclUri(uriInfo, project, topicName, aclId).build();
dto.setHref(uri);
Optional<TopicAcls> aclsOptional = kafkaController.findAclByIdAndTopic(topicName, aclId);
if (aclsOptional.isPresent()) {
TopicAcls acl = aclsOptional.get();
dto.setId(acl.getId());
dto.setProjectName(KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()));
dto.setUserEmail(acl.getUser().getEmail());
dto.setPermissionType(acl.getPermissionType());
dto.setOperationType(acl.getOperationType());
dto.setHost(acl.getHost());
dto.setRole(acl.getRole());
}
return dto;
}
Aggregations