Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.privacyidea</groupId>
<artifactId>privacyidea-java-client</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -83,16 +83,16 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/org/privacyidea/AsyncRequestCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;

import static org.privacyidea.PIConstants.ENDPOINT_AUTH;
Expand Down Expand Up @@ -76,15 +77,22 @@ public void onFailure(@NotNull Call call, @NotNull IOException e)
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException
{
if (response.body() != null)
// Only response.body() is available in OkHttp; ensure it is closed and consumed only once to prevent resource leaks.
// The body can only be consumed once.
try (ResponseBody responseBody = response.body())
{
String s = response.body().string();
if (!privacyIDEA.logExcludedEndpoints().contains(path) && !ENDPOINT_AUTH.equals(path))
if (responseBody != null)
{
privacyIDEA.log(path + ":\n" + privacyIDEA.parser.formatJson(s));
String s = responseBody.string();
if (!privacyIDEA.logExcludedEndpoints().contains(path) && !ENDPOINT_AUTH.equals(path))
{
privacyIDEA.log(path + " (" + response.code() + "):\n" + privacyIDEA.parser.formatJson(s));
}
callbackResult[0] = s;
}
callbackResult[0] = s;
}
latch.countDown();
finally {
latch.countDown();
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/privacyidea/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import static org.privacyidea.PIConstants.TIME;
import static org.privacyidea.PIConstants.TOKEN;
import static org.privacyidea.PIConstants.TOKENS;
import static org.privacyidea.PIConstants.TOKEN_TYPE_PASSKEY;
import static org.privacyidea.PIConstants.TOKEN_TYPE_WEBAUTHN;
import static org.privacyidea.PIConstants.TRANSACTION_ID;
import static org.privacyidea.PIConstants.TYPE;
Expand Down Expand Up @@ -277,6 +278,7 @@ else if ("interactive".equals(modeFromResponse))
});
}

// Multichallenge
JsonArray arrChallenges = detail.getAsJsonArray(MULTI_CHALLENGE);
if (arrChallenges != null)
{
Expand Down Expand Up @@ -311,6 +313,10 @@ else if ("interactive".equals(modeFromResponse))
webauthnSignRequests.add(webauthnSignRequest);
}
}
else if (TOKEN_TYPE_PASSKEY.equals(type))
{
response.passkeyChallenge = challenge.toString();
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using challenge.toString() with Gson may serialize a JsonPrimitive string including quotes or a JsonObject's full JSON; if passkeyChallenge is expected to be the raw string value, use challenge.getAsString(). If an object is expected, assign challenge.getAsJsonObject() and adjust the target type.

Suggested change
response.passkeyChallenge = challenge.toString();
response.passkeyChallenge = challenge.getAsString();

Copilot uses AI. Check for mistakes.
}
else
{
response.multiChallenge.add(new Challenge(serial, message, clientMode, image, transactionID, type));
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/privacyidea/PIResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ public String pushTransactionId() {
return null;
}

public boolean hasChallenges()
{
return (multiChallenge != null && !multiChallenge.isEmpty()) ||
isNotBlank(mergedSignRequest()) ||
isNotBlank(passkeyChallenge);
}

private boolean isNotBlank(String str) {
return str != null && !str.trim().isEmpty();
}

/**
* Get the messages of all token that require an input field (HOTP, TOTP, SMS, Email...) reduced to a single string.
*
Expand Down