Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added SignedJWT deserializer. #175

Merged
merged 3 commits into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SignedJWTDeserializer.java
*
* 8 jan 2025
*/
package it.pagopa.swclient.mil.auth.util;

import java.io.IOException;
import java.text.ParseException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.nimbusds.jwt.SignedJWT;

import io.quarkus.logging.Log;
import it.pagopa.swclient.mil.auth.AuthErrorCode;
import it.pagopa.swclient.mil.bean.Errors;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

/**
* <p>
* Deserializes strings in signed JWT.
* </p>
*
* @author Antonio Tarricone
*/
public class SignedJWTDeserializer extends JsonDeserializer<SignedJWT> {
/**
* <p>
* Default constructor.
* </p>
*/
public SignedJWTDeserializer() {
super();
}

/**
*
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(JsonParser,
* DeserializationContext) JsonDeserializer#deserialize(JsonParser, DeserializationContext)
*/
@Override
public SignedJWT deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
Log.trace("deserialize");
try {
return SignedJWT.parse(p.getText());
} catch (ParseException e) {
String message = String.format("[%s] Error parsing token", AuthErrorCode.ERROR_PARSING_TOKEN);
Log.errorf(e, message);
Response error = Response.status(Status.BAD_REQUEST)
.entity(new Errors(AuthErrorCode.ERROR_PARSING_TOKEN, message))
.build();
throw new BadRequestException(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public SignedJWT fromString(String value) {
*/
@Override
public String toString(SignedJWT value) {
// For now this method is not useful, so to avoid coverage checking,
// I prefer to return an exception!
// The real implementation should be:
// Log.trace("toString"); // NOSONAR
// return value.serialize(); // NOSONAR
throw new UnsupportedOperationException();
Log.trace("toString");
return value.serialize();
}
}
60 changes: 30 additions & 30 deletions src/main/terraform/container_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,36 @@ resource "azurerm_container_app" "auth" {
secret_name = "identity-client-id"
}

liveness_probe {
path = "/q/health/live"
port = 8080
transport = "HTTP"
initial_delay = 0
interval_seconds = 10
failure_count_threshold = 3
timeout = 1
}

readiness_probe {
path = "/q/health/ready"
port = 8080
transport = "HTTP"
initial_delay = 0
interval_seconds = 10
failure_count_threshold = 3
success_count_threshold = 1
timeout = 1
}

startup_probe {
path = "/q/health/started"
port = 8080
transport = "HTTP"
initial_delay = 0
interval_seconds = 10
failure_count_threshold = 3
timeout = 1
}
#liveness_probe {
# path = "/q/health/live"
# port = 8080
# transport = "HTTP"
# initial_delay = 0
# interval_seconds = 10
# failure_count_threshold = 3
# timeout = 1
#}

#readiness_probe {
# path = "/q/health/ready"
# port = 8080
# transport = "HTTP"
# initial_delay = 0
# interval_seconds = 10
# failure_count_threshold = 3
# success_count_threshold = 1
# timeout = 1
#}

#startup_probe {
# path = "/q/health/started"
# port = 8080
# transport = "HTTP"
# initial_delay = 0
# interval_seconds = 10
# failure_count_threshold = 3
# timeout = 1
#}
}

max_replicas = var.mil_auth_max_replicas
Expand Down
189 changes: 0 additions & 189 deletions src/main/terraform/container_app_arm.off

This file was deleted.

37 changes: 37 additions & 0 deletions src/test/java/it/pagopa/swclient/mil/auth/util/Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Sample.java
*
* 8 jan 2025
*/
package it.pagopa.swclient.mil.auth.util;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.nimbusds.jwt.SignedJWT;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
*
* @author Antonio Tarricone
*/
@Getter
@Setter
@Accessors(chain = true)
public class Sample {
/**
* JSON keys.
*/
public static final String JWT_JK = "jwt";

/**
*
*/
@JsonProperty(JWT_JK)
@JsonSerialize(using = SignedJWTSerializer.class)
@JsonDeserialize(using = SignedJWTDeserializer.class)
private SignedJWT jwt;
}
Loading
Loading