Skip to content

Commit 29a701b

Browse files
author
Daniel Rentsch
committed
add support for accessing 'X-Forwarded-For' field respectively proxied address
1 parent 52c9e8a commit 29a701b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class WebSocketListener implements Listener {
5353
private static final int OCPPJ_CP_MIN_PASSWORD_LENGTH = 16;
5454
private static final int OCPPJ_CP_MAX_PASSWORD_LENGTH = 20;
5555

56+
private static final String HTTP_HEADER_PROXIED_ADDRESS = "X-Forwarded-For";
57+
5658
private final ISessionFactory sessionFactory;
5759
private final List<Draft> drafts;
5860

@@ -106,10 +108,18 @@ public void relay(String message) {
106108

107109
sockets.put(webSocket, receiver);
108110

111+
String proxiedAddress = clientHandshake.getFieldValue(HTTP_HEADER_PROXIED_ADDRESS);
112+
113+
logger.debug(
114+
"New web-socket connection opened from address: {} proxied for: {}",
115+
webSocket.getRemoteSocketAddress(),
116+
proxiedAddress);
117+
109118
SessionInformation information =
110119
new SessionInformation.Builder()
111120
.Identifier(clientHandshake.getResourceDescriptor())
112121
.InternetAddress(webSocket.getRemoteSocketAddress())
122+
.ProxiedAddress(proxiedAddress)
113123
.build();
114124

115125
handler.newSession(

ocpp-common/src/main/java/eu/chargetime/ocpp/model/SessionInformation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class SessionInformation {
3131
private String identifier;
3232
private InetSocketAddress address;
3333
private String SOAPtoURL;
34+
private String proxiedAddress;
3435

3536
public String getIdentifier() {
3637
return identifier;
@@ -44,11 +45,16 @@ public String getSOAPtoURL() {
4445
return SOAPtoURL;
4546
}
4647

48+
public String getProxiedAddress() {
49+
return proxiedAddress;
50+
}
51+
4752
public static class Builder {
4853

4954
private String identifier;
5055
private InetSocketAddress address;
5156
private String SOAPtoURL;
57+
private String proxiedAddress;
5258

5359
public Builder Identifier(String identifier) {
5460
this.identifier = identifier;
@@ -60,11 +66,17 @@ public Builder InternetAddress(InetSocketAddress address) {
6066
return this;
6167
}
6268

69+
public Builder ProxiedAddress(String proxiedAddress) {
70+
this.proxiedAddress = proxiedAddress;
71+
return this;
72+
}
73+
6374
public SessionInformation build() {
6475
SessionInformation sessionInformation = new SessionInformation();
6576
sessionInformation.identifier = this.identifier;
6677
sessionInformation.address = this.address;
6778
sessionInformation.SOAPtoURL = this.SOAPtoURL;
79+
sessionInformation.proxiedAddress = this.proxiedAddress;
6880
return sessionInformation;
6981
}
7082

0 commit comments

Comments
 (0)