Skip to content

Commit

Permalink
Merge pull request #308 from Joo200/feat/configure_pw_length
Browse files Browse the repository at this point in the history
Allow configuration of allowed password string length
  • Loading branch information
TVolden authored Jan 31, 2024
2 parents 01ba01e + 6060237 commit 0293ce1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> parameters = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down

0 comments on commit 0293ce1

Please sign in to comment.