Skip to content

Commit 0293ce1

Browse files
authored
Merge pull request #308 from Joo200/feat/configure_pw_length
Allow configuration of allowed password string length
2 parents 01ba01e + 6060237 commit 0293ce1

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class JSONConfiguration {
3939
public static final String CONNECT_NON_BLOCKING_PARAMETER = "CONNECT_NON_BLOCKING";
4040
public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";
4141
public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT";
42+
public static final String HTTP_HEALTH_CHECK_ENABLED = "HTTP_HEALTH_CHECK_ENABLED";
43+
public static final String OCPPJ_CP_MIN_PASSWORD_LENGTH = "OCPPJ_CP_MIN_PASSWORD_LENGTH";
44+
public static final String OCPPJ_CP_MAX_PASSWORD_LENGTH = "OCPPJ_CP_MAX_PASSWORD_LENGTH";
45+
public static final String OCPP2J_CP_MIN_PASSWORD_LENGTH = "OCPP2J_CP_MIN_PASSWORD_LENGTH";
46+
public static final String OCPP2J_CP_MAX_PASSWORD_LENGTH = "OCPP2J_CP_MAX_PASSWORD_LENGTH";
4247

4348
private final HashMap<String, Object> parameters = new HashMap<>();
4449

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
166166
}
167167
}
168168
if (password == null
169-
|| password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH
170-
|| password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
169+
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
170+
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
171171
throw new InvalidDataException(401, "Invalid password length");
172172
}
173173

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public JSONServer(ServerCoreProfile coreProfile, JSONConfiguration configuration
6969
protocols.add(new Protocol(""));
7070
draftOcppOnly = new Draft_6455(Collections.emptyList(), protocols);
7171

72-
if(configuration.getParameter("HTTP_HEALTH_CHECK_ENABLED", true)) {
72+
if(configuration.getParameter(JSONConfiguration.HTTP_HEALTH_CHECK_ENABLED, true)) {
7373
logger.info("JSONServer 1.6 with HttpHealthCheckDraft");
7474
this.listener = new WebSocketListener(sessionFactory, configuration, draftOcppOnly, new Draft_HttpHealthCheck());
7575
} else {

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public MultiProtocolJSONServer(
7373
}
7474
Draft draft = new Draft_6455(Collections.emptyList(), protocols);
7575

76-
if (configuration.getParameter("HTTP_HEALTH_CHECK_ENABLED", true)) {
76+
if (configuration.getParameter(JSONConfiguration.HTTP_HEALTH_CHECK_ENABLED, true)) {
7777
logger.info("JSONServer with HttpHealthCheckDraft");
7878
listener =
7979
new MultiProtocolWebSocketListener(

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
186186
}
187187
if (protocolVersion == null || protocolVersion == ProtocolVersion.OCPP1_6) {
188188
if (password == null
189-
|| password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH
190-
|| password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
189+
|| password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH)
190+
|| password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH))
191191
throw new InvalidDataException(401, "Invalid password length");
192192
} else {
193193
if (password == null
194-
|| password.length < OCPP2J_CP_MIN_PASSWORD_LENGTH
195-
|| password.length > OCPP2J_CP_MAX_PASSWORD_LENGTH)
194+
|| password.length < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH)
195+
|| password.length > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH))
196196
throw new InvalidDataException(401, "Invalid password length");
197197
}
198198
}

0 commit comments

Comments
 (0)