working on token endpoint
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
/* © SRSoftware 2024 */
|
/* © SRSoftware 2024 */
|
||||||
package de.srsoftware.logging;
|
package de.srsoftware.logging;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
import static de.srsoftware.logging.ConsoleColors.*;
|
import static de.srsoftware.logging.ConsoleColors.*;
|
||||||
import static java.lang.System.Logger.Level.*;
|
import static java.lang.System.Logger.Level.*;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class ColorLogger implements System.Logger {
|
public class ColorLogger implements System.Logger {
|
||||||
private final String name;
|
private final String name;
|
||||||
private static int rootLevel = INFO.getSeverity();
|
private static int rootLevel = INFO.getSeverity();
|
||||||
|
|
||||||
public ColorLogger(String name) {
|
public ColorLogger(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -31,7 +30,7 @@ public class ColorLogger implements System.Logger {
|
|||||||
@Override
|
@Override
|
||||||
public void log(Level level, ResourceBundle bundle, String msg, Throwable thrown) {
|
public void log(Level level, ResourceBundle bundle, String msg, Throwable thrown) {
|
||||||
if (isLoggable(level)) {
|
if (isLoggable(level)) {
|
||||||
System.out.println(colorize(msg,level.getSeverity()));
|
System.out.println(colorize(msg, level.getSeverity()));
|
||||||
thrown.printStackTrace();
|
thrown.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,19 +38,19 @@ public class ColorLogger implements System.Logger {
|
|||||||
@Override
|
@Override
|
||||||
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
|
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
|
||||||
if (isLoggable(level)) {
|
if (isLoggable(level)) {
|
||||||
System.out.println(colorize(MessageFormat.format(format, params),level.getSeverity()));
|
System.out.println(colorize(MessageFormat.format(format, params), level.getSeverity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorLogger setLogLevel(Level level){
|
public ColorLogger setLogLevel(Level level) {
|
||||||
rootLevel = level.getSeverity();
|
rootLevel = level.getSeverity();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String colorize(String message,int severity){
|
private static String colorize(String message, int severity) {
|
||||||
var color = severity >= ERROR.getSeverity() ? RED : severity >= WARNING.getSeverity() ? YELLOW : severity >= INFO.getSeverity() ? WHITE_BRIGHT : WHITE;
|
var color = severity >= ERROR.getSeverity() ? RED : severity >= WARNING.getSeverity() ? YELLOW : severity >= INFO.getSeverity() ? WHITE_BRIGHT : WHITE;
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
|
var FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
|
||||||
return WHITE+FORMAT.format(date)+" "+color+message+RESET;
|
return WHITE + FORMAT.format(date) + " " + color + message + RESET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +1,77 @@
|
|||||||
|
/* © SRSoftware 2024 */
|
||||||
package de.srsoftware.logging;
|
package de.srsoftware.logging;
|
||||||
|
|
||||||
public class ConsoleColors {
|
public class ConsoleColors {
|
||||||
// Reset
|
// Reset
|
||||||
public static final String RESET = "\033[0m"; // Text Reset
|
public static final String RESET = "\033[0m"; // Text Reset
|
||||||
|
|
||||||
// Regular Colors
|
// Regular Colors
|
||||||
public static final String BLACK = "\033[0;30m"; // BLACK
|
public static final String BLACK = "\033[0;30m"; // BLACK
|
||||||
public static final String RED = "\033[0;31m"; // RED
|
public static final String RED = "\033[0;31m"; // RED
|
||||||
public static final String GREEN = "\033[0;32m"; // GREEN
|
public static final String GREEN = "\033[0;32m"; // GREEN
|
||||||
public static final String YELLOW = "\033[0;33m"; // YELLOW
|
public static final String YELLOW = "\033[0;33m"; // YELLOW
|
||||||
public static final String BLUE = "\033[0;34m"; // BLUE
|
public static final String BLUE = "\033[0;34m"; // BLUE
|
||||||
public static final String PURPLE = "\033[0;35m"; // PURPLE
|
public static final String PURPLE = "\033[0;35m"; // PURPLE
|
||||||
public static final String CYAN = "\033[0;36m"; // CYAN
|
public static final String CYAN = "\033[0;36m"; // CYAN
|
||||||
public static final String WHITE = "\033[0;37m"; // WHITE
|
public static final String WHITE = "\033[0;37m"; // WHITE
|
||||||
|
|
||||||
// Bold
|
// Bold
|
||||||
public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
|
public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
|
||||||
public static final String RED_BOLD = "\033[1;31m"; // RED
|
public static final String RED_BOLD = "\033[1;31m"; // RED
|
||||||
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
|
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
|
||||||
public static final String YELLOW_BOLD = "\033[1;33m"; // YELLOW
|
public static final String YELLOW_BOLD = "\033[1;33m"; // YELLOW
|
||||||
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
|
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
|
||||||
public static final String PURPLE_BOLD = "\033[1;35m"; // PURPLE
|
public static final String PURPLE_BOLD = "\033[1;35m"; // PURPLE
|
||||||
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
|
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
|
||||||
public static final String WHITE_BOLD = "\033[1;37m"; // WHITE
|
public static final String WHITE_BOLD = "\033[1;37m"; // WHITE
|
||||||
|
|
||||||
// Underline
|
// Underline
|
||||||
public static final String BLACK_UNDERLINED = "\033[4;30m"; // BLACK
|
public static final String BLACK_UNDERLINED = "\033[4;30m"; // BLACK
|
||||||
public static final String RED_UNDERLINED = "\033[4;31m"; // RED
|
public static final String RED_UNDERLINED = "\033[4;31m"; // RED
|
||||||
public static final String GREEN_UNDERLINED = "\033[4;32m"; // GREEN
|
public static final String GREEN_UNDERLINED = "\033[4;32m"; // GREEN
|
||||||
public static final String YELLOW_UNDERLINED = "\033[4;33m"; // YELLOW
|
public static final String YELLOW_UNDERLINED = "\033[4;33m"; // YELLOW
|
||||||
public static final String BLUE_UNDERLINED = "\033[4;34m"; // BLUE
|
public static final String BLUE_UNDERLINED = "\033[4;34m"; // BLUE
|
||||||
public static final String PURPLE_UNDERLINED = "\033[4;35m"; // PURPLE
|
public static final String PURPLE_UNDERLINED = "\033[4;35m"; // PURPLE
|
||||||
public static final String CYAN_UNDERLINED = "\033[4;36m"; // CYAN
|
public static final String CYAN_UNDERLINED = "\033[4;36m"; // CYAN
|
||||||
public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
|
public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
|
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
|
||||||
public static final String RED_BACKGROUND = "\033[41m"; // RED
|
public static final String RED_BACKGROUND = "\033[41m"; // RED
|
||||||
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
|
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
|
||||||
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
|
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
|
||||||
public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
|
public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
|
||||||
public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
|
public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
|
||||||
public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
|
public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
|
||||||
public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
|
public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
|
||||||
|
|
||||||
// High Intensity
|
// High Intensity
|
||||||
public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
|
public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
|
||||||
public static final String RED_BRIGHT = "\033[0;91m"; // RED
|
public static final String RED_BRIGHT = "\033[0;91m"; // RED
|
||||||
public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
|
public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
|
||||||
public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
|
public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
|
||||||
public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
|
public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
|
||||||
public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
|
public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
|
||||||
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
|
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
|
||||||
public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
|
public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
|
||||||
|
|
||||||
// Bold High Intensity
|
// Bold High Intensity
|
||||||
public static final String BLACK_BOLD_BRIGHT = "\033[1;90m"; // BLACK
|
public static final String BLACK_BOLD_BRIGHT = "\033[1;90m"; // BLACK
|
||||||
public static final String RED_BOLD_BRIGHT = "\033[1;91m"; // RED
|
public static final String RED_BOLD_BRIGHT = "\033[1;91m"; // RED
|
||||||
public static final String GREEN_BOLD_BRIGHT = "\033[1;92m"; // GREEN
|
public static final String GREEN_BOLD_BRIGHT = "\033[1;92m"; // GREEN
|
||||||
public static final String YELLOW_BOLD_BRIGHT = "\033[1;93m";// YELLOW
|
public static final String YELLOW_BOLD_BRIGHT = "\033[1;93m"; // YELLOW
|
||||||
public static final String BLUE_BOLD_BRIGHT = "\033[1;94m"; // BLUE
|
public static final String BLUE_BOLD_BRIGHT = "\033[1;94m"; // BLUE
|
||||||
public static final String PURPLE_BOLD_BRIGHT = "\033[1;95m";// PURPLE
|
public static final String PURPLE_BOLD_BRIGHT = "\033[1;95m"; // PURPLE
|
||||||
public static final String CYAN_BOLD_BRIGHT = "\033[1;96m"; // CYAN
|
public static final String CYAN_BOLD_BRIGHT = "\033[1;96m"; // CYAN
|
||||||
public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
|
public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
|
||||||
|
|
||||||
// High Intensity backgrounds
|
// High Intensity backgrounds
|
||||||
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
|
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m"; // BLACK
|
||||||
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
|
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m"; // RED
|
||||||
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
|
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m"; // GREEN
|
||||||
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
|
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m"; // YELLOW
|
||||||
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
|
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m"; // BLUE
|
||||||
public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
|
public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
|
||||||
public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
|
public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
|
||||||
public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
|
public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,12 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public record Client(String id, String name, String secret, Set<String> redirectUris) {
|
public record Client(String id, String name, String secret, Set<String> redirectUris) {
|
||||||
private static System.Logger LOG = System.getLogger(Client.class.getSimpleName());
|
private static System.Logger LOG = System.getLogger(Client.class.getSimpleName());
|
||||||
public Map<String, Object> map() {
|
public Map<String, Object> map() {
|
||||||
return Map.of(CLIENT_ID, id, NAME, name, SECRET, secret, REDIRECT_URIS, redirectUris);
|
return Map.of(CLIENT_ID, id, NAME, name, SECRET, secret, REDIRECT_URIS, redirectUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateCode() {
|
public String generateCode() {
|
||||||
LOG.log(WARNING,"{0}.generateCode() not implemented!", getClass().getSimpleName());
|
LOG.log(WARNING, "{0}.generateCode() not implemented!", getClass().getSimpleName());
|
||||||
return UUID.randomUUID().toString();
|
return UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ public class Constants {
|
|||||||
public static final String CLIENT_ID = "client_id";
|
public static final String CLIENT_ID = "client_id";
|
||||||
public static final String CODE = "code";
|
public static final String CODE = "code";
|
||||||
public static final String CONFIRMED = "confirmed";
|
public static final String CONFIRMED = "confirmed";
|
||||||
|
public static final String GRANT_TYPE = "grant_type";
|
||||||
public static final String NAME = "name";
|
public static final String NAME = "name";
|
||||||
public static final String REDIRECT_URI = "redirect_uri";
|
public static final String REDIRECT_URI = "redirect_uri";
|
||||||
public static final String REDIRECT_URIS = "redirect_uris";
|
public static final String REDIRECT_URIS = "redirect_uris";
|
||||||
public static final String SECRET = "secret";
|
public static final String SECRET = "secret";
|
||||||
public static final String STATE = "state";
|
public static final String STATE = "state";
|
||||||
|
public static final String ATUH_CODE = "authorization_code";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ import java.util.stream.Stream;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public abstract class PathHandler implements HttpHandler {
|
public abstract class PathHandler implements HttpHandler {
|
||||||
public System.Logger LOG = System.getLogger(getClass().getSimpleName());
|
public static final String CONTENT_TYPE = "Content-Type";
|
||||||
public static final String CONTENT_TYPE = "Content-Type";
|
public static final String DELETE = "DELETE";
|
||||||
public static final String DELETE = "DELETE";
|
private static final String FORWARDED_HOST = "x-forwarded-host";
|
||||||
public static final String GET = "GET";
|
public static final String GET = "GET";
|
||||||
public static final String JSON = "application/json";
|
public static final String HOST = "host";
|
||||||
public static final String POST = "POST";
|
public static final String JSON = "application/json";
|
||||||
|
public static System.Logger LOG = System.getLogger(PathHandler.class.getSimpleName());
|
||||||
|
public static final String POST = "POST";
|
||||||
|
|
||||||
private String[] paths;
|
private String[] paths;
|
||||||
|
|
||||||
@@ -96,7 +98,10 @@ public abstract class PathHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String hostname(HttpExchange ex) {
|
public static String hostname(HttpExchange ex) {
|
||||||
return "http://%s".formatted(ex.getRequestHeaders().getFirst("Host"));
|
var headers = ex.getRequestHeaders();
|
||||||
|
var host = headers.getFirst(FORWARDED_HOST);
|
||||||
|
if (host == null) host = headers.getFirst(HOST);
|
||||||
|
return host == null ? null : "https://"+host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject json(HttpExchange ex) throws IOException {
|
public static JSONObject json(HttpExchange ex) throws IOException {
|
||||||
@@ -118,6 +123,7 @@ public abstract class PathHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean sendContent(HttpExchange ex, int status, byte[] bytes) throws IOException {
|
public static boolean sendContent(HttpExchange ex, int status, byte[] bytes) throws IOException {
|
||||||
|
LOG.log(DEBUG, "sending {0} response…", status);
|
||||||
ex.sendResponseHeaders(status, bytes.length);
|
ex.sendResponseHeaders(status, bytes.length);
|
||||||
ex.getResponseBody().write(bytes);
|
ex.getResponseBody().write(bytes);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -21,17 +21,17 @@ import java.util.*;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
public static final String BACKEND = "/api";
|
public static final String BACKEND = "/api";
|
||||||
private static final String FAVICON = "/favicon.ico";
|
private static final String FAVICON = "/favicon.ico";
|
||||||
public static final String ROOT = "/";
|
public static final String ROOT = "/";
|
||||||
public static final String STATIC_PATH = "/web";
|
public static final String STATIC_PATH = "/web";
|
||||||
private static final String WELL_KNOWN = "/.well-known";
|
private static final String WELL_KNOWN = "/.well-known";
|
||||||
public static final String FIRST_USER = "admin";
|
public static final String FIRST_USER = "admin";
|
||||||
public static final String FIRST_USER_PASS = "admin";
|
public static final String FIRST_USER_PASS = "admin";
|
||||||
public static final String FIRST_UUID = UUID.randomUUID().toString();
|
public static final String FIRST_UUID = UUID.randomUUID().toString();
|
||||||
public static final String INDEX = STATIC_PATH + "/index.html";
|
public static final String INDEX = STATIC_PATH + "/index.html";
|
||||||
private static final String BASE_PATH = "basePath";
|
private static final String BASE_PATH = "basePath";
|
||||||
private static System.Logger LOG = new ColorLogger("Application").setLogLevel(DEBUG);
|
private static System.Logger LOG = new ColorLogger("Application").setLogLevel(DEBUG);
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
var argMap = map(args);
|
var argMap = map(args);
|
||||||
@@ -60,7 +60,7 @@ public class Application {
|
|||||||
map.put(BASE_PATH, Path.of(tokens.remove(0)));
|
map.put(BASE_PATH, Path.of(tokens.remove(0)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG.log(ERROR,"Unknown option: {0}", token);
|
LOG.log(ERROR, "Unknown option: {0}", token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -126,7 +128,7 @@ public class Backend extends PathHandler {
|
|||||||
return logout(ex, session);
|
return logout(ex, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.log(WARNING,"not implemented");
|
LOG.log(WARNING, "not implemented");
|
||||||
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +162,7 @@ public class Backend extends PathHandler {
|
|||||||
case "/user":
|
case "/user":
|
||||||
return sendUserAndCookie(ex, session);
|
return sendUserAndCookie(ex, session);
|
||||||
}
|
}
|
||||||
LOG.log(WARNING,"not implemented");
|
LOG.log(WARNING, "not implemented");
|
||||||
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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"));
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/* © SRSoftware 2024 */
|
/* © SRSoftware 2024 */
|
||||||
package de.srsoftware.oidc.web;
|
package de.srsoftware.oidc.web;
|
||||||
|
|
||||||
|
import static java.lang.System.Logger.Level.INFO;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import de.srsoftware.oidc.api.PathHandler;
|
import de.srsoftware.oidc.api.PathHandler;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static java.lang.System.Logger.Level.INFO;
|
|
||||||
|
|
||||||
public class Forward extends PathHandler {
|
public class Forward extends PathHandler {
|
||||||
private final int CODE = 302;
|
private final int CODE = 302;
|
||||||
private final String toPath;
|
private final String toPath;
|
||||||
@@ -17,7 +17,7 @@ public class Forward extends PathHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doGet(String path, HttpExchange ex) throws IOException {
|
public boolean doGet(String path, HttpExchange ex) throws IOException {
|
||||||
LOG.log(INFO,"Forwarding ({0}}) {1} to {2}…", CODE, path, toPath);
|
LOG.log(INFO, "Forwarding ({0}}) {1} to {2}…", CODE, path, toPath);
|
||||||
return sendRedirect(ex, toPath);
|
return sendRedirect(ex, toPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ public class StaticPages extends PathHandler {
|
|||||||
try {
|
try {
|
||||||
Response response = loadFile(lang, relativePath).orElseThrow(() -> new FileNotFoundException());
|
Response response = loadFile(lang, relativePath).orElseThrow(() -> new FileNotFoundException());
|
||||||
ex.getResponseHeaders().add(CONTENT_TYPE, response.contentType);
|
ex.getResponseHeaders().add(CONTENT_TYPE, response.contentType);
|
||||||
LOG.log(DEBUG,"Loaded {0} for language {1}…success.", relativePath, lang);
|
LOG.log(DEBUG, "Loaded {0} for language {1}…success.", relativePath, lang);
|
||||||
return sendContent(ex, response.content);
|
return sendContent(ex, response.content);
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
LOG.log(WARNING,"Loaded {0} for language {1}…failed.", relativePath, lang);
|
LOG.log(WARNING, "Loaded {0} for language {1}…failed.", relativePath, lang);
|
||||||
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
return sendEmptyResponse(HTTP_NOT_FOUND, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,29 +8,31 @@
|
|||||||
<link rel="stylesheet" href="style.css" />
|
<link rel="stylesheet" href="style.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<a id="clients" href="clients.html">Clients</a>
|
<a id="clients" href="clients.html">Clients</a>
|
||||||
</nav>
|
</nav>
|
||||||
<h1>Clients</h1>
|
<h1>Clients</h1>
|
||||||
<fieldset>
|
<a href="https://umbrella.srsoftware.de/user/login">Umbrella</a>
|
||||||
<legend>These are clients that are registered with LightOIDC:</legend>
|
|
||||||
<table>
|
<fieldset>
|
||||||
<tr>
|
<legend>These are clients that are registered with LightOIDC:</legend>
|
||||||
<th>Client</th>
|
<table>
|
||||||
<th>ID</th>
|
<tr>
|
||||||
<th>Redirect URLs</th>
|
<th>Client</th>
|
||||||
<th>Actions</th>
|
<th>ID</th>
|
||||||
</tr>
|
<th>Redirect URLs</th>
|
||||||
<tr id="bottom">
|
<th>Actions</th>
|
||||||
<td></td>
|
</tr>
|
||||||
<td></td>
|
<tr id="bottom">
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>
|
<td></td>
|
||||||
<button onclick="window.location.href='newclient.html';">Add new client…</button>
|
<td></td>
|
||||||
</td>
|
<td>
|
||||||
</tr>
|
<button onclick="window.location.href='newclient.html';">Add new client…</button>
|
||||||
</table>
|
</td>
|
||||||
<span class="hidden" id="message">Really remove client "{}"?</span>
|
</tr>
|
||||||
</fieldset>
|
</table>
|
||||||
|
<span class="hidden" id="message">Really remove client "{}"?</span>
|
||||||
|
</fieldset>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -29,6 +29,5 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<a href="https://umbrella.srsoftware.de/user/login">Umbrella</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user