commit | author | age
|
6e87f8
|
1 |
/* |
U |
2 |
jwtTest - JSON Web Token Testimplementierung |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.auth.handler; |
|
19 |
|
|
20 |
import com.sun.net.httpserver.HttpContext; |
|
21 |
import com.sun.net.httpserver.HttpExchange; |
|
22 |
import com.sun.net.httpserver.HttpHandler; |
|
23 |
import de.uhilger.httpserver.auth.TokenAuthenticator; |
|
24 |
import de.uhilger.httpserver.base.handler.HttpResponder; |
|
25 |
import java.io.IOException; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author Ulrich Hilger |
|
30 |
* @version 1, 02.06.2021 |
|
31 |
*/ |
|
32 |
public class LogoutHandler implements HttpHandler { |
|
33 |
|
|
34 |
@Override |
|
35 |
public void handle(HttpExchange exchange) throws IOException { |
|
36 |
HttpContext context = exchange.getHttpContext(); |
|
37 |
Object o = context.getAttributes().get(LoginHandler.ATTR_AUTHENTICATOR); |
|
38 |
if (o instanceof TokenAuthenticator) { |
|
39 |
TokenAuthenticator auth = (TokenAuthenticator) o; |
|
40 |
String jwt = auth.cookieLesen(exchange, TokenAuthenticator.JWT_INDICATOR); |
|
41 |
if (jwt != null) { |
|
42 |
auth.abmelden(jwt); |
|
43 |
HttpResponder r = new HttpResponder(); |
|
44 |
r.antwortSenden(exchange, HttpResponder.SC_OK, "Abgemeldet."); |
|
45 |
} else { |
|
46 |
// kein JSON Web Token |
|
47 |
} |
|
48 |
} else { |
|
49 |
// kein passender Authenticator |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
} |