working on user login

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-17 00:18:14 +02:00
parent 5627db16b5
commit add4209a1f
22 changed files with 173 additions and 401 deletions

View File

@@ -0,0 +1,20 @@
plugins {
id 'java'
}
group = 'de.srsoftware'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation project(':de.srsoftware.oidc.api')
}
test {
useJUnitPlatform()
}

View File

@@ -0,0 +1,44 @@
/* © SRSoftware 2024 */
package de.srsoftware.oidc.backend;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.oidc.api.PathHandler;
import java.io.IOException;
import java.util.Optional;
public class Backend extends PathHandler {
@Override
public void handle(HttpExchange ex) throws IOException {
String path = relativePath(ex);
String method = ex.getRequestMethod();
System.out.printf("%s %s…", method, path);
if ("login".equals(path)) {
doLogin(ex);
return;
}
var token = getAuthToken(ex);
if (token.isEmpty()) {
emptyResponse(HTTP_UNAUTHORIZED, ex);
System.err.println("unauthorized");
return;
}
System.err.println("not implemented");
ex.sendResponseHeaders(HTTP_NOT_FOUND, 0);
ex.getResponseBody().close();
}
private void doLogin(HttpExchange ex) throws IOException {
Optional<String> user = getHeader(ex, "login-username");
Optional<String> pass = getHeader(ex, "login-password");
System.out.printf("%s : %s", user, pass);
emptyResponse(HTTP_UNAUTHORIZED, ex);
}
private Optional<String> getAuthToken(HttpExchange ex) {
return getHeader(ex, "Authorization");
}
}