Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit cb287a4

Browse files
committed
Seeing if this helps with DiceID callback
1 parent 41feccd commit cb287a4

File tree

2 files changed

+134
-6
lines changed

2 files changed

+134
-6
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.appirio.tech.core.service.identity.representation;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class DiceCallbackRequest {
6+
private String type;
7+
private String action;
8+
private String name;
9+
private String email;
10+
@JsonProperty(value = "connection_id")
11+
private String connectionId;
12+
@JsonProperty(value = "credential_exchange_id")
13+
private String credentialExchangeId;
14+
@JsonProperty(value = "presentation_exchange_id")
15+
private String presentationExchangeId;
16+
@JsonProperty(value = "schema_id")
17+
private String schemaId;
18+
19+
public String getConnectionId() {
20+
return connectionId;
21+
}
22+
23+
public void setConnectionId(String connectionId) {
24+
this.connectionId = connectionId;
25+
}
26+
27+
public String getCredentialExchangeId() {
28+
return credentialExchangeId;
29+
}
30+
31+
public void setCredentialExchangeId(String credentialExchangeId) {
32+
this.credentialExchangeId = credentialExchangeId;
33+
}
34+
35+
public String getPresentationExchangeId() {
36+
return presentationExchangeId;
37+
}
38+
39+
public void setPresentationExchangeId(String presentationExchangeId) {
40+
this.presentationExchangeId = presentationExchangeId;
41+
}
42+
43+
public String getSchemaId() {
44+
return schemaId;
45+
}
46+
47+
public void setSchemaId(String schemaId) {
48+
this.schemaId = schemaId;
49+
}
50+
51+
public String getType() {
52+
return type;
53+
}
54+
55+
public void setType(String type) {
56+
this.type = type;
57+
}
58+
59+
public String getAction() {
60+
return action;
61+
}
62+
63+
public void setAction(String action) {
64+
this.action = action;
65+
}
66+
67+
public String getName() {
68+
return name;
69+
}
70+
71+
public void setName(String name) {
72+
this.name = name;
73+
}
74+
75+
public String getEmail() {
76+
return email;
77+
}
78+
79+
public void setEmail(String email) {
80+
this.email = email;
81+
}
82+
}

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ private String sendDiceInvitation(UserDiceAttributes diceAttributes)
18081808
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
18091809
sendSlackNotification(diceAttributes.getHandle(), "Error happened, please check the logs.");
18101810
throw new APIRuntimeException(HttpURLConnection.HTTP_INTERNAL_ERROR,
1811-
String.format("Error when calling dice connection api with body. %s %s %d %s", mapper.writeValueAsString(body), token, response.getStatusCode(),
1811+
String.format("Error when calling dice connection api with body. %s %s %d %s", mapper.writeValueAsString(body), token,response.getStatusCode(),
18121812
response.getMessage()));
18131813
}
18141814
DiceInvitationResponse diceInvitation = new ObjectMapper().readValue(response.getText(),
@@ -1817,16 +1817,21 @@ private String sendDiceInvitation(UserDiceAttributes diceAttributes)
18171817
}
18181818

18191819
@POST
1820-
@Path("/dice-status")
1820+
@Path("/dice-callback")
18211821
@Timed
1822-
public ApiResponse diceStatus(@Valid PostPutRequest<DiceStatusRequest> postRequest,
1822+
public ApiResponse diceStatus(@Valid PostPutRequest<DiceCallbackRequest> postRequest,
18231823
@Context HttpServletRequest request) {
1824-
logger.info(String.format("Dice status request: %s %s", postRequest, request));
1824+
logger.info(String.format("Dice callback: %s %s", postRequest, request));
18251825
if (!diceAuth.isValidAPIKey(request)) {
18261826
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
18271827
}
1828-
checkParam(postRequest);
1829-
DiceStatusRequest status = postRequest.getParam();
1828+
1829+
if (postRequest == null) {
1830+
return ApiResponseFactory.createResponse(
1831+
createValidationResult(true, "Connection success"));
1832+
}
1833+
1834+
DiceCallbackRequest status = postRequest.getParam();
18301835
if (status.getType() == null) {
18311836
logger.info(String.format("Dice status missing type: %s %s", postRequest, request));
18321837
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "type"));
@@ -1860,6 +1865,47 @@ public ApiResponse diceStatus(@Valid PostPutRequest<DiceStatusRequest> postReque
18601865
return ApiResponseFactory.createResponse("SUCCESS");
18611866
}
18621867

1868+
@POST
1869+
@Path("/dice-status")
1870+
@Timed
1871+
public ApiResponse diceStatus(@Valid PostPutRequest<DiceStatusRequest> postRequest,
1872+
@Context HttpServletRequest request) {
1873+
if (!diceAuth.isValidAPIKey(request)) {
1874+
throw new APIRuntimeException(SC_FORBIDDEN, "Forbidden");
1875+
}
1876+
checkParam(postRequest);
1877+
DiceStatusRequest status = postRequest.getParam();
1878+
if (status.getEvent() == null) {
1879+
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "event"));
1880+
}
1881+
if (status.getConnectionId() == null || status.getConnectionId().isEmpty()) {
1882+
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "connectionId"));
1883+
}
1884+
logger.info(status);
1885+
switch (status.getEvent()) {
1886+
case "connection-invitation":
1887+
handleConnectionCreatedEvent(status.getConnectionId(), status.getEmailId(), status.getShortUrl());
1888+
break;
1889+
case "connection-response":
1890+
handleConnectionAcceptedEvent(status.getConnectionId());
1891+
break;
1892+
case "credential-issuance":
1893+
handleCredentialIssuanceEvent(status.getConnectionId());
1894+
break;
1895+
case "connection-declined":
1896+
handleConnectionDeclinedEvent(status.getConnectionId());
1897+
break;
1898+
case "credential-declined":
1899+
handleCredentialDeclinedEvent(status.getConnectionId());
1900+
break;
1901+
default:
1902+
throw new APIRuntimeException(SC_BAD_REQUEST,
1903+
String.format("%s is not valid event", status.getEvent()));
1904+
}
1905+
1906+
return ApiResponseFactory.createResponse("SUCCESS");
1907+
}
1908+
18631909
private void handleConnectionCreatedEvent(String connectionId, String emailId, String shortUrl) {
18641910
if (emailId == null || emailId.isEmpty()) {
18651911
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "emailId"));

0 commit comments

Comments
 (0)