Skip to content

Commit

Permalink
#186387666 : Governance rule fix (#120)
Browse files Browse the repository at this point in the history
* update dependency, add a new route

* use new goveranance rule API, update dependency

* Updated moesifapi version, Readme and other examples.

---------

Co-authored-by: Praveen Kumar <[email protected]>
  • Loading branch information
Sean Huo and praves77 authored Nov 30, 2023
1 parent 78fbb2d commit ebbb71e
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 28 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ transaction-logs
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/
.debug

## File-based project format:
*.iws
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Add the Moesif dependency to your project's pom.xml file:
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>

<!-- OR for newer Jakarta-->
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet-jakarta</artifactId>
<version>2.0.3</version>
<version>2.1.1</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet-jakarta</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public String random() {
return "{\"success\" : true}";
}

@GetMapping("gov/multiple_match")
public String multiple_match() {
return "{\"success\" : true}";
}

@RequestMapping("/api/text")
@ResponseBody
public String simpleString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet-jakarta</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jersey-servlet-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion moesif-servlet-jakarta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add the Moesif dependency to your project's pom.xml file:
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet-jakarta</artifactId>
<version>2.0.3</version>
<version>2.1.1</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions moesif-servlet-jakarta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet-jakarta</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<packaging>jar</packaging>
<name>moesif-servlet-jakarta</name>
<description>Moesif SDK for Java Servlet to log and analyze API calls using Jakarta</description>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>com.moesif.api</groupId>
<artifactId>moesifapi</artifactId>
<version>1.7.4</version>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
config.getMetadata(httpRequest, null)
);

if(moesifApi.getAPI().isBlockedByGovernanceRules(event)) {
logger.warning("Blocked by governance rules" + event.getBlockedBy());
BlockedByGovernanceRulesResponse blockResponse = moesifApi.getAPI().getBlockedByGovernanceRulesResponse(event);
if(blockResponse.isBlocked) {
logger.warning("Blocked by governance rules" + blockResponse.blockedBy);
event.setBlockedBy(blockResponse.blockedBy);
event.setResponse(blockResponse.response);
EventResponseModel responseModel = event.getResponse();
if (transactionId != null) {
responseModel.getHeaders().put("X-Moesif-Transaction-Id", transactionId);
Expand Down
4 changes: 2 additions & 2 deletions moesif-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
<packaging>jar</packaging>
<name>moesif-servlet</name>
<description>Moesif SDK for Java Servlet to log and analyze API calls</description>
Expand Down Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>com.moesif.api</groupId>
<artifactId>moesifapi</artifactId>
<version>1.7.4</version>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
config.getMetadata(httpRequest, null)
);

if(moesifApi.getAPI().isBlockedByGovernanceRules(event)) {
BlockedByGovernanceRulesResponse blockResponse = moesifApi.getAPI().getBlockedByGovernanceRulesResponse(event);
if(blockResponse.isBlocked) {
logger.warning("Blocked by governance rules" + blockResponse.blockedBy);
event.setBlockedBy(blockResponse.blockedBy);
event.setResponse(blockResponse.response);
EventResponseModel responseModel = event.getResponse();
if (transactionId != null) {
responseModel.getHeaders().put("X-Moesif-Transaction-Id", transactionId);
}

EventModel maskedEvent = config.maskContent(event);
this.addEventToQueue(maskedEvent);
Map<String, String> headers = responseModel.getHeaders();
Expand Down
4 changes: 2 additions & 2 deletions moesif-springrequest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.moesif.springrequest</groupId>
<artifactId>moesif-springrequest</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>
<name>moesif-springrequest</name>
<description>Moesif SDK for Java to log and analyze outgoing API calls</description>
Expand Down Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>com.moesif.api</groupId>
<artifactId>moesifapi</artifactId>
<version>1.7.4</version>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp
config.getSessionToken(request, null),
config.getMetadata(request, null)
);

if (moesifApi.getAPI().isBlockedByGovernanceRules(event)) {
BlockedByGovernanceRulesResponse blockResponse = moesifApi.getAPI().getBlockedByGovernanceRulesResponse(event);
if (blockResponse.isBlocked) {
EventResponseModel responseModel = event.getResponse();
if (!config.skip(request, null)) {
EventModel maskedEvent = config.maskContent(event);
Expand Down
4 changes: 2 additions & 2 deletions servlet-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.moesif.servlet</groupId>
<artifactId>servlet-example</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>war</packaging>
<name>servlet-example</name>

Expand All @@ -28,7 +28,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion spark-servlet-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>
<!--
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-servlet-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>


Expand Down
2 changes: 1 addition & 1 deletion spring-boot-starter-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>com.moesif.servlet</groupId>
<artifactId>moesif-servlet</artifactId>
<version>1.7.9</version>
<version>1.7.10</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit ebbb71e

Please sign in to comment.