Java-OCA-OCPP icon indicating copy to clipboard operation
Java-OCA-OCPP copied to clipboard

Basic auth not working - sending null byte array for password field

Open FaheemBhatti opened this issue 2 years ago • 2 comments

I'm using a Java library for my ocpp operations. groupId of pom dependencies: eu.chargetime.ocpp.

Right now I'm trying to implement the authenticateSession method from ServerEvents, so that anytime a wallbox requests a connection to our backend, we validate the input password that comes as byte array. However, for some reason in most of the wallboxes that my company owns the password field comes as null, despite adding a password in the authorizationKey text field of their UI-s.

How do you usually handle the basic auth workflow for such cases? Has anyone ever faced a similar issue and how have you managed to resolve it?

I am attaching my code snippet for ServerEventConfig.java

	public ServerEvents createServerCoreImpl() {
		return getNewServerEventsImpl();
	}

	private ServerEvents getNewServerEventsImpl() {
		return new ServerEvents() {

			@Override
			public void newSession(UUID sessionIndex, SessionInformation information) {
				log.info("New session " + sessionIndex + ": " + information.getIdentifier());
				log.info("InetSocketAddress: " + information.getAddress());
				log.info("Soap to URL: " + information.getSOAPtoURL());
				sessionHandler.addSession(information.getIdentifier(), sessionIndex);
				SessionDetail sessionDetailsToStore =  sessionHandler.buildWebSocketSession(information.getIdentifier().substring(1) , sessionIndex.toString());
				sessionHandler.storeSessionInSessionCollection(sessionDetailsToStore);
				executePostSessionActions(sessionIndex);
			}

			@Override
			public void lostSession(UUID sessionIndex) {
				LocalDateTime eventTimestamp = LocalDateTime.now();
				String identifier = sessionHandler.getCpIdBySessionId(sessionIndex);
				log.info("Session " + sessionIndex + " having identifier: " + identifier + " lost connection");
				String connectorId = sessionHandler.getCpIdBySessionId(sessionIndex);
				sessionHandler.deleteSession(connectorId, sessionIndex);
				sessionHandler.deleteSessionFromDb(sessionIndex.toString());
				sessionHandler.handlerConnectorStatusOnConnectionLost(connectorId, eventTimestamp);
			}

			@Override
			public void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException
			{
				
				log.info(username);
				log.info(password.toString());
			}
		};
	}

Thank you in advance:)

FaheemBhatti avatar Dec 08 '23 15:12 FaheemBhatti

Is it the same case as https://github.com/ChargeTimeEU/Java-OCA-OCPP/issues/240?

jmluy avatar Dec 13 '23 08:12 jmluy

Is your password the expected length? See https://github.com/ChargeTimeEU/Java-OCA-OCPP/issues/240#issuecomment-1596368566 as indicated by @jmluy

bantu avatar Jan 24 '24 01:01 bantu