Skip to content

Commit 125990d

Browse files
committed
small changes, prepare v1.5.0
1 parent 7a37a25 commit 125990d

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>org.privacyidea</groupId>
77
<artifactId>privacyidea-java-client</artifactId>
8-
<version>1.4.0</version>
8+
<version>1.5.0</version>
99
<packaging>jar</packaging>
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -83,16 +83,16 @@
8383
<version>4.13.2</version>
8484
<scope>test</scope>
8585
</dependency>
86-
<dependency>
87-
<groupId>com.squareup.okhttp3</groupId>
88-
<artifactId>okhttp</artifactId>
89-
<version>4.12.0</version>
90-
</dependency>
9186
<dependency>
9287
<groupId>org.jetbrains.kotlin</groupId>
9388
<artifactId>kotlin-stdlib</artifactId>
9489
<version>1.9.0</version>
9590
</dependency>
91+
<dependency>
92+
<groupId>com.squareup.okhttp3</groupId>
93+
<artifactId>okhttp</artifactId>
94+
<version>4.12.0</version>
95+
</dependency>
9696
<dependency>
9797
<groupId>com.squareup.okio</groupId>
9898
<artifactId>okio</artifactId>

src/main/java/org/privacyidea/AsyncRequestCallable.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import okhttp3.Call;
2525
import okhttp3.Callback;
2626
import okhttp3.Response;
27+
import okhttp3.ResponseBody;
2728
import org.jetbrains.annotations.NotNull;
2829

2930
import static org.privacyidea.PIConstants.ENDPOINT_AUTH;
@@ -76,15 +77,23 @@ public void onFailure(@NotNull Call call, @NotNull IOException e)
7677
@Override
7778
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException
7879
{
79-
if (response.body() != null)
80+
// The body of the response can be in `body()` for success cases or in `errorBody()` for error cases.
81+
// We need to handle both and ensure the body is closed to prevent resource leaks.
82+
// The body can only be consumed once.
83+
try (ResponseBody responseBody = response.body())
8084
{
81-
String s = response.body().string();
82-
if (!privacyIDEA.logExcludedEndpoints().contains(path) && !ENDPOINT_AUTH.equals(path))
85+
if (responseBody != null)
8386
{
84-
privacyIDEA.log(path + ":\n" + privacyIDEA.parser.formatJson(s));
87+
String s = responseBody.string();
88+
if (!privacyIDEA.logExcludedEndpoints().contains(path))
89+
{
90+
privacyIDEA.log(path + " (" + response.code() + "):\n" + privacyIDEA.parser.formatJson(s));
91+
}
92+
callbackResult[0] = s;
8593
}
86-
callbackResult[0] = s;
8794
}
88-
latch.countDown();
95+
finally {
96+
latch.countDown();
97+
}
8998
}
9099
}

src/main/java/org/privacyidea/JSONParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import static org.privacyidea.PIConstants.TIME;
7474
import static org.privacyidea.PIConstants.TOKEN;
7575
import static org.privacyidea.PIConstants.TOKENS;
76+
import static org.privacyidea.PIConstants.TOKEN_TYPE_PASSKEY;
7677
import static org.privacyidea.PIConstants.TOKEN_TYPE_WEBAUTHN;
7778
import static org.privacyidea.PIConstants.TRANSACTION_ID;
7879
import static org.privacyidea.PIConstants.TYPE;
@@ -277,6 +278,7 @@ else if ("interactive".equals(modeFromResponse))
277278
});
278279
}
279280

281+
// Multichallenge
280282
JsonArray arrChallenges = detail.getAsJsonArray(MULTI_CHALLENGE);
281283
if (arrChallenges != null)
282284
{
@@ -311,6 +313,10 @@ else if ("interactive".equals(modeFromResponse))
311313
webauthnSignRequests.add(webauthnSignRequest);
312314
}
313315
}
316+
else if (TOKEN_TYPE_PASSKEY.equals(type))
317+
{
318+
response.passkeyChallenge = challenge.toString();
319+
}
314320
else
315321
{
316322
response.multiChallenge.add(new Challenge(serial, message, clientMode, image, transactionID, type));

src/main/java/org/privacyidea/PIResponse.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ public String pushTransactionId() {
124124
return null;
125125
}
126126

127+
public boolean hasChallenges()
128+
{
129+
return (multiChallenge != null && !multiChallenge.isEmpty()) ||
130+
isNotBlank(mergedSignRequest()) ||
131+
isNotBlank(passkeyChallenge);
132+
}
133+
134+
private boolean isNotBlank(String str) {
135+
return str != null && !str.trim().isEmpty();
136+
}
137+
127138
/**
128139
* Get the messages of all token that require an input field (HOTP, TOTP, SMS, Email...) reduced to a single string.
129140
*

0 commit comments

Comments
 (0)