-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AuthZEN - added simple request/response classes for client
Signed-off-by: YuriyZ <[email protected]>
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ""; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
jans-auth-server/client/src/main/java/io/jans/as/client/AccessEvaluationClientResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |