diff --git a/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientRequest.java b/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientRequest.java new file mode 100644 index 00000000000..b4baa62da0c --- /dev/null +++ b/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientRequest.java @@ -0,0 +1,63 @@ +package io.jans.as.client; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.jans.as.model.util.QueryBuilder; +import io.jans.model.authzen.AccessEvaluationRequest; +import org.apache.log4j.Logger; + +/** + * @author Yuriy Z + */ +public class AccessEvaluationClientRequest extends ClientAuthnRequest implements IsJsonRequest { + + private static final Logger LOG = Logger.getLogger(AccessEvaluationClientRequest.class); + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private AccessEvaluationRequest request; + + public AccessEvaluationClientRequest() { + setContentType("application/json"); + } + + public AccessEvaluationRequest getRequest() { + return request; + } + + public AccessEvaluationClientRequest setRequest(AccessEvaluationRequest request) { + this.request = request; + return this; + } + + @Override + public String getQueryString() { + QueryBuilder builder = QueryBuilder.instance(); + if (request == null) { + return builder.toString(); + } + + appendClientAuthnToQuery(builder); + for (String key : getCustomParameters().keySet()) { + builder.append(key, getCustomParameters().get(key)); + } + + return builder.toString(); + } + + @Override + public String toString() { + return "AccessEvaluationClientRequest{" + + "request=" + request + + "} " + super.toString(); + } + + @Override + public String asJson() { + try { + return request != null ? MAPPER.writeValueAsString(request) : ""; + } catch (JsonProcessingException e) { + LOG.error("Failed to serialize request", e); + return ""; + } + } +} diff --git a/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientResponse.java b/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientResponse.java new file mode 100644 index 00000000000..c423d3bb413 --- /dev/null +++ b/jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientResponse.java @@ -0,0 +1,52 @@ +package io.jans.as.client; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.jans.model.authzen.AccessEvaluationResponse; +import jakarta.ws.rs.core.Response; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +/** + * @author Yuriy Z + */ +public class AccessEvaluationClientResponse extends BaseResponse { + + private static final Logger LOG = Logger.getLogger(AccessEvaluationClientResponse.class); + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private AccessEvaluationResponse response; + + public AccessEvaluationClientResponse(Response clientResponse) { + super(clientResponse); + injectDataFromJson(entity); + } + + public void injectDataFromJson(String json) { + if (StringUtils.isBlank(json)) { + return; + } + + try { + response = MAPPER.readValue(json, AccessEvaluationResponse.class); + } catch (JsonProcessingException e) { + LOG.error("Failed to read json: " + json, e); + } + } + + public AccessEvaluationResponse getResponse() { + return response; + } + + public AccessEvaluationClientResponse setResponse(AccessEvaluationResponse response) { + this.response = response; + return this; + } + + @Override + public String toString() { + return "AccessEvaluationClientResponse{" + + "response=" + response + + "} " + super.toString(); + } +}