From c7d492742233c73d4594e5ff3b3b448809d93209 Mon Sep 17 00:00:00 2001 From: ulrich Date: Thu, 03 Jun 2021 17:21:34 +0000 Subject: [PATCH] Readme hinzugefuegt, Kommentare ergaenzt --- src/de/uhilger/httpserver/auth/handler/LoginHandler.java | 23 ++++++++++------------- 1 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/de/uhilger/httpserver/auth/handler/LoginHandler.java b/src/de/uhilger/httpserver/auth/handler/LoginHandler.java index 7158157..e4f4771 100644 --- a/src/de/uhilger/httpserver/auth/handler/LoginHandler.java +++ b/src/de/uhilger/httpserver/auth/handler/LoginHandler.java @@ -1,5 +1,5 @@ /* - jwtTest - JSON Web Token Testimplementierung + http-auth - Authentication Extensions to jdk.httpserver Copyright (C) 2021 Ulrich Hilger This program is free software: you can redistribute it and/or modify @@ -24,10 +24,7 @@ import com.sun.net.httpserver.HttpHandler; import de.uhilger.httpserver.auth.TokenAuthenticator; import de.uhilger.httpserver.auth.realm.User; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -42,7 +39,7 @@ /* Der Logger fuer diesen JWTLoginHandler */ //private static final Logger logger = Logger.getLogger(LoginHandler.class.getName()); - public static final String ATTR_JWT_AUTH = "jwtauth"; + public static final String ATTR_AUTHENTICATOR = "authenticator"; //protected String ctx; @@ -65,12 +62,12 @@ public void handle(HttpExchange exchange) throws IOException { User nutzer = getUser(exchange); HttpContext context = exchange.getHttpContext(); - Object o = context.getAttributes().get(ATTR_JWT_AUTH); + Object o = context.getAttributes().get(ATTR_AUTHENTICATOR); if (o instanceof TokenAuthenticator) { - TokenAuthenticator jwtAuth = (TokenAuthenticator) o; - String token = jwtAuth.anmelden(nutzer.getName(), nutzer.getPassword()); + TokenAuthenticator auth = (TokenAuthenticator) o; + String token = auth.anmelden(nutzer.getName(), nutzer.getPassword()); if (token != null) { - loginResponse(exchange, jwtAuth, token); + loginResponse(exchange, auth, token); } else { // Nutzer und Kennwort passen nicht } @@ -81,7 +78,7 @@ protected void setAuthenticatedHeader(HttpExchange exchange, Authenticator auth, String token) { if(auth instanceof TokenAuthenticator) { - TokenAuthenticator jwtAuth = (TokenAuthenticator) auth; + TokenAuthenticator tAuth = (TokenAuthenticator) auth; // angemeldet, Token als Antwort zurueckgeben Headers respHeaders = exchange.getResponseHeaders(); // JWT=[cookie-inhalt]; Expires=Thu, 21 Oct 2021 07:28:00 GMT; Secure; HttpOnly @@ -89,7 +86,7 @@ new SimpleDateFormat(TokenAuthenticator.HEADER_DATE_PATTERN, Locale.US); Date exp = Date.from(new Date().toInstant().plusSeconds(TokenAuthenticator.TOKEN_EXPIRATION)); respHeaders.add(TokenAuthenticator.SET_COOKIE_HEADER, - jwtAuth.cookieBilden(TokenAuthenticator.JWT_INDICATOR, token, exp)); + tAuth.cookieBilden(TokenAuthenticator.JWT_INDICATOR, token, exp)); } } @@ -97,7 +94,7 @@ protected abstract User getUser(HttpExchange exchange) throws IOException; - + /* protected String bodyLesen(HttpExchange exchange) throws IOException { StringBuilder sb = new StringBuilder(); InputStream is = exchange.getRequestBody(); @@ -109,6 +106,6 @@ } return sb.toString(); } - + */ } -- Gitblit v1.9.3