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

Commit 92c9d12

Browse files
committed
update dice conf
1 parent c12fd6f commit 92c9d12

File tree

8 files changed

+215
-32
lines changed

8 files changed

+215
-32
lines changed

buildtokenproperties.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ AUTH0_NEW_NONINTERACTIVE_ID=$(eval "echo \$${ENV}_AUTH0_NEW_NONINTERACTIVE_ID")
1717
AUTH0_NEW_NONINTERACTIVE_ID_SECRET=$(eval "echo \$${ENV}_AUTH0_NEW_NONINTERACTIVE_ID_SECRET")
1818
DICEAUTH_DICE_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_URL")
1919
DICEAUTH_DICE_API_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_URL")
20-
DICEAUTH_API_KEY=$(eval "echo \$${ENV}_DICEAUTH_API_KEY")
20+
DICEAUTH_DICE_VERIFIER=$(eval "echo \$${ENV}_DICEAUTH_DICE_VERIFIER")
21+
DICEAUTH_ID=$(eval "echo \$${ENV}_DICEAUTH_ID")
22+
DICEAUTH_ID_SECRET=$(eval "echo \$${ENV}_DICEAUTH_ID_SECRET")
23+
DICEAUTH_PASSWORD=$(eval "echo \$${ENV}_DICEAUTH_PASSWORD")
24+
DICEAUTH_SCOPE=$(eval "echo \$${ENV}_DICEAUTH_SCOPE")
25+
DICEAUTH_TENANT=$(eval "echo \$${ENV}_DICEAUTH_TENANT")
26+
DICEAUTH_USERNAME=$(eval "echo \$${ENV}_DICEAUTH_USERNAME")
2127
DICEAUTH_CREDDEFID=$(eval "echo \$${ENV}_DICEAUTH_CREDDEFID")
2228
ZENDESK_ID=$(eval "echo \$${ENV}_ZENDESK_ID")
2329
SERVICEACC02_UID=$(eval "echo \$${ENV}_SERVICEACC02_UID")
@@ -90,7 +96,13 @@ perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID\}\}/$AUTH0_NEW_NONINTERACTIVE_ID/
9096
perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID_SECRET\}\}/$AUTH0_NEW_NONINTERACTIVE_ID_SECRET/g" $CONFFILENAME
9197
perl -pi -e "s|\{\{DICEAUTH_DICE_URL\}\}|$DICEAUTH_DICE_URL|g" $CONFFILENAME
9298
perl -pi -e "s|\{\{DICEAUTH_DICE_API_URL\}\}|$DICEAUTH_DICE_API_URL|g" $CONFFILENAME
93-
perl -pi -e "s/\{\{DICEAUTH_API_KEY\}\}/$DICEAUTH_API_KEY/g" $CONFFILENAME
99+
perl -pi -e "s|\{\{DICEAUTH_DICE_VERIFIER\}\}|$DICEAUTH_DICE_VERIFIER|g" $CONFFILENAME
100+
perl -pi -e "s/\{\{DICEAUTH_ID\}\}/$DICEAUTH_ID/g" $CONFFILENAME
101+
perl -pi -e "s/\{\{DICEAUTH_ID_SECRET\}\}/$DICEAUTH_ID_SECRET/g" $CONFFILENAME
102+
perl -pi -e "s/\{\{DICEAUTH_PASSWORD\}\}/$DICEAUTH_PASSWORD/g" $CONFFILENAME
103+
perl -pi -e "s/\{\{DICEAUTH_SCOPE\}\}/$DICEAUTH_SCOPE/g" $CONFFILENAME
104+
perl -pi -e "s/\{\{DICEAUTH_TENANT\}\}/$DICEAUTH_TENANT/g" $CONFFILENAME
105+
perl -pi -e "s/\{\{DICEAUTH_USERNAME\}\}/$DICEAUTH_USERNAME/g" $CONFFILENAME
94106
perl -pi -e "s/\{\{DICEAUTH_CREDDEFID\}\}/$DICEAUTH_CREDDEFID/g" $CONFFILENAME
95107
perl -pi -e "s/\{\{ZENDESK_KEY\}\}/$ZENDESK_KEY/g" $CONFFILENAME
96108
perl -pi -e "s/\{\{ZENDESK_ID\}\}/$ZENDESK_ID/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/clients/EventBusServiceClient.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111

12-
import java.net.SocketTimeoutException;
13-
12+
import javax.ws.rs.ProcessingException;
1413
import javax.ws.rs.client.Client;
1514
import javax.ws.rs.client.Entity;
1615
import javax.ws.rs.client.Invocation;
@@ -89,9 +88,8 @@ public void reFireEvent(EventMessage eventMessage) {
8988
if (response.getStatusInfo().getStatusCode() != HttpStatus.OK_200 && response.getStatusInfo().getStatusCode()!= HttpStatus.NO_CONTENT_204) {
9089
LOGGER.error("Unable to fire the event: {}", response);
9190
}
92-
} catch (SocketTimeoutException e) {
93-
LOGGER.info(e.getMessage());
94-
if(!e.getMessage().equals("Read timed out")) {
91+
} catch (ProcessingException e) {
92+
if(!e.getMessage().equals("java.net.SocketTimeoutException: Read timed out")) {
9593
LOGGER.error("Failed to fire the event: {}", e);
9694
}
9795
} catch (Exception e) {

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,50 +1517,52 @@ public ApiResponse updateUser2fa(
15171517
validateResourceIdAndCheckPermission(authUser, id, user2faFactory.getUpdateScopes());
15181518
// checking param
15191519
checkParam(postRequest);
1520-
1520+
15211521
User2fa user2fa = postRequest.getParam();
15221522

1523-
if(user2fa.getEnabled() == null) {
1523+
if (user2fa.getEnabled() == null) {
15241524
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "enabled"));
15251525
}
15261526
logger.info(String.format("update user 2fa(%s) - %b", resourceId, user2fa.getEnabled()));
15271527

15281528
Long userId = Utils.toLongValue(id);
1529-
1529+
15301530
logger.info(String.format("findUserById(%s)", resourceId));
15311531
User2fa user2faInDb = userDao.findUser2faById(userId);
1532-
if(user2faInDb==null)
1532+
if (user2faInDb == null)
15331533
throw new APIRuntimeException(SC_NOT_FOUND, MSG_TEMPLATE_USER_NOT_FOUND);
1534-
1534+
15351535
Boolean shouldSendInvite = false;
1536-
if(user2faInDb.getEnabled() == null) {
1536+
if (user2faInDb.getEnabled() == null) {
15371537
userDao.insertUser2fa(userId, user2fa.getEnabled());
15381538
shouldSendInvite = user2fa.getEnabled();
1539-
} else if(!user2faInDb.getEnabled().equals(user2fa.getEnabled())) {
1539+
} else if (!user2faInDb.getEnabled().equals(user2fa.getEnabled())) {
15401540
userDao.update2fa(user2faInDb.getId(), user2fa.getEnabled(), false);
15411541
shouldSendInvite = user2fa.getEnabled();
15421542
}
15431543

15441544
if (shouldSendInvite) {
15451545
Response response;
15461546
try {
1547-
response = new Request(diceAuth.getDiceApiUrl() + "/v1/connection/submit", "POST")
1547+
response = new Request(diceAuth.getDiceApiUrl() + "/connection/invitation", "POST")
15481548
.param("emailId", user2faInDb.getEmail())
1549-
.header("x-api-key", diceAuth.getApiKey())
1549+
.header("Authorization", "Bearer " + diceAuth.getToken())
15501550
.execute();
15511551
} catch (Exception e) {
15521552
logger.error("Error when calling 2fa submit api", e);
1553+
userDao.update2fa(user2faInDb.getId(), false, false);
15531554
throw new APIRuntimeException(SC_INTERNAL_SERVER_ERROR, "Error when calling 2fa submit api");
15541555
}
15551556
if (response.getStatusCode() != HttpURLConnection.HTTP_CREATED) {
1557+
userDao.update2fa(user2faInDb.getId(), false, false);
15561558
throw new APIRuntimeException(HttpURLConnection.HTTP_INTERNAL_ERROR,
15571559
String.format("Got unexpected response from remote service. %d %s", response.getStatusCode(),
15581560
response.getMessage()));
15591561
}
15601562
logger.info(response.getText());
15611563
send2faInvitationEmailEvent(user2faInDb, diceAuth.getDiceUrl() + "/verify/" + response.getText());
15621564
}
1563-
1565+
15641566
return ApiResponseFactory.createResponse("SUCCESS");
15651567
}
15661568

@@ -1619,10 +1621,10 @@ public ApiResponse issueCredentials(
16191621
preview.set("attributes", attributes);
16201622
Response response;
16211623
try {
1622-
response = new Request(diceAuth.getDiceApiUrl()+"/v1/credentialoffer/api/credentialoffer", "POST")
1623-
.header("x-api-key", diceAuth.getApiKey())
1624-
.json(mapper.writeValueAsString(body))
1625-
.execute();
1624+
response = new Request(diceAuth.getDiceApiUrl() + "/cred/issuance/offer", "POST")
1625+
.header("Authorization", "Bearer " + diceAuth.getToken())
1626+
.json(mapper.writeValueAsString(body))
1627+
.execute();
16261628
} catch (JsonProcessingException e) {
16271629
logger.error("Error when processing JSON content", e);
16281630
throw new APIRuntimeException(SC_INTERNAL_SERVER_ERROR, "Error when calling credentialoffer api");
@@ -1635,6 +1637,9 @@ public ApiResponse issueCredentials(
16351637
String.format("Got unexpected response from remote service. %d %s", response.getStatusCode(),
16361638
response.getMessage()));
16371639
}
1640+
if (user.getVerified()) {
1641+
userDao.update2fa(user.getId(), true, false);
1642+
}
16381643
return ApiResponseFactory.createResponse("SUCCESS");
16391644
}
16401645

@@ -2098,6 +2103,7 @@ private void send2faInvitationEmailEvent(User2fa user, String inviteLink) {
20982103
Map<String,Object> data = new LinkedHashMap<String,Object>();
20992104
data.put("handle", user.getHandle());
21002105
data.put("link", inviteLink);
2106+
data.put("verifier", diceAuth.getDiceVerifier());
21012107

21022108
payload.put("data", data);
21032109

src/main/java/com/appirio/tech/core/service/identity/util/auth/DICEAuth.java

Lines changed: 149 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
package com.appirio.tech.core.service.identity.util.auth;
22

3+
import java.net.HttpURLConnection;
4+
import java.util.Date;
5+
36
import javax.validation.constraints.NotNull;
47

8+
import org.apache.log4j.Logger;
9+
10+
import com.appirio.tech.core.api.v3.exception.APIRuntimeException;
11+
import com.appirio.tech.core.api.v3.util.jwt.InvalidTokenException;
12+
import com.appirio.tech.core.service.identity.util.HttpUtil.Request;
13+
import com.appirio.tech.core.service.identity.util.HttpUtil.Response;
14+
import com.auth0.jwt.JWT;
15+
import com.auth0.jwt.exceptions.JWTDecodeException;
16+
import com.auth0.jwt.interfaces.DecodedJWT;
17+
import com.fasterxml.jackson.databind.ObjectMapper;
18+
519
public class DICEAuth {
20+
private static final Logger logger = Logger.getLogger(Auth0Client.class);
21+
622
@NotNull
723
private String diceUrl;
824

925
@NotNull
1026
private String diceApiUrl;
1127

1228
@NotNull
13-
private String apiKey;
29+
private String diceVerifier;
30+
31+
@NotNull
32+
private String tenant;
33+
34+
@NotNull
35+
private String username;
36+
37+
@NotNull
38+
private String password;
39+
40+
@NotNull
41+
private String scope;
42+
43+
@NotNull
44+
private String clientId;
45+
46+
@NotNull
47+
private String clientSecret;
1448

1549
@NotNull
1650
private String credDefId;
1751

1852
private String credPreview = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview";
1953

54+
private String cachedToken;
55+
2056
public DICEAuth() {
2157
}
2258

23-
public DICEAuth(String diceUrl, String diceApiUrl, String apiKey, String credDefId) {
59+
public DICEAuth(String diceUrl, String diceApiUrl, String diceVerifier, String tenant, String username,
60+
String password, String scope, String clientId, String clientSecret, String credDefId) {
2461
this.diceUrl = diceUrl;
2562
this.diceApiUrl = diceApiUrl;
26-
this.apiKey = apiKey;
63+
this.diceVerifier = diceVerifier;
64+
this.tenant = tenant;
65+
this.username = username;
66+
this.password = password;
67+
this.scope = scope;
68+
this.clientId = clientId;
69+
this.clientSecret = clientSecret;
2770
this.credDefId = credDefId;
2871
}
2972

@@ -43,12 +86,60 @@ public void setDiceApiUrl(String diceApiUrl) {
4386
this.diceApiUrl = diceApiUrl;
4487
}
4588

46-
public String getApiKey() {
47-
return apiKey;
89+
public String getDiceVerifier() {
90+
return diceVerifier;
91+
}
92+
93+
public void setDiceVerifier(String diceVerifier) {
94+
this.diceVerifier = diceVerifier;
95+
}
96+
97+
public String getTenant() {
98+
return tenant;
99+
}
100+
101+
public void setTenant(String tenant) {
102+
this.tenant = tenant;
48103
}
49104

50-
public void setApiKey(String apiKey) {
51-
this.apiKey = apiKey;
105+
public String getUsername() {
106+
return username;
107+
}
108+
109+
public void setUsername(String username) {
110+
this.username = username;
111+
}
112+
113+
public String getPassword() {
114+
return password;
115+
}
116+
117+
public void setPassword(String password) {
118+
this.password = password;
119+
}
120+
121+
public String getScope() {
122+
return scope;
123+
}
124+
125+
public void setScope(String scope) {
126+
this.scope = scope;
127+
}
128+
129+
public String getClientId() {
130+
return clientId;
131+
}
132+
133+
public void setClientId(String clientId) {
134+
this.clientId = clientId;
135+
}
136+
137+
public String getClientSecret() {
138+
return clientSecret;
139+
}
140+
141+
public void setClientSecret(String clientSecret) {
142+
this.clientSecret = clientSecret;
52143
}
53144

54145
public String getCredDefId() {
@@ -66,4 +157,55 @@ public String getCredPreview() {
66157
public void setCredPreview(String credPreview) {
67158
this.credPreview = credPreview;
68159
}
160+
161+
public String getToken() throws Exception {
162+
Boolean isCachedTokenExpired = false;
163+
if (cachedToken != null) {
164+
if (getTokenExpiryTime(cachedToken) <= 0) {
165+
isCachedTokenExpired = true;
166+
logger.info("Application cached token expired");
167+
}
168+
}
169+
if (cachedToken == null || isCachedTokenExpired) {
170+
Response response = new Request(
171+
"https://login.microsoftonline.com/" + getTenant() + "/oauth2/v2.0/token", "POST")
172+
.param("grant_type", "password")
173+
.param("username", getUsername())
174+
.param("password", getPassword())
175+
.param("scope", getScope())
176+
.param("client_id", getClientId())
177+
.param("client_secret", getClientSecret()).execute();
178+
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
179+
throw new APIRuntimeException(HttpURLConnection.HTTP_INTERNAL_ERROR,
180+
String.format("Got unexpected response from remote service. %d %s", response.getStatusCode(),
181+
response.getText()));
182+
}
183+
cachedToken = new ObjectMapper().readValue(response.getText(), Auth0Credential.class).getIdToken();
184+
}
185+
return cachedToken;
186+
}
187+
188+
/**
189+
* Get token expiry time in seconds
190+
*
191+
* @param token JWT token
192+
* throws Exception if any error occurs
193+
* @return the Integer result
194+
*/
195+
private Integer getTokenExpiryTime(String token) throws Exception {
196+
DecodedJWT decodedJWT = null;
197+
Integer tokenExpiryTime = 0;
198+
if (token != null) {
199+
try {
200+
decodedJWT = JWT.decode(token);
201+
} catch (JWTDecodeException e) {
202+
throw new InvalidTokenException(token, "Error occurred in decoding token. " + e.getLocalizedMessage(),
203+
e);
204+
}
205+
Date tokenExpiryDate = decodedJWT.getExpiresAt();
206+
Long tokenExpiryTimeInMilliSeconds = tokenExpiryDate.getTime() - (new Date().getTime()) - 60 * 1000;
207+
tokenExpiryTime = (int) Math.floor(tokenExpiryTimeInMilliSeconds / 1000);
208+
}
209+
return tokenExpiryTime;
210+
}
69211
}

src/main/resources/config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ auth0New:
9595
diceAuth:
9696
diceUrl: @diceAuth.diceUrl@
9797
diceApiUrl: @diceAuth.diceApiUrl@
98-
apiKey: @diceAuth.apiKey@
98+
diceVerifier: @diceAuth.diceVerifier@
99+
clientId: @diceAuth.clientId@
100+
clientSecret: @diceAuth.clientSecret@
101+
password: @diceAuth.password@
102+
scope: @diceAuth.scope@
103+
tenant: @diceAuth.tenant@
104+
username: @diceAuth.username@
99105
credDefId: @diceAuth.credDefId@
100106

101107
# Authorized accounts

src/main/resources/config.yml.localdev

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ auth0New:
8787

8888
diceAuth:
8989
diceUrl: dummy
90-
apiKey: dummy
90+
diceApiUrl: dummy
91+
diceVerifier: dummy
92+
clientId: dummy
93+
clientSecret: dummy
94+
password: dummy
95+
scope: dummy
96+
tenant: dummy
97+
username: dummy
9198
credDefId: dummy
9299

93100
# LDAP Settings

token.properties.localdev

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232

3333
@diceAuth.diceUrl@=dummy
3434
@diceAuth.diceApiUrl@=dummy
35-
@diceAuth.apiKey@=dummy
35+
@diceAuth.diceVerifier@=dummy
36+
@diceAuth.clientId@=dummy
37+
@diceAuth.clientSecret@=dummy
38+
@diceAuth.password@=dummy
39+
@diceAuth.scope@=dummy
40+
@diceAuth.tenant@=dummy
41+
@diceAuth.username@=dummy
3642
@diceAuth.credDefId@=dummy
3743

3844
@zendesk.secret@=ZENDESK_SECRET

0 commit comments

Comments
 (0)