Skip to content

Commit f561ece

Browse files
committed
fixes #123 update request and response transformer and rules
1 parent af649e4 commit f561ece

File tree

14 files changed

+144
-36
lines changed

14 files changed

+144
-36
lines changed

.classpath

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
<attribute name="optional" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
16+
<attributes>
17+
<attribute name="optional" value="true"/>
18+
<attribute name="maven.pomderived" value="true"/>
19+
<attribute name="test" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
23+
<attributes>
24+
<attribute name="maven.pomderived" value="true"/>
25+
<attribute name="test" value="true"/>
26+
<attribute name="optional" value="true"/>
27+
</attributes>
28+
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
30+
<attributes>
31+
<attribute name="maven.pomderived" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
35+
<attributes>
36+
<attribute name="maven.pomderived" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="src" path="target/generated-sources/annotations">
40+
<attributes>
41+
<attribute name="optional" value="true"/>
42+
<attribute name="maven.pomderived" value="true"/>
43+
<attribute name="ignore_optional_problems" value="true"/>
44+
<attribute name="m2e-apt" value="true"/>
45+
</attributes>
46+
</classpathentry>
47+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
48+
<attributes>
49+
<attribute name="optional" value="true"/>
50+
<attribute name="maven.pomderived" value="true"/>
51+
<attribute name="ignore_optional_problems" value="true"/>
52+
<attribute name="m2e-apt" value="true"/>
53+
<attribute name="test" value="true"/>
54+
</attributes>
55+
</classpathentry>
56+
<classpathentry kind="output" path="target/classes"/>
57+
</classpath>

.project

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.networknt-lambda-native</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1736902947174</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
34+
</projectDescription>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
4+
encoding//src/test/java=UTF-8
5+
encoding//src/test/resources=UTF-8
6+
encoding/<project>=UTF-8
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
8+
org.eclipse.jdt.core.compiler.release=disabled
9+
org.eclipse.jdt.core.compiler.source=11
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

src/main/java/com/networknt/aws/lambda/handler/middleware/security/JwtVerifyMiddleware.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ public Status handleJwt(LightLambdaExchange exchange, String pathPrefix, String
103103

104104
String clientId = claims.getStringClaimValue(Constants.CLIENT_ID_STRING);
105105
String userId = claims.getStringClaimValue(Constants.USER_ID_STRING);
106-
String issuer = claims.getStringClaimValue(Constants.ISS_STRING);
106+
String issuer = claims.getStringClaimValue(Constants.ISS);
107107
// try to get the cid as some OAuth tokens name it as cid like Okta.
108108
if (clientId == null)
109-
clientId = claims.getStringClaimValue(Constants.CID_STRING);
109+
clientId = claims.getStringClaimValue(Constants.CID);
110110

111111

112112
// try to get the uid as some OAuth tokens name it as uid like Okta.
113113
if (userId == null)
114-
userId = claims.getStringClaimValue(Constants.UID_STRING);
114+
userId = claims.getStringClaimValue(Constants.UID);
115115

116116
/* if no auditInfo has been set previously, we populate here */
117117
auditInfo = (exchange.getAttachment(AUDIT_ATTACHMENT_KEY) != null) ? (Map<String, Object>) exchange.getAttachment(AUDIT_ATTACHMENT_KEY) : new HashMap<>();

src/main/java/com/networknt/aws/lambda/handler/middleware/transformer/RequestTransformerMiddleware.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class RequestTransformerMiddleware extends AbstractTransformerMiddleware {
2727
private static final Logger LOG = LoggerFactory.getLogger(RequestTransformerMiddleware.class);
28-
static final String REQUEST_TRANSFORM = "request-transform";
28+
static final String REQUEST_TRANSFORM = "req-tra";
2929

3030
private static RequestTransformerConfig CONFIG;
3131
public RequestTransformerMiddleware() {
@@ -71,7 +71,7 @@ public Status execute(LightLambdaExchange exchange) {
7171
if(LOG.isDebugEnabled()) LOG.debug("endpointRules: " + endpointRules.get(REQUEST_TRANSFORM).size());
7272
}
7373
if(endpointRules != null) {
74-
List<Map<String, Object>> requestTransformRules = endpointRules.get(REQUEST_TRANSFORM);
74+
List<String> requestTransformRules = endpointRules.get(REQUEST_TRANSFORM);
7575
if(requestTransformRules != null) {
7676
boolean finalResult = true;
7777
// call the rule engine to transform the request metadata or body. The input contains all the request elements
@@ -92,12 +92,10 @@ public Status execute(LightLambdaExchange exchange) {
9292
}
9393
}
9494
Map<String, Object> result = null;
95-
String ruleId = null;
9695
// iterate the rules and execute them in sequence. Break only if one rule is successful.
9796
if(LOG.isDebugEnabled()) LOG.debug("requestTransformRules list count: " + requestTransformRules.size());
98-
for(Map<String, Object> ruleMap: requestTransformRules) {
99-
ruleId = (String)ruleMap.get(Constants.RULE_ID);
100-
if(LOG.isDebugEnabled()) LOG.debug("ruleID found: " + ruleId);
97+
for(String ruleId: requestTransformRules) {
98+
if(LOG.isDebugEnabled()) LOG.debug("ruleId found: {}", ruleId);
10199
try {
102100
result = ruleEngine.executeRule(ruleId, objMap);
103101
boolean res = (Boolean) result.get(RuleConstants.RESULT);

src/main/java/com/networknt/aws/lambda/handler/middleware/transformer/ResponseTransformerMiddleware.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class ResponseTransformerMiddleware extends AbstractTransformerMiddleware {
2323
private static ResponseTransformerConfig CONFIG;
2424
private static final Logger LOG = LoggerFactory.getLogger(ResponseTransformerMiddleware.class);
25-
private static final String RESPONSE_TRANSFORM = "response-transform";
25+
private static final String RESPONSE_TRANSFORM = "res-tra";
2626
private static final String RESPONSE_HEADERS = "responseHeaders";
2727
private static final String REQUEST_HEADERS = "requestHeaders";
2828
private static final String RESPONSE_BODY = "responseBody";
@@ -123,12 +123,10 @@ public Status execute(LightLambdaExchange exchange) {
123123
}
124124

125125
boolean finalResult = true;
126-
List<Map<String, Object>> responseTransformRules = endpointRules.get(RESPONSE_TRANSFORM);
126+
List<String> responseTransformRules = endpointRules.get(RESPONSE_TRANSFORM);
127127
Map<String, Object> result = null;
128-
String ruleId = null;
129128
// iterate the rules and execute them in sequence. Break only if one rule is successful.
130-
for(Map<String, Object> ruleMap: responseTransformRules) {
131-
ruleId = (String)ruleMap.get(Constants.RULE_ID);
129+
for(String ruleId: responseTransformRules) {
132130
try {
133131
result = ruleEngine.executeRule(ruleId, objMap);
134132
boolean res = (Boolean) result.get(RuleConstants.RESULT);

src/test/java/com/networknt/aws/lambda/middleware/transformer/DummyRequestBodyUpdateAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.networknt.rule.IAction;
66
import com.networknt.rule.RuleActionValue;
77
import com.networknt.rule.RuleConstants;
8+
import com.networknt.rule.exception.RuleEngineException;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011

@@ -19,7 +20,7 @@ public class DummyRequestBodyUpdateAction implements IAction {
1920
private static final Logger logger = LoggerFactory.getLogger(DummyRequestBodyUpdateAction.class);
2021

2122
@Override
22-
public void performAction(Map<String, Object> objMap, Map<String, Object> resultMap, Collection<RuleActionValue> actionValues) {
23+
public void performAction(String ruleId, String actionId, Map<String, Object> objMap, Map<String, Object> resultMap, Collection<RuleActionValue> actionValues) throws RuleEngineException {
2324
resultMap.put(RuleConstants.RESULT, true);
2425
String requestBody = (String)objMap.get("requestBody");
2526
if(logger.isTraceEnabled()) logger.debug("original request body = " + requestBody);

0 commit comments

Comments
 (0)