Search in sources :

Example 1 with RhIdPrincipal

use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.

the class UserConfigResource method getSettingsSchema.

@GET
@Path("/notification-preference")
@Produces(APPLICATION_JSON)
@Operation(hidden = true)
public Response getSettingsSchema(@Context SecurityContext sec, @QueryParam("bundleName") String bundleName) {
    final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
    final String account = principal.getAccount();
    final String name = principal.getName();
    SettingsValues settingsValues = getSettingsValueForUser(account, name, bundleName);
    String jsonFormString = settingsValuesToJsonForm(settingsValues);
    Response.ResponseBuilder builder;
    builder = Response.ok(jsonFormString);
    EntityTag etag = new EntityTag(String.valueOf(jsonFormString.hashCode()));
    builder.header("ETag", etag);
    return builder.build();
}
Also used : Response(javax.ws.rs.core.Response) SettingsValues(com.redhat.cloud.notifications.routers.models.SettingsValues) RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) EntityTag(javax.ws.rs.core.EntityTag) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 2 with RhIdPrincipal

use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.

the class UserConfigResource method getPreferences.

@GET
@Path("/notification-preference/{bundleName}/{applicationName}")
@Produces(APPLICATION_JSON)
@Operation(hidden = true)
public UserConfigPreferences getPreferences(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName) {
    final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
    final String account = principal.getAccount();
    final String name = principal.getName();
    final UserConfigPreferences preferences = new UserConfigPreferences();
    // TODO Get the DAILY and INSTANT subscriptions with a single SQL query and return UserConfigPreferences directly from Hibernate.
    EmailSubscription daily = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.DAILY);
    preferences.setDailyEmail(daily != null);
    EmailSubscription instant = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.INSTANT);
    preferences.setInstantEmail(instant != null);
    return preferences;
}
Also used : RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) UserConfigPreferences(com.redhat.cloud.notifications.routers.models.UserConfigPreferences) EmailSubscription(com.redhat.cloud.notifications.models.EmailSubscription) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 3 with RhIdPrincipal

use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.

the class EndpointResource method getEndpointHistory.

@GET
@Path("/{id}/history")
@Produces(APPLICATION_JSON)
@Parameters({ @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page, if not specified or 0 is used, returns a maximum of " + MAX_NOTIFICATION_HISTORY_RESULTS + " 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)), @Parameter(name = "includeDetail", description = "Include the detail in the reply", schema = @Schema(type = SchemaType.BOOLEAN)) })
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
public List<NotificationHistory> getEndpointHistory(@Context SecurityContext sec, @PathParam("id") UUID id, @QueryParam("includeDetail") Boolean includeDetail, @BeanParam Query query) {
    // TODO We need globally limitations (Paging support and limits etc)
    RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
    boolean doDetail = includeDetail != null && includeDetail;
    return notificationRepository.getNotificationHistory(principal.getAccount(), id, doDetail, query);
}
Also used : RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with RhIdPrincipal

use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.

the class EndpointResource method disableEndpoint.

@DELETE
@Path("/{id}/enable")
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "204", description = "The integration has been disabled", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response disableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
    RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
    EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
    checkSystemEndpoint(endpointType);
    endpointRepository.disableEndpoint(principal.getAccount(), id);
    return Response.noContent().build();
}
Also used : RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) EndpointType(com.redhat.cloud.notifications.models.EndpointType) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Transactional(javax.transaction.Transactional)

Example 5 with RhIdPrincipal

use of com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal in project notifications-backend by RedHatInsights.

the class EndpointResource method enableEndpoint.

@PUT
@Path("/{id}/enable")
@Produces(TEXT_PLAIN)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response enableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
    RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
    EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
    checkSystemEndpoint(endpointType);
    endpointRepository.enableEndpoint(principal.getAccount(), id);
    return Response.ok().build();
}
Also used : RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) EndpointType(com.redhat.cloud.notifications.models.EndpointType) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) Transactional(javax.transaction.Transactional)

Aggregations

RhIdPrincipal (com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)13 RolesAllowed (javax.annotation.security.RolesAllowed)12 Transactional (javax.transaction.Transactional)10 GET (javax.ws.rs.GET)7 NotFoundException (javax.ws.rs.NotFoundException)7 APIResponse (org.eclipse.microprofile.openapi.annotations.responses.APIResponse)6 CompositeEndpointType (com.redhat.cloud.notifications.models.CompositeEndpointType)5 EndpointType (com.redhat.cloud.notifications.models.EndpointType)5 BadRequestException (javax.ws.rs.BadRequestException)5 Consumes (javax.ws.rs.Consumes)5 Application (com.redhat.cloud.notifications.models.Application)4 DELETE (javax.ws.rs.DELETE)4 POST (javax.ws.rs.POST)4 PUT (javax.ws.rs.PUT)4 CamelProperties (com.redhat.cloud.notifications.models.CamelProperties)3 Endpoint (com.redhat.cloud.notifications.models.Endpoint)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)3 Response (javax.ws.rs.core.Response)3