commit | author | age
|
7ecde3
|
1 |
/* |
U |
2 |
http-oauth - OAuth Extensions to jdk.httpserver |
|
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.oauth; |
|
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.base.handler.HttpHelper; |
|
24 |
import de.uhilger.httpserver.base.handler.HttpResponder; |
|
25 |
import static de.uhilger.httpserver.oauth.BearerLoginHandler.ATTR_AUTHENTICATOR; |
|
26 |
import java.io.IOException; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* |
|
31 |
* @author Ulrich Hilger |
|
32 |
* @version 1, 08.06.2021 |
|
33 |
*/ |
|
34 |
public class BearerRefreshHandler extends BearerLoginHandler { |
|
35 |
|
|
36 |
@Override |
|
37 |
public void handle(HttpExchange exchange) throws IOException { |
|
38 |
HttpHelper h = new HttpHelper(); |
|
39 |
String body = h.bodyLesen(exchange); |
|
40 |
String[] parts = body.split("&"); |
|
41 |
for(String part : parts) { |
|
42 |
String[] keyVals = part.split("="); |
|
43 |
if(keyVals[0].equalsIgnoreCase("refresh_token")) { |
|
44 |
HttpContext context = exchange.getHttpContext(); |
|
45 |
Object o = context.getAttributes().get(ATTR_AUTHENTICATOR); |
|
46 |
if (o instanceof BearerAuthenticator) { |
|
47 |
BearerAuthenticator auth = (BearerAuthenticator) o; |
|
48 |
LoginResponse response = auth.refresh(keyVals[1]); |
|
49 |
handleLoginResponse(exchange, response); |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
} |