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

Commit 153698c

Browse files
committed
send slack notification
1 parent 8b885b7 commit 153698c

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

buildtokenproperties.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ DICEAUTH_DICE_API_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_URL")
1919
DICEAUTH_DICE_API_KEY=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_KEY")
2020
DICEAUTH_CREDDEFID=$(eval "echo \$${ENV}_DICEAUTH_CREDDEFID")
2121
DICEAUTH_OTP_DURATION=$(eval "echo \$${ENV}_DICEAUTH_OTP_DURATION")
22+
SLACK_BOT_KEY=$(eval "echo \$${ENV}_SLACK_BOT_KEY")
23+
SLACK_CHANNEL_ID=$(eval "echo \$${ENV}_SLACK_CHANNEL_ID")
2224
ZENDESK_ID=$(eval "echo \$${ENV}_ZENDESK_ID")
2325
SERVICEACC02_UID=$(eval "echo \$${ENV}_SERVICEACC02_UID")
2426
AUTH_SECRET=$(eval "echo \$${ENV}_AUTH_SECRET")
@@ -92,6 +94,8 @@ perl -pi -e "s|\{\{DICEAUTH_DICE_API_URL\}\}|$DICEAUTH_DICE_API_URL|g" $CONFFILE
9294
perl -pi -e "s|\{\{DICEAUTH_DICE_API_KEY\}\}|$DICEAUTH_DICE_API_KEY|g" $CONFFILENAME
9395
perl -pi -e "s/\{\{DICEAUTH_CREDDEFID\}\}/$DICEAUTH_CREDDEFID/g" $CONFFILENAME
9496
perl -pi -e "s/\{\{DICEAUTH_OTP_DURATION\}\}/$DICEAUTH_OTP_DURATION/g" $CONFFILENAME
97+
perl -pi -e "s|\{\{SLACK_BOT_KEY\}\}|$SLACK_BOT_KEY|g" $CONFFILENAME
98+
perl -pi -e "s|\{\{SLACK_CHANNEL_ID\}\}|$SLACK_CHANNEL_ID|g" $CONFFILENAME
9599
perl -pi -e "s/\{\{ZENDESK_KEY\}\}/$ZENDESK_KEY/g" $CONFFILENAME
96100
perl -pi -e "s/\{\{ZENDESK_ID\}\}/$ZENDESK_ID/g" $CONFFILENAME
97101
perl -pi -e "s/\{\{SERVICEACC01_CID\}\}/$SERVICEACC01_CID/g" $CONFFILENAME

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,11 +1649,13 @@ public ApiResponse updateUser2fa(
16491649
throw new APIRuntimeException(SC_BAD_REQUEST, "You have multiple accounts registered with same email. Please contact with support.");
16501650
}
16511651
}
1652+
Boolean oldMfaStatus = user2faInDb.getMfaEnabled() == null ? false : user2faInDb.getMfaEnabled();
1653+
Boolean oldDiceStatus = user2faInDb.getDiceEnabled() == null ? false : user2faInDb.getDiceEnabled();
16521654
if (user2fa.getMfaEnabled() == null) {
1653-
user2fa.setMfaEnabled(user2faInDb.getMfaEnabled() == null ? false : user2faInDb.getMfaEnabled());
1655+
user2fa.setMfaEnabled(oldMfaStatus);
16541656
}
16551657
if (user2fa.getDiceEnabled() == null) {
1656-
user2fa.setDiceEnabled(user2faInDb.getDiceEnabled() == null ? false : user2faInDb.getDiceEnabled());
1658+
user2fa.setDiceEnabled(oldDiceStatus);
16571659
}
16581660
if (user2faInDb.getId() == null) {
16591661
long newId = userDao.insertUser2fa(userId, user2fa.getMfaEnabled(), user2fa.getDiceEnabled(),
@@ -1665,6 +1667,9 @@ public ApiResponse updateUser2fa(
16651667
user2fa.getDiceEnabled(), Utils.toLongValue(authUser.getUserId()));
16661668
user2faInDb = userDao.findUser2faById(user2faInDb.getId());
16671669
}
1670+
if (!oldDiceStatus.equals(user2faInDb.getDiceEnabled())) {
1671+
sendSlackNotification(user2faInDb.getHandle(), null, user2faInDb.getDiceEnabled() ? "DICE enabled" : "DICE disabled");
1672+
}
16681673
return ApiResponseFactory.createResponse(user2faInDb);
16691674
}
16701675

@@ -1703,6 +1708,7 @@ public ApiResponse getDiceConnection(
17031708
diceConnection.setCreatedAt(diceAttributes.getDiceConnectionCreatedAt());
17041709
diceConnection.setConnection(diceAuth.getDiceApiUrl() + "/web/connection/inviteurl/"
17051710
+ diceAttributes.getDiceConnection());
1711+
sendSlackNotification(diceAttributes.getHandle(), diceAttributes.getEmail(), "Reusing DICE connection");
17061712
return ApiResponseFactory.createResponse(diceConnection);
17071713
}
17081714
}
@@ -1731,6 +1737,7 @@ public ApiResponse getDiceConnection(
17311737
diceConnection.setId(newId);
17321738
diceConnection.setConnection(diceAuth.getDiceApiUrl() + "/web/connection/inviteurl/" + connectionId);
17331739
diceConnection.setAccepted(false);
1740+
sendSlackNotification(diceAttributes.getHandle(), diceAttributes.getEmail(), "Created new DICE connection");
17341741
return ApiResponseFactory.createResponse(diceConnection);
17351742
}
17361743

@@ -1847,6 +1854,7 @@ public ApiResponse issueCredentials(
18471854
response.getMessage()));
18481855
}
18491856
userDao.updateDiceConnectionStatus(user.getDiceConnectionId(), true);
1857+
sendSlackNotification(user.getHandle(), user.getEmail(), "DICE connection accepted");
18501858
return ApiResponseFactory.createResponse("SUCCESS");
18511859
}
18521860

@@ -2455,6 +2463,21 @@ private void sendWelcomeEmailEvent(User user) {
24552463
logger.error("Error occured while publishing the events to new kafka.");
24562464
}
24572465
}
2466+
2467+
private void sendSlackNotification(String handle, String email, String message) {
2468+
ObjectMapper mapper = new ObjectMapper();
2469+
ObjectNode body = mapper.createObjectNode();
2470+
body.put("channel", diceAuth.getSlackChannelId());
2471+
body.put("text", String.format("%s%s : %s", handle, email == null ? "" : String.format(" (%s)", email) , message));
2472+
try {
2473+
new Request("https://slack.com/api/chat.postMessage", "POST")
2474+
.header("Authorization", "Bearer " + diceAuth.getSlackKey())
2475+
.json(mapper.writeValueAsString(body))
2476+
.execute();
2477+
} catch (Exception e) {
2478+
logger.error("Error when calling slack bot", e);
2479+
}
2480+
}
24582481

24592482
protected NotificationPayload createActivationNotificationPayload(User user, String redirectUrl) {
24602483
//If for Connect registration, send activation email with activation code only.

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ public class DICEAuth {
1616
@NotNull
1717
private Integer otpDuration;
1818

19+
@NotNull
20+
private String slackKey;
21+
22+
@NotNull
23+
private String slackChannelId;
24+
1925
private String credPreview = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview";
2026

2127
public DICEAuth() {
2228
}
2329

24-
public DICEAuth(String diceApiUrl, String diceApiKey, String credDefId, Integer otpDuration) {
30+
public DICEAuth(String diceApiUrl, String diceApiKey, String credDefId, Integer otpDuration, String slackKey,
31+
String slackChannelId) {
2532
this.diceApiUrl = diceApiUrl;
2633
this.diceApiKey = diceApiKey;
2734
this.credDefId = credDefId;
2835
this.otpDuration = otpDuration;
36+
this.slackKey = slackKey;
37+
this.slackChannelId = slackChannelId;
2938
}
3039

3140
public String getDiceApiUrl() {
@@ -67,4 +76,20 @@ public String getCredPreview() {
6776
public void setCredPreview(String credPreview) {
6877
this.credPreview = credPreview;
6978
}
79+
80+
public String getSlackKey() {
81+
return slackKey;
82+
}
83+
84+
public void setSlackKey(String slackKey) {
85+
this.slackKey = slackKey;
86+
}
87+
88+
public String getSlackChannelId() {
89+
return slackChannelId;
90+
}
91+
92+
public void setSlackChannelId(String slackChannelId) {
93+
this.slackChannelId = slackChannelId;
94+
}
7095
}

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ diceAuth:
9898
diceApiKey: @diceAuth.diceApiKey@
9999
credDefId: @diceAuth.credDefId@
100100
otpDuration: @diceAuth.otpDuration@
101+
slackKey: @diceAuth.slackKey@
102+
slackChannelId: @diceAuth.slackChannelId@
101103

102104
# Authorized accounts
103105
serviceAccount:

token.properties.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
@diceAuth.diceApiKey@={{DICEAUTH_DICE_API_KEY}}
5656
@diceAuth.credDefId@={{DICEAUTH_CREDDEFID}}
5757
@diceAuth.otpDuration@={{DICEAUTH_OTP_DURATION}}
58+
@diceAuth.slackKey@={{SLACK_BOT_KEY}}
59+
@diceAuth.slackChannelId@={{SLACK_CHANNEL_ID}}
5860

5961
@zendesk.secret@={{ZENDESK_KEY}}
6062
@zendesk.idprefix@={{ZENDESK_ID}}

0 commit comments

Comments
 (0)