use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method getOrCreateEmailSubscriptionEndpoint.
@POST
@Path("/system/email_subscription")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
@Transactional
public Endpoint getOrCreateEmailSubscriptionEndpoint(@Context SecurityContext sec, @NotNull @Valid RequestEmailSubscriptionProperties requestProps) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
if (requestProps.getGroupId() != null && requestProps.isOnlyAdmins()) {
throw new BadRequestException(String.format("Cannot use RBAC groups and only admins in the same endpoint"));
}
if (requestProps.getGroupId() != null) {
boolean isValid = rbacGroupValidator.validate(requestProps.getGroupId(), principal.getIdentity().rawIdentity);
if (!isValid) {
throw new BadRequestException(String.format("Invalid RBAC group identified with id %s", requestProps.getGroupId()));
}
}
// Prevent from creating not public facing properties
EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
properties.setOnlyAdmins(requestProps.isOnlyAdmins());
properties.setGroupId(requestProps.getGroupId());
return endpointRepository.getOrCreateEmailSubscriptionEndpoint(principal.getAccount(), properties);
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method getEndpoint.
@GET
@Path("/{id}")
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
public Endpoint getEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
Endpoint endpoint = endpointRepository.getEndpoint(principal.getAccount(), id);
if (endpoint == null) {
throw new NotFoundException();
} else {
return endpoint;
}
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method getDetailedEndpointHistory.
@GET
@Path("/{id}/history/{history_id}/details")
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
public Response getDetailedEndpointHistory(@Context SecurityContext sec, @PathParam("id") UUID endpointId, @PathParam("history_id") UUID historyId) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
JsonObject json = notificationRepository.getNotificationDetails(principal.getAccount(), endpointId, historyId);
if (json == null) {
// Maybe 404 should only be returned if history_id matches nothing? Otherwise 204
throw new NotFoundException();
} else {
if (json.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(json).build();
}
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method getEndpoints.
@GET
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
@Parameters({ @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page. If the value is 0, it will return all elements", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "pageNumber", in = ParameterIn.QUERY, description = "Page number. Starts at first page (0), if not specified starts at first page.", schema = @Schema(type = SchemaType.INTEGER)) })
public EndpointPage getEndpoints(@Context SecurityContext sec, @BeanParam Query query, @QueryParam("type") List<String> targetType, @QueryParam("active") Boolean activeOnly, @QueryParam("name") String name) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
List<Endpoint> endpoints;
Long count;
if (targetType != null && targetType.size() > 0) {
Set<CompositeEndpointType> compositeType = targetType.stream().map(s -> {
try {
return CompositeEndpointType.fromString(s);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unknown endpoint type: [" + s + "]", e);
}
}).collect(Collectors.toSet());
endpoints = endpointRepository.getEndpointsPerCompositeType(principal.getAccount(), name, compositeType, activeOnly, query);
count = endpointRepository.getEndpointsCountPerCompositeType(principal.getAccount(), name, compositeType, activeOnly);
} else {
endpoints = endpointRepository.getEndpoints(principal.getAccount(), name, query);
count = endpointRepository.getEndpointsCount(principal.getAccount(), name);
}
return new EndpointPage(endpoints, new HashMap<>(), new Meta(count));
}
use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.
the class EndpointResource method createEndpoint.
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@Transactional
public Endpoint createEndpoint(@Context SecurityContext sec, @NotNull @Valid Endpoint endpoint) {
checkSystemEndpoint(endpoint.getType());
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
endpoint.setAccountId(principal.getAccount());
if (endpoint.getProperties() == null) {
throw new BadRequestException("Properties is required");
}
if (obEnabled) {
// TODO NOTIF-429 - see similar in EndpointResources#createEndpoint
String endpointSubType;
if (endpoint.getSubType() != null) {
endpointSubType = endpoint.getSubType();
} else {
if (endpoint.getType() == EndpointType.CAMEL) {
endpointSubType = endpoint.getProperties(CamelProperties.class).getSubType();
} else {
// No Camel endpoint, so we can skip
endpointSubType = "not-defined";
}
}
if (endpointSubType != null && endpointSubType.equals("slack")) {
CamelProperties properties = endpoint.getProperties(CamelProperties.class);
String processorName = "p-" + endpoint.getAccountId() + "-" + UUID.randomUUID();
properties.getExtras().put(OB_PROCESSOR_NAME, processorName);
String processorId = null;
try {
processorId = setupOpenBridgeProcessor(endpoint, properties, processorName);
} catch (Exception e) {
LOGGER.warn("Processor setup failed: " + e.getMessage());
throw new InternalServerErrorException("Can't set up the endpoint");
}
// TODO find a better place for these, that should not be
// visible to users / OB actions
// See also CamelTypeProcessor#callOpenBridge
properties.getExtras().put(OB_PROCESSOR_ID, processorId);
}
}
return endpointRepository.createEndpoint(endpoint);
}
Aggregations