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

Commit 8ddbb52

Browse files
authored
Merge pull request #88 from appirio-tech/feature/slack
Feature/slack
2 parents 79ea783 + b9b4efa commit 8ddbb52

File tree

7 files changed

+64
-5
lines changed

7 files changed

+64
-5
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ workflows:
146146
context : org-global
147147
filters:
148148
branches:
149-
only: [dev, 'feature/jira-plat-152', 'auth0-kt']
149+
only: [dev, 'feature/jira-plat-152', 'update-keystore']
150150
# Production build is executed on "master" branch only.
151151
- "build-prod":
152152
context : org-global

build/build-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ echo "[CHECK THIS IS CORRECT] application domain: ${APPDOMAIN}"
9090

9191
echo "copying LDAP keystore file"
9292
#cp /mnt/ebs/deploy/topcoder/ap-identity/conf/$CONFIG/TC.prod.ldap.keystore $DOCKER_DIR/TC.prod.ldap.keystore
93-
aws s3 cp s3://appirio-platform-$CONFIG/application/tc-api-core/$CONFIG/TC.prod.ldap.keystore $DOCKER_DIR/TC.prod.ldap.keystore
93+
aws s3 cp s3://appirio-platform-$CONFIG/application/tc-api-core/$CONFIG/TC.prod.ldap.new.keystore $DOCKER_DIR/TC.prod.ldap.keystore
9494

9595
echo "copying environment-specific resources"
9696
cat $WORK_DIR/config/sumo-template.conf | sed -e "s/@APINAME@/${SERVICE}/g" | sed -e "s/@CONFIG@/${CONFIG}/g" > $DOCKER_DIR/sumo.conf

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: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public class UserResource implements GetResource<User>, DDLResource<User> {
128128

129129
private String domain;
130130

131+
private String domainEnv;
132+
131133
private String sendgridTemplateId;
132134

133135
private String sendgridWelcomeTemplateId;
@@ -1649,11 +1651,13 @@ public ApiResponse updateUser2fa(
16491651
throw new APIRuntimeException(SC_BAD_REQUEST, "You have multiple accounts registered with same email. Please contact with support.");
16501652
}
16511653
}
1654+
Boolean oldMfaStatus = user2faInDb.getMfaEnabled() == null ? false : user2faInDb.getMfaEnabled();
1655+
Boolean oldDiceStatus = user2faInDb.getDiceEnabled() == null ? false : user2faInDb.getDiceEnabled();
16521656
if (user2fa.getMfaEnabled() == null) {
1653-
user2fa.setMfaEnabled(user2faInDb.getMfaEnabled() == null ? false : user2faInDb.getMfaEnabled());
1657+
user2fa.setMfaEnabled(oldMfaStatus);
16541658
}
16551659
if (user2fa.getDiceEnabled() == null) {
1656-
user2fa.setDiceEnabled(user2faInDb.getDiceEnabled() == null ? false : user2faInDb.getDiceEnabled());
1660+
user2fa.setDiceEnabled(oldDiceStatus);
16571661
}
16581662
if (user2faInDb.getId() == null) {
16591663
long newId = userDao.insertUser2fa(userId, user2fa.getMfaEnabled(), user2fa.getDiceEnabled(),
@@ -1665,6 +1669,9 @@ public ApiResponse updateUser2fa(
16651669
user2fa.getDiceEnabled(), Utils.toLongValue(authUser.getUserId()));
16661670
user2faInDb = userDao.findUser2faById(user2faInDb.getId());
16671671
}
1672+
if (!oldDiceStatus.equals(user2faInDb.getDiceEnabled())) {
1673+
sendSlackNotification(user2faInDb.getHandle(), null, user2faInDb.getDiceEnabled() ? "DICE enabled" : "DICE disabled");
1674+
}
16681675
return ApiResponseFactory.createResponse(user2faInDb);
16691676
}
16701677

@@ -1703,6 +1710,7 @@ public ApiResponse getDiceConnection(
17031710
diceConnection.setCreatedAt(diceAttributes.getDiceConnectionCreatedAt());
17041711
diceConnection.setConnection(diceAuth.getDiceApiUrl() + "/web/connection/inviteurl/"
17051712
+ diceAttributes.getDiceConnection());
1713+
sendSlackNotification(diceAttributes.getHandle(), diceAttributes.getEmail(), "Reusing DICE connection");
17061714
return ApiResponseFactory.createResponse(diceConnection);
17071715
}
17081716
}
@@ -1731,6 +1739,7 @@ public ApiResponse getDiceConnection(
17311739
diceConnection.setId(newId);
17321740
diceConnection.setConnection(diceAuth.getDiceApiUrl() + "/web/connection/inviteurl/" + connectionId);
17331741
diceConnection.setAccepted(false);
1742+
sendSlackNotification(diceAttributes.getHandle(), diceAttributes.getEmail(), "Created new DICE connection");
17341743
return ApiResponseFactory.createResponse(diceConnection);
17351744
}
17361745

@@ -1847,6 +1856,7 @@ public ApiResponse issueCredentials(
18471856
response.getMessage()));
18481857
}
18491858
userDao.updateDiceConnectionStatus(user.getDiceConnectionId(), true);
1859+
sendSlackNotification(user.getHandle(), user.getEmail(), "DICE connection accepted");
18501860
return ApiResponseFactory.createResponse("SUCCESS");
18511861
}
18521862

@@ -2298,6 +2308,7 @@ public String getDomain() {
22982308

22992309
public void setDomain(String domain) {
23002310
this.domain = domain;
2311+
this.domainEnv = domain.toLowerCase().contains("dev") ? "DEV" : domain.toLowerCase().contains("qa") ? "QA" : "PROD";
23012312
}
23022313

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

24592485
protected NotificationPayload createActivationNotificationPayload(User user, String redirectUrl) {
24602486
//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)