From 6e87f899f1f811fbbc88d70a678b20ebe5c3ae83 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 02 Jun 2021 11:35:57 +0000
Subject: [PATCH] LogoutHandler hinzugefuegt

---
 src/de/uhilger/httpserver/auth/handler/LoginHandler.java |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/de/uhilger/httpserver/auth/handler/LoginHandler.java b/src/de/uhilger/httpserver/auth/handler/LoginHandler.java
index 7158157..2ba726a 100644
--- a/src/de/uhilger/httpserver/auth/handler/LoginHandler.java
+++ b/src/de/uhilger/httpserver/auth/handler/LoginHandler.java
@@ -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