Skip to content

Commit e55f3cb

Browse files
authored
Merge pull request ChargeTimeEU#165 from listestalo/proxied_address
add support for accessing 'X-Forwarded-For' field respectively proxied address
2 parents fc413a1 + 29a701b commit e55f3cb

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
@@ -54,6 +54,8 @@ public class WebSocketListener implements Listener {
5454
private static final int OCPPJ_CP_MIN_PASSWORD_LENGTH = 16;
5555
private static final int OCPPJ_CP_MAX_PASSWORD_LENGTH = 20;
5656

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

@@ -110,10 +112,18 @@ public void relay(String message) {
110112

111113
sockets.put(webSocket, receiver);
112114

115+
String proxiedAddress = clientHandshake.getFieldValue(HTTP_HEADER_PROXIED_ADDRESS);
116+
117+
logger.debug(
118+
"New web-socket connection opened from address: {} proxied for: {}",
119+
webSocket.getRemoteSocketAddress(),
120+
proxiedAddress);
121+
113122
SessionInformation information =
114123
new SessionInformation.Builder()
115124
.Identifier(clientHandshake.getResourceDescriptor())
116125
.InternetAddress(webSocket.getRemoteSocketAddress())
126+
.ProxiedAddress(proxiedAddress)
117127
.build();
118128

119129
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)