From 606023768ba61aaaace0d0eed65fb95ac2ff835a Mon Sep 17 00:00:00 2001 From: Johannes Zangl Date: Thu, 25 Jan 2024 11:51:37 +0100 Subject: [PATCH] Allow configuration of allowed password string length This change allows the configuration of the password length with entries in JSONConfiguration. --- .../main/java/eu/chargetime/ocpp/JSONConfiguration.java | 5 +++++ .../main/java/eu/chargetime/ocpp/WebSocketListener.java | 4 ++-- .../src/main/java/eu/chargetime/ocpp/JSONServer.java | 2 +- .../java/eu/chargetime/ocpp/MultiProtocolJSONServer.java | 2 +- .../chargetime/ocpp/MultiProtocolWebSocketListener.java | 8 ++++---- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java b/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java index 0f785b23f..782550433 100644 --- a/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java +++ b/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java @@ -39,6 +39,11 @@ public class JSONConfiguration { public static final String CONNECT_NON_BLOCKING_PARAMETER = "CONNECT_NON_BLOCKING"; public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS"; public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT"; + public static final String HTTP_HEALTH_CHECK_ENABLED = "HTTP_HEALTH_CHECK_ENABLED"; + public static final String OCPPJ_CP_MIN_PASSWORD_LENGTH = "OCPPJ_CP_MIN_PASSWORD_LENGTH"; + public static final String OCPPJ_CP_MAX_PASSWORD_LENGTH = "OCPPJ_CP_MAX_PASSWORD_LENGTH"; + public static final String OCPP2J_CP_MIN_PASSWORD_LENGTH = "OCPP2J_CP_MIN_PASSWORD_LENGTH"; + public static final String OCPP2J_CP_MAX_PASSWORD_LENGTH = "OCPP2J_CP_MAX_PASSWORD_LENGTH"; private final HashMap parameters = new HashMap<>(); diff --git a/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java b/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java index 464cc86f0..5eb06e667 100644 --- a/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java +++ b/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java @@ -166,8 +166,8 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer( } } if (password == null - || password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH - || password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH) + || password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH) + || password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH)) throw new InvalidDataException(401, "Invalid password length"); } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java index a3461e90f..b0cc81e42 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java @@ -69,7 +69,7 @@ public JSONServer(ServerCoreProfile coreProfile, JSONConfiguration configuration protocols.add(new Protocol("")); draftOcppOnly = new Draft_6455(Collections.emptyList(), protocols); - if(configuration.getParameter("HTTP_HEALTH_CHECK_ENABLED", true)) { + if(configuration.getParameter(JSONConfiguration.HTTP_HEALTH_CHECK_ENABLED, true)) { logger.info("JSONServer 1.6 with HttpHealthCheckDraft"); this.listener = new WebSocketListener(sessionFactory, configuration, draftOcppOnly, new Draft_HttpHealthCheck()); } else { diff --git a/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONServer.java b/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONServer.java index 853d6c286..282a6e12d 100644 --- a/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONServer.java +++ b/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONServer.java @@ -73,7 +73,7 @@ public MultiProtocolJSONServer( } Draft draft = new Draft_6455(Collections.emptyList(), protocols); - if (configuration.getParameter("HTTP_HEALTH_CHECK_ENABLED", true)) { + if (configuration.getParameter(JSONConfiguration.HTTP_HEALTH_CHECK_ENABLED, true)) { logger.info("JSONServer with HttpHealthCheckDraft"); listener = new MultiProtocolWebSocketListener( diff --git a/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java b/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java index 0a32b13f3..47c37fe45 100644 --- a/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java +++ b/ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketListener.java @@ -186,13 +186,13 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer( } if (protocolVersion == null || protocolVersion == ProtocolVersion.OCPP1_6) { if (password == null - || password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH - || password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH) + || password.length < configuration.getParameter(JSONConfiguration.OCPPJ_CP_MIN_PASSWORD_LENGTH, OCPPJ_CP_MIN_PASSWORD_LENGTH) + || password.length > configuration.getParameter(JSONConfiguration.OCPPJ_CP_MAX_PASSWORD_LENGTH, OCPPJ_CP_MAX_PASSWORD_LENGTH)) throw new InvalidDataException(401, "Invalid password length"); } else { if (password == null - || password.length < OCPP2J_CP_MIN_PASSWORD_LENGTH - || password.length > OCPP2J_CP_MAX_PASSWORD_LENGTH) + || password.length < configuration.getParameter(JSONConfiguration.OCPP2J_CP_MIN_PASSWORD_LENGTH, OCPP2J_CP_MIN_PASSWORD_LENGTH) + || password.length > configuration.getParameter(JSONConfiguration.OCPP2J_CP_MAX_PASSWORD_LENGTH, OCPP2J_CP_MAX_PASSWORD_LENGTH)) throw new InvalidDataException(401, "Invalid password length"); } }