1
1
package io .camunda .common .auth ;
2
2
3
+ import java .lang .invoke .MethodHandles ;
4
+ import java .util .*;
3
5
import org .apache .hc .client5 .http .classic .methods .HttpPost ;
4
6
import org .apache .hc .client5 .http .entity .UrlEncodedFormEntity ;
5
7
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
10
12
import org .slf4j .Logger ;
11
13
import org .slf4j .LoggerFactory ;
12
14
13
- import java .lang .invoke .MethodHandles ;
14
- import java .util .*;
15
-
16
15
public class SimpleAuthentication implements Authentication {
17
16
18
17
private static final Logger LOG = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
@@ -24,30 +23,35 @@ public class SimpleAuthentication implements Authentication {
24
23
25
24
public SimpleAuthentication (String simpleUrl , SimpleConfig simpleConfig ) {
26
25
this .simpleConfig = simpleConfig ;
27
- this .authUrl = simpleUrl + "/api/login" ;
26
+ this .authUrl = simpleUrl + "/api/login" ;
28
27
}
29
28
30
- public static SimpleAuthenticationBuilder builder () { return new SimpleAuthenticationBuilder (); }
29
+ public static SimpleAuthenticationBuilder builder () {
30
+ return new SimpleAuthenticationBuilder ();
31
+ }
31
32
32
33
public SimpleConfig getSimpleConfig () {
33
34
return simpleConfig ;
34
35
}
35
36
36
37
private String retrieveToken (Product product , SimpleCredential simpleCredential ) {
37
- try (CloseableHttpClient client = HttpClients .createDefault ()) {
38
+ try (CloseableHttpClient client = HttpClients .createDefault ()) {
38
39
HttpPost request = buildRequest (simpleCredential );
39
- String cookie = client .execute (request , response -> {
40
- Header [] cookieHeaders = response .getHeaders ("Set-Cookie" );
41
- String cookieCandidate = null ;
42
- String cookiePrefix = product .toString ().toUpperCase () + "-SESSION" ;
43
- for (Header cookieHeader : cookieHeaders ) {
44
- if (cookieHeader .getValue ().startsWith (cookiePrefix )) {
45
- cookieCandidate = response .getHeader ("Set-Cookie" ).getValue ();
46
- break ;
47
- }
48
- }
49
- return cookieCandidate ;
50
- });
40
+ String cookie =
41
+ client .execute (
42
+ request ,
43
+ response -> {
44
+ Header [] cookieHeaders = response .getHeaders ("Set-Cookie" );
45
+ String cookieCandidate = null ;
46
+ String cookiePrefix = product .toString ().toUpperCase () + "-SESSION" ;
47
+ for (Header cookieHeader : cookieHeaders ) {
48
+ if (cookieHeader .getValue ().startsWith (cookiePrefix )) {
49
+ cookieCandidate = response .getHeader ("Set-Cookie" ).getValue ();
50
+ break ;
51
+ }
52
+ }
53
+ return cookieCandidate ;
54
+ });
51
55
if (cookie == null ) {
52
56
throw new RuntimeException ("Unable to authenticate due to missing Set-Cookie" );
53
57
}
@@ -68,7 +72,7 @@ private HttpPost buildRequest(SimpleCredential simpleCredential) {
68
72
return httpPost ;
69
73
}
70
74
71
- @ Override
75
+ @ Override
72
76
public Map .Entry <String , String > getTokenHeader (Product product ) {
73
77
String token ;
74
78
if (tokens .containsKey (product )) {
0 commit comments