|
|
@ -12,9 +12,11 @@ import com.sun.net.httpserver.HttpExchange; |
|
|
|
import de.srsoftware.cookies.SessionToken; |
|
|
|
import de.srsoftware.cookies.SessionToken; |
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
import org.json.JSONObject; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public class Backend extends PathHandler { |
|
|
|
public class Backend extends PathHandler { |
|
|
@ -186,11 +188,18 @@ public class Backend extends PathHandler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean provideToken(HttpExchange ex) throws IOException { |
|
|
|
private boolean provideToken(HttpExchange ex) throws IOException { |
|
|
|
LOG.log(ERROR,"{0}.provideToken(ex) not implemented!\n", getClass().getSimpleName()); |
|
|
|
var map = deserialize(body(ex)); |
|
|
|
LOG.log(WARNING,json(ex)); |
|
|
|
LOG.log(WARNING, "map: {0}", map); |
|
|
|
|
|
|
|
LOG.log(ERROR, "{0}.provideToken(ex) not implemented!", getClass().getSimpleName()); |
|
|
|
|
|
|
|
var grantType = map.get(GRANT_TYPE); |
|
|
|
|
|
|
|
if (!ATUH_CODE.equals(grantType)) sendContent(ex, HTTP_BAD_REQUEST, Map.of(ERROR, "unknown grant type", GRANT_TYPE, grantType)); |
|
|
|
return sendEmptyResponse(HTTP_NOT_FOUND, ex); |
|
|
|
return sendEmptyResponse(HTTP_NOT_FOUND, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> deserialize(String body) { |
|
|
|
|
|
|
|
return Arrays.stream(body.split("&")).map(s -> s.split("=")).collect(Collectors.toMap(arr -> arr[0], arr -> arr[1])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean openidConfig(HttpExchange ex) throws IOException { |
|
|
|
private boolean openidConfig(HttpExchange ex) throws IOException { |
|
|
|
var host = hostname(ex); |
|
|
|
var host = hostname(ex); |
|
|
|
return sendContent(ex, Map.of("token_endpoint", host + "/api/token", "authorization_endpoint", host + "/web/authorization.html", "userinfo_endpoint", host + "/api/userinfo", "jwks_uri", host + "/api/jwks")); |
|
|
|
return sendContent(ex, Map.of("token_endpoint", host + "/api/token", "authorization_endpoint", host + "/web/authorization.html", "userinfo_endpoint", host + "/api/userinfo", "jwks_uri", host + "/api/jwks")); |
|
|
|