-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Accelerator 4] Adding event notification endpoint implementation #169
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5146005
Adding event notification endpoint implementation
Ashi1993 cd58793
Merge remote-tracking branch 'upstream/main' into event-endpoint
Ashi1993 00320c0
Merge remote-tracking branch 'upstream/main' into event-endpoint
Ashi1993 bd498c6
Adding event endpoint configs
Ashi1993 1f79f12
Fixed review comments
Ashi1993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
...rnal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<!-- | ||
~ Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
~ | ||
~ WSO2 LLC. licenses this file to you under the Apache License, | ||
~ Version 2.0 (the "License"); you may not use this file except | ||
~ in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, | ||
~ software distributed under the License is distributed on an | ||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~ KIND, either express or implied. See the License for the | ||
~ specific language governing permissions and limitations | ||
~ under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>financial-services-accelerator</artifactId> | ||
<groupId>org.wso2.financial.services.accelerator</groupId> | ||
<version>4.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>org.wso2.financial.services.accelerator.event.notifications.endpoint</artifactId> | ||
<packaging>war</packaging> | ||
<name>WSO2 Financial Services - Event Notification Endpoint</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.swagger</groupId> | ||
<artifactId>swagger-jaxrs</artifactId> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>jsr311-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.json.wso2</groupId> | ||
<artifactId>json</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-frontend-jaxrs</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId> | ||
<artifactId>org.wso2.carbon.identity.oauth</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.financial.services.accelerator</groupId> | ||
<artifactId>org.wso2.financial.services.accelerator.common</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.financial.services.accelerator</groupId> | ||
<artifactId>org.wso2.financial.services.accelerator.consent.mgt.service</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.financial.services.accelerator</groupId> | ||
<artifactId>org.wso2.financial.services.accelerator.consent.mgt.dao</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.wso2.financial.services.accelerator</groupId> | ||
<artifactId>org.wso2.financial.services.accelerator.event.notifications.service</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<configuration> | ||
<webResources> | ||
<resource> | ||
<!-- this is relative to the pom.xml directory --> | ||
<directory>src/main/webapp</directory> | ||
</resource> | ||
</webResources> | ||
<warName>api#fs#event-notifications</warName> | ||
<packagingExcludes>WEB-INF/lib/slf4j-api-*.jar</packagingExcludes> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<effort>Max</effort> | ||
<threshold>Low</threshold> | ||
<xmlOutput>true</xmlOutput> | ||
<failOnError>true</failOnError> | ||
<spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs</spotbugsXmlOutputDirectory> | ||
<excludeFilterFile>${project.basedir}/src/main/resources/findbugs-exclude.xml</excludeFilterFile> | ||
<includeFilterFile>${project.basedir}/src/main/resources/findbugs-include.xml</includeFilterFile> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.h3xstream.findsecbugs</groupId> | ||
<artifactId>findsecbugs-plugin</artifactId> | ||
<version>${com.h3xstream.findsecbugs.version}</version> | ||
</plugin> | ||
</plugins> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>analyze-compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
162 changes: 162 additions & 0 deletions
162
...inancial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* <p> | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.financial.services.accelerator.event.notifications.endpoint.api; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.json.JSONObject; | ||
import org.wso2.financial.services.accelerator.event.notifications.endpoint.constants.EventNotificationEndPointConstants; | ||
import org.wso2.financial.services.accelerator.event.notifications.endpoint.util.EventNotificationUtils; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.dto.NotificationCreationDTO; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.handler.EventCreationServiceHandler; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.model.EventCreationResponse; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* Events creation API. | ||
*/ | ||
@Path("/") | ||
public class EventCreationEndpoint { | ||
|
||
private static final Log log = LogFactory.getLog(EventCreationEndpoint.class); | ||
private final EventCreationServiceHandler eventCreationServiceHandler; | ||
private static final String specialChars = "!@#$%&*()'+,./:;<=>?[]^_`{|}"; | ||
private static final String illegalChars = "\\\\r|\\\\n|\\r|\\n|\\[|]| "; | ||
|
||
public EventCreationEndpoint() { | ||
|
||
eventCreationServiceHandler = EventNotificationUtils.getEventNotificationCreationServiceHandler(); | ||
} | ||
|
||
public EventCreationEndpoint(EventCreationServiceHandler handler) { | ||
|
||
eventCreationServiceHandler = handler; | ||
} | ||
|
||
/** | ||
* This API will be used to create events. | ||
*/ | ||
@SuppressFBWarnings({"JAXRS_ENDPOINT", "SERVLET_HEADER"}) | ||
// Suppressed content - Endpoint | ||
// Suppression reason - False Positive : This endpoint is secured with access control lists in the configuration | ||
// Suppressed content - request.getHeader() | ||
// Suppression reason - False Positive : Header is properly validated to ensure no special characters are passed | ||
// Suppressed warning count - 4 | ||
@POST | ||
@Path("/create-events") | ||
@Consumes({"application/x-www-form-urlencoded"}) | ||
@Produces({"application/json; charset=utf-8"}) | ||
public Response createEvents(@Context HttpServletRequest request, @Context HttpServletResponse response, | ||
MultivaluedMap parameterMap) { | ||
|
||
|
||
NotificationCreationDTO notificationCreationDTO = new NotificationCreationDTO(); | ||
String requestData = StringUtils.EMPTY; | ||
JSONObject notificationEvents; | ||
|
||
try { | ||
//Check if the request pay load is empty | ||
if (!parameterMap.isEmpty() && parameterMap.containsKey(EventNotificationEndPointConstants.REQUEST)) { | ||
|
||
requestData = parameterMap.get(EventNotificationEndPointConstants.REQUEST). | ||
toString().replaceAll(illegalChars, StringUtils.EMPTY); | ||
|
||
byte[] decodedBytes = Base64.getDecoder().decode(requestData); | ||
String decodedString = new String(decodedBytes, StandardCharsets.UTF_8); | ||
notificationEvents = new JSONObject(decodedString); | ||
log.debug("Decoded payload string : " + decodedString.replaceAll("[\r\n]", "")); | ||
|
||
} else { | ||
log.error(EventNotificationEndPointConstants.MISSING_REQUEST_PAYLOAD); | ||
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationServiceUtil | ||
.getErrorDTO(EventNotificationEndPointConstants.MISSING_REQUEST_PAYLOAD, | ||
EventNotificationConstants.MISSING_REQ_PAYLOAD)).build(); | ||
} | ||
|
||
//check if the client id is present in the header | ||
String clientId = request.getHeader(EventNotificationEndPointConstants.X_WSO2_CLIENT_ID); | ||
if (!StringUtils.isBlank(clientId)) { | ||
notificationCreationDTO.setClientId(request.getHeader( | ||
EventNotificationEndPointConstants.X_WSO2_CLIENT_ID)); | ||
} else { | ||
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationServiceUtil | ||
.getErrorDTO(EventNotificationEndPointConstants.MISSING_REQUEST_HEADER, | ||
EventNotificationConstants.MISSING_HEADER_PARAM_CLIENT_ID)).build(); | ||
} | ||
|
||
//check if the resource id is present in the header | ||
String resourceId = request.getHeader(EventNotificationEndPointConstants.X_WSO2_RESOURCE_ID); | ||
if (!StringUtils.isBlank(resourceId)) { | ||
if (StringUtils.containsAny(resourceId, specialChars)) { | ||
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationServiceUtil. | ||
getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST_HEADER, | ||
EventNotificationConstants.INVALID_CHARS_IN_HEADER_ERROR)).build(); | ||
} | ||
notificationCreationDTO.setResourceId(request.getHeader( | ||
EventNotificationEndPointConstants.X_WSO2_RESOURCE_ID));; | ||
} else { | ||
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationServiceUtil. | ||
getErrorDTO(EventNotificationEndPointConstants.MISSING_REQUEST_HEADER, | ||
EventNotificationConstants.MISSING_HEADER_PARAM_RESOURCE_ID)).build(); | ||
} | ||
|
||
//set events to notificationCreationDTO | ||
notificationEvents.keySet().forEach(eventName -> { | ||
JSONObject eventInformation = notificationEvents.getJSONObject(eventName); | ||
notificationCreationDTO.setEventPayload(eventName, eventInformation); | ||
}); | ||
|
||
|
||
EventCreationResponse eventCreationResponse = eventCreationServiceHandler. | ||
publishEvent(notificationCreationDTO); | ||
|
||
return EventNotificationUtils.mapEventCreationServiceResponse(eventCreationResponse); | ||
|
||
} catch (ClassCastException e) { | ||
log.error(EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR, e); | ||
return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationServiceUtil | ||
.getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, | ||
EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); | ||
} catch (FSEventNotificationException e) { | ||
log.error(EventNotificationEndPointConstants.EVENT_CREATION_ERROR_RESPONSE, e); | ||
return Response.status(e.getStatus()).entity(EventNotificationServiceUtil | ||
.getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST, | ||
e.getMessage())).build(); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed the log here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIxed in 1f79f12