Skip to content

Commit dd6ad00

Browse files
nilsbehlenCopilot
andauthored
Prepare 1.5.0 (#84)
* small changes, prepare v1.5.0 * v1.5.0 * update actions * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove badges, dont skip tests, update dep --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3a3da74 commit dd6ad00

7 files changed

Lines changed: 36 additions & 65 deletions

File tree

.github/badges/branches.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/badges/coverage-summary.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/badges/jacoco.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/build.yml

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
22

3-
name: Java CI with Maven, Run Tests, Coverage Report and Badge
3+
name: Build
44

55
on:
66
push:
@@ -15,56 +15,6 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v4
18-
19-
- name: Setup Java Development Kits
20-
uses: actions/setup-java@v4
21-
with:
22-
java-version: 17
23-
distribution: microsoft
24-
cache: maven
25-
18+
2619
- name: Build with Maven
2720
run: mvn -B package --file pom.xml
28-
29-
- name: Generate JavaCodeCoverage badge
30-
id: jacoco
31-
uses: cicirello/jacoco-badge-generator@v2
32-
with:
33-
badges-directory: .github/badges
34-
generate-branches-badge: true
35-
generate-summary: true
36-
37-
- name: Log coverage percentages to workflow output
38-
run: |
39-
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
40-
echo "branches = ${{ steps.jacoco.outputs.branches }}"
41-
42-
- name: Upload JaCoCo coverage report as a workflow artifact
43-
uses: actions/upload-artifact@v4
44-
with:
45-
name: jacoco-report
46-
path: target/site/jacoco/
47-
48-
- name: Commit and push the coverage badges and summary file
49-
if: ${{ github.event_name != 'pull_request' }}
50-
run: |
51-
cd .github/badges
52-
if [[ `git status --porcelain *.svg *.json` ]]; then
53-
git config --global user.name 'github-actions'
54-
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
55-
git add *.svg *.json
56-
git commit -m "Autogenerated JaCoCo coverage badges" *.svg *.json
57-
git push
58-
fi
59-
60-
# - name: Comment on PR with coverage percentages
61-
# if: ${{ github.event_name == 'pull_request' }}
62-
# run: |
63-
# REPORT=$(<.github/badges/coverage-summary.json)
64-
# COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
65-
# BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
66-
# NEWLINE=$'\n'
67-
# BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
68-
# gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
69-
# env:
70-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<dependency>
119119
<groupId>com.auth0</groupId>
120120
<artifactId>java-jwt</artifactId>
121-
<version>4.4.0</version>
121+
<version>4.5.1</version>
122122
</dependency>
123123
</dependencies>
124124
</project>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ public void onFailure(@NotNull Call call, @NotNull IOException e)
7777
@Override
7878
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException
7979
{
80-
// Only response.body() is available in OkHttp; ensure it is closed and consumed only once to prevent resource leaks.
81-
// The body can only be consumed once.
80+
// For OkHttp, the response body is always available via `body()`, regardless of HTTP status.
81+
// We must ensure the body is closed to prevent resource leaks, and it can only be consumed once.
82+
// Using try-with-resources guarantees the body is properly closed after reading.
8283
try (ResponseBody responseBody = response.body())
8384
{
8485
if (responseBody != null)

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
import com.google.gson.Gson;
2020
import com.google.gson.GsonBuilder;
21+
import com.google.gson.JsonDeserializationContext;
22+
import com.google.gson.JsonDeserializer;
23+
import com.google.gson.JsonElement;
24+
import com.google.gson.JsonObject;
25+
import java.lang.reflect.Type;
2126
import java.util.ArrayList;
2227
import java.util.List;
2328
import java.util.function.Predicate;
@@ -84,10 +89,11 @@ public boolean authenticationSuccessful()
8489
*/
8590
public boolean pushAvailable()
8691
{
87-
return multiChallenge.stream().anyMatch(c -> isPushOrSmartphoneContainer(c.getType()));
92+
return multiChallenge.stream().anyMatch(c -> isPushOrSmartphoneContainer(c.getType()) && "poll".equals(c.getClientMode()));
8893
}
8994

90-
private boolean isPushOrSmartphoneContainer(String type) {
95+
private boolean isPushOrSmartphoneContainer(String type)
96+
{
9197
return TOKEN_TYPE_PUSH.equals(type) || CONTAINER_TYPE_SMARTPHONE.equals(type);
9298
}
9399

@@ -113,7 +119,8 @@ public String otpTransactionId()
113119
return null;
114120
}
115121

116-
public String pushTransactionId() {
122+
public String pushTransactionId()
123+
{
117124
for (Challenge challenge : multiChallenge)
118125
{
119126
if (isPushOrSmartphoneContainer(challenge.getType()))
@@ -142,14 +149,18 @@ private boolean isNotBlank(String str) {
142149
*/
143150
public String otpMessage()
144151
{
145-
return reduceChallengeMessagesWhere(c -> !(isPushOrSmartphoneContainer(c.getType())));
152+
return reduceChallengeMessagesWhere(c -> "interactive".equals(c.getClientMode()));
146153
}
147154

148155
private String reduceChallengeMessagesWhere(Predicate<Challenge> predicate)
149156
{
150157
StringBuilder sb = new StringBuilder();
151-
sb.append(
152-
multiChallenge.stream().filter(predicate).map(Challenge::getMessage).distinct().reduce("", (a, s) -> a + s + ", ").trim());
158+
sb.append(this.multiChallenge.stream()
159+
.filter(predicate)
160+
.map(Challenge::getMessage)
161+
.distinct()
162+
.reduce("", (a, s) -> a + s + ", ")
163+
.trim());
153164

154165
if (sb.length() > 0)
155166
{
@@ -198,7 +209,19 @@ public String toJSON()
198209

199210
public static PIResponse fromJSON(String json)
200211
{
201-
return new Gson().fromJson(json, PIResponse.class);
212+
JsonDeserializer<Challenge> challengeDeserializer = (jsonElement, type, ctx) ->
213+
{
214+
JsonObject obj = jsonElement.getAsJsonObject();
215+
String serial = obj.has("serial") && !obj.get("serial").isJsonNull() ? obj.get("serial").getAsString() : "";
216+
String message = obj.has("message") && !obj.get("message").isJsonNull() ? obj.get("message").getAsString() : "";
217+
String clientMode = obj.has("clientMode") && !obj.get("clientMode").isJsonNull() ? obj.get("clientMode").getAsString() : "";
218+
String image = obj.has("image") && !obj.get("image").isJsonNull() ? obj.get("image").getAsString() : "";
219+
String transactionID = obj.has("transactionID") && !obj.get("transactionID").isJsonNull() ? obj.get("transactionID").getAsString() : "";
220+
String tokenType = obj.has("type") && !obj.get("type").isJsonNull() ? obj.get("type").getAsString() : "";
221+
return new Challenge(serial, message, clientMode, image, transactionID, tokenType);
222+
};
223+
Gson gson = new GsonBuilder().registerTypeAdapter(Challenge.class, challengeDeserializer).create();
224+
return gson.fromJson(json, PIResponse.class);
202225
}
203226

204227
@Override

0 commit comments

Comments
 (0)