|
|
@ -4,11 +4,21 @@ package de.srsoftware.http; |
|
|
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.Headers; |
|
|
|
import com.sun.net.httpserver.Headers; |
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
|
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SessionToken extends Cookie { |
|
|
|
public class SessionToken extends Cookie { |
|
|
|
private final String sessionId; |
|
|
|
private final String sessionId; |
|
|
|
|
|
|
|
private static final DateTimeFormatter FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss O"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SessionToken(String sessionId, Instant expiration){ |
|
|
|
|
|
|
|
super("sessionToken", "%s; Path=/api; Expires=%s".formatted(sessionId,FORMAT.format(expiration.atZone(ZoneOffset.UTC)))); |
|
|
|
|
|
|
|
this.sessionId = sessionId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public SessionToken(String sessionId) { |
|
|
|
public SessionToken(String sessionId) { |
|
|
|
super("sessionToken", sessionId + "; Path=/api"); |
|
|
|
super("sessionToken", sessionId + "; Path=/api"); |
|
|
@ -17,8 +27,8 @@ public class SessionToken extends Cookie { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public <T extends Cookie> T addTo(Headers headers) { |
|
|
|
public <T extends Cookie> T addTo(Headers headers) { |
|
|
|
headers.add("session", sessionId); |
|
|
|
headers.add("session", getValue()); |
|
|
|
return (T)this; // super.addTo(headers);
|
|
|
|
return super.addTo(headers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Optional<SessionToken> from(HttpExchange ex) { |
|
|
|
public static Optional<SessionToken> from(HttpExchange ex) { |
|
|
|