generated from openMF/ph-ee-start-here
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHEE-413 Fixed the bug while verifying signature in the interceptor (#42
) * PHEE-413 Fixed the bug while verifying signature in the interceptor * Version upgraded to 1.6.1-rc.1 * Generic logs converted to info for better observability
- Loading branch information
1 parent
dafcd12
commit beed14d
Showing
7 changed files
with
189 additions
and
34 deletions.
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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/org/mifos/connector/common/interceptor/MultiReadFilter.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,24 @@ | ||
package org.mifos.connector.common.interceptor; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.mifos.connector.common.interceptor.helper.MultiReadHttpServletRequest; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
|
||
@Slf4j | ||
public class MultiReadFilter extends GenericFilterBean { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
log.debug("Inside caching filter"); | ||
MultiReadHttpServletRequest multiReadRequest = new MultiReadHttpServletRequest((HttpServletRequest) request); | ||
chain.doFilter(multiReadRequest, response); | ||
} | ||
} |
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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/mifos/connector/common/interceptor/helper/ByteArrayServletInputStream.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,35 @@ | ||
package org.mifos.connector.common.interceptor.helper; | ||
|
||
import javax.servlet.ReadListener; | ||
import javax.servlet.ServletInputStream; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
public class ByteArrayServletInputStream extends ServletInputStream { | ||
|
||
private final ByteArrayInputStream inputStream; | ||
|
||
public ByteArrayServletInputStream(byte[] bytes) { | ||
inputStream = new ByteArrayInputStream(bytes); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
return inputStream.read(); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return inputStream.available() == 0; | ||
} | ||
|
||
@Override | ||
public boolean isReady() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setReadListener(ReadListener readListener) { | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/mifos/connector/common/interceptor/helper/MultiReadHttpServletRequest.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,53 @@ | ||
package org.mifos.connector.common.interceptor.helper; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.util.StreamUtils; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletInputStream; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
import javax.servlet.http.Part; | ||
import java.io.BufferedReader; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Collection; | ||
|
||
public class MultiReadHttpServletRequest extends HttpServletRequestWrapper { | ||
|
||
private byte[] body; | ||
|
||
/** | ||
* Creates a ServletRequest adaptor wrapping the given request object. | ||
* | ||
* @param request | ||
* @throws IllegalArgumentException if the request is null | ||
*/ | ||
public MultiReadHttpServletRequest(HttpServletRequest request) { | ||
super(request); | ||
try { | ||
body = StreamUtils.copyToByteArray(request.getInputStream()); | ||
}catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public ServletInputStream getInputStream() throws IOException { | ||
return new ByteArrayServletInputStream(body); | ||
} | ||
|
||
@Override | ||
public BufferedReader getReader() throws IOException { | ||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.body); | ||
return new BufferedReader(new InputStreamReader(byteArrayInputStream)); | ||
} | ||
|
||
@Override | ||
public Collection<Part> getParts() throws IOException, ServletException { | ||
return ((HttpServletRequest) getRequest()).getParts(); | ||
} | ||
|
||
} |