You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
package com.yablochkov.ocppstub;
|
|
|
|
import eu.chargetime.ocpp.YablSessionInformation;
|
|
import eu.chargetime.ocpp.model.SessionInformation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.java_websocket.handshake.ClientHandshake;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
@Service
|
|
@Slf4j
|
|
public class SessionService {
|
|
private final Map<UUID,SessionInformation> cache = new HashMap<>();
|
|
public void register(UUID sessionIndex, SessionInformation information) {
|
|
log.info("Register new session {}", sessionIndex);
|
|
cache.put(sessionIndex, information);
|
|
}
|
|
|
|
public void unregister(UUID sessionIndex) {
|
|
cache.remove(sessionIndex);
|
|
}
|
|
|
|
public String getAuthBySessionId(UUID sessionId) {
|
|
SessionInformation sessionInformation = cache.get(sessionId);
|
|
|
|
if (sessionInformation instanceof YablSessionInformation) {
|
|
YablSessionInformation session = (YablSessionInformation) sessionInformation;
|
|
|
|
ClientHandshake clientHandshake = session.getClientHandshake();
|
|
if (clientHandshake != null) {
|
|
return clientHandshake.getFieldValue("Authorization");
|
|
}
|
|
}
|
|
|
|
log.debug("Session {} auth status not found", sessionId);
|
|
return null;
|
|
}
|
|
}
|
|
|