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

Commit 0c10748

Browse files
authored
Merge pull request #79 from appirio-tech/dev
DICE Integration
2 parents 8eaef01 + a72750a commit 0c10748

File tree

22 files changed

+906
-16
lines changed

22 files changed

+906
-16
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']
149+
only: [dev, 'feature/jira-plat-152', 'auth0-kt']
150150
# Production build is executed on "master" branch only.
151151
- "build-prod":
152152
context : org-global

build/build-image.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ VER=`date "+%Y%m%d%H%M"`
2525
# }
2626

2727
# configure_aws_cli
28-
aws s3 cp "s3://appirio-platform-$CONFIG/services/common/dockercfg" ~/.dockercfg
28+
# aws s3 cp "s3://appirio-platform-$CONFIG/services/common/dockercfg" ~/.dockercfg
2929

3030
# Elastic Beanstalk Application name
3131
# dev
@@ -97,6 +97,12 @@ cat $WORK_DIR/config/sumo-template.conf | sed -e "s/@APINAME@/${SERVICE}/g" | se
9797
cat $WORK_DIR/config/sumo-sources-template.json | sed -e "s/@APINAME@/${SERVICE}/g" | sed -e "s/@CONFIG@/${CONFIG}/g" > $DOCKER_DIR/sumo-sources.json
9898
cat $WORK_DIR/config/newrelic-template.yml | sed -e "s/@APINAME@/${SERVICE}/g" | sed -e "s/@CONFIG@/${CONFIG}/g" > $DOCKER_DIR/newrelic.yml
9999

100+
echo "Logging into docker"
101+
echo "############################"
102+
DOCKER_USER=$(aws ssm get-parameter --name /$CONFIG/build/dockeruser --with-decryption --output text --query Parameter.Value)
103+
DOCKER_PASSWD=$(aws ssm get-parameter --name /$CONFIG/build/dockercfg --with-decryption --output text --query Parameter.Value)
104+
echo $DOCKER_PASSWD | docker login -u $DOCKER_USER --password-stdin
105+
100106
echo "building docker image: ${IMAGE}"
101107
docker build -t $TAG $DOCKER_DIR
102108
handle_error "docker build failed."

buildtokenproperties.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ AUTH0_NEW_ID=$(eval "echo \$${ENV}_AUTH0_NEW_ID")
1515
AUTH0_NEW_ID_SECRET=$(eval "echo \$${ENV}_AUTH0_NEW_ID_SECRET")
1616
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")
18+
DICEAUTH_DICE_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_URL")
19+
DICEAUTH_DICE_API_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_URL")
20+
DICEAUTH_DICE_VERIFIER=$(eval "echo \$${ENV}_DICEAUTH_DICE_VERIFIER")
21+
DICEAUTH_DICE_API_KEY=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_KEY")
22+
DICEAUTH_CREDDEFID=$(eval "echo \$${ENV}_DICEAUTH_CREDDEFID")
23+
DICEAUTH_OTP_DURATION=$(eval "echo \$${ENV}_DICEAUTH_OTP_DURATION")
1824
ZENDESK_ID=$(eval "echo \$${ENV}_ZENDESK_ID")
1925
SERVICEACC02_UID=$(eval "echo \$${ENV}_SERVICEACC02_UID")
2026
AUTH_SECRET=$(eval "echo \$${ENV}_AUTH_SECRET")
@@ -33,6 +39,9 @@ M2MAUTHCONFIG_USERPROFILES_CREATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFIL
3339
M2MAUTHCONFIG_USERPROFILES_UPDATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_UPDATE")
3440
M2MAUTHCONFIG_USERPROFILES_READ=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_READ")
3541
M2MAUTHCONFIG_USERPROFILES_DELETE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_DELETE")
42+
M2MAUTHCONFIG_USER2FA_ENABLE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_ENABLE")
43+
M2MAUTHCONFIG_USER2FA_VERIFY=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_VERIFY")
44+
M2MAUTHCONFIG_USER2FA_CREDENTIAL=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_CREDENTIAL")
3645

3746
DOMAIN=$(eval "echo \$${ENV}_DOMAIN")
3847
SMTP=$(eval "echo \$${ENV}_SMTP")
@@ -47,6 +56,8 @@ SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_RESE
4756
SENDGRID_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_WELCOME_EMAIL_TEMPLATE_ID")
4857
SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID")
4958
SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID")
59+
SENDGRID_2FA_INVITATION_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_2FA_INVITATION_TEMPLATE_ID")
60+
SENDGRID_2FA_OTP_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_2FA_OTP_TEMPLATE_ID")
5061

5162

5263
if [[ -z "$ENV" ]] ; then
@@ -79,6 +90,12 @@ perl -pi -e "s/\{\{AUTH0_NEW_ID\}\}/$AUTH0_NEW_ID/g" $CONFFILENAME
7990
perl -pi -e "s/\{\{AUTH0_NEW_ID_SECRET\}\}/$AUTH0_NEW_ID_SECRET/g" $CONFFILENAME
8091
perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID\}\}/$AUTH0_NEW_NONINTERACTIVE_ID/g" $CONFFILENAME
8192
perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID_SECRET\}\}/$AUTH0_NEW_NONINTERACTIVE_ID_SECRET/g" $CONFFILENAME
93+
perl -pi -e "s|\{\{DICEAUTH_DICE_URL\}\}|$DICEAUTH_DICE_URL|g" $CONFFILENAME
94+
perl -pi -e "s|\{\{DICEAUTH_DICE_API_URL\}\}|$DICEAUTH_DICE_API_URL|g" $CONFFILENAME
95+
perl -pi -e "s|\{\{DICEAUTH_DICE_VERIFIER\}\}|$DICEAUTH_DICE_VERIFIER|g" $CONFFILENAME
96+
perl -pi -e "s|\{\{DICEAUTH_DICE_API_KEY\}\}|$DICEAUTH_DICE_API_KEY|g" $CONFFILENAME
97+
perl -pi -e "s/\{\{DICEAUTH_CREDDEFID\}\}/$DICEAUTH_CREDDEFID/g" $CONFFILENAME
98+
perl -pi -e "s/\{\{DICEAUTH_OTP_DURATION\}\}/$DICEAUTH_OTP_DURATION/g" $CONFFILENAME
8299
perl -pi -e "s/\{\{ZENDESK_KEY\}\}/$ZENDESK_KEY/g" $CONFFILENAME
83100
perl -pi -e "s/\{\{ZENDESK_ID\}\}/$ZENDESK_ID/g" $CONFFILENAME
84101
perl -pi -e "s/\{\{SERVICEACC01_CID\}\}/$SERVICEACC01_CID/g" $CONFFILENAME
@@ -109,9 +126,14 @@ perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_CREATE\}\}|$M2MAUTHCONFIG_USERPROF
109126
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_UPDATE\}\}|$M2MAUTHCONFIG_USERPROFILES_UPDATE|g" $CONFFILENAME
110127
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_READ\}\}|$M2MAUTHCONFIG_USERPROFILES_READ|g" $CONFFILENAME
111128
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROFILES_DELETE|g" $CONFFILENAME
129+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_ENABLE\}\}|$M2MAUTHCONFIG_USER2FA_ENABLE|g" $CONFFILENAME
130+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_VERIFY\}\}|$M2MAUTHCONFIG_USER2FA_VERIFY|g" $CONFFILENAME
131+
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_CREDENTIAL\}\}|$M2MAUTHCONFIG_USER2FA_CREDENTIAL|g" $CONFFILENAME
112132
perl -pi -e "s/\{\{AUTH0_NEW_DOMAIN\}\}/$AUTH0_NEW_DOMAIN/g" $CONFFILENAME
113133
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME
114134
perl -pi -e "s/\{\{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
115135
perl -pi -e "s/\{\{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
116136
perl -pi -e "s/\{\{SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
117137
perl -pi -e "s/\{\{SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
138+
perl -pi -e "s/\{\{SENDGRID_2FA_INVITATION_TEMPLATE_ID\}\}/$SENDGRID_2FA_INVITATION_TEMPLATE_ID/g" $CONFFILENAME
139+
perl -pi -e "s/\{\{SENDGRID_2FA_OTP_TEMPLATE_ID\}\}/$SENDGRID_2FA_OTP_TEMPLATE_ID/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/IdentityApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,16 @@ public void run(IdentityConfiguration configuration, Environment environment) th
234234
configuration.getEventBusServiceClientConfig(), configuration.getM2mAuthConfiguration());
235235
// Resources::users
236236
CacheService cacheService = configuration.getCache().createCacheService();
237-
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles());
237+
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles(), configuration.getM2mAuthConfiguration().getUser2fa());
238238
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
239+
userResource.setDiceAuth(configuration.getDiceAuth());
239240
userResource.setDomain(configuration.getAuthDomain());
240241
userResource.setSendgridTemplateId(Utils.getString("sendGridTemplateId"));
241242
userResource.setSendgridWelcomeTemplateId(Utils.getString("sendGridWelcomeTemplateId"));
242243
userResource.setSendgridSelfServiceTemplateId(Utils.getString("sendGridSelfServiceTemplateId"));
243244
userResource.setSendgridSelfServiceWelcomeTemplateId(Utils.getString("sendGridSelfServiceWelcomeTemplateId"));
245+
userResource.setSendgrid2faInvitationTemplateId(Utils.getString("sendGrid2faInvitationTemplateId"));
246+
userResource.setSendgrid2faOtpTemplateId(Utils.getString("sendGrid2faOtpTemplateId"));
244247
// this secret _used_ to be different from the one used in AuthorizationResource.
245248
// it _was_ the secret x2. (userResource.setSecret(getSecret()+getSecret());)
246249
// we assume this was done to further limit the usability of the oneTimeToken generated in userResource

src/main/java/com/appirio/tech/core/service/identity/IdentityConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.appirio.clients.BaseClientConfiguration;
1212
import com.appirio.tech.core.api.v3.dropwizard.APIBaseConfiguration;
1313
import com.appirio.tech.core.service.identity.util.auth.Auth0Client;
14+
import com.appirio.tech.core.service.identity.util.auth.DICEAuth;
1415
import com.appirio.tech.core.service.identity.util.auth.ServiceAccountAuthenticatorFactory;
1516
import com.appirio.tech.core.service.identity.util.cache.CacheServiceFactory;
1617
import com.appirio.tech.core.service.identity.util.event.EventSystemFactory;
@@ -61,6 +62,10 @@ public class IdentityConfiguration extends APIBaseConfiguration {
6162
@Valid
6263
@JsonProperty
6364
private Auth0Client auth0New = new Auth0Client();
65+
66+
@Valid
67+
@JsonProperty
68+
private DICEAuth diceAuth = new DICEAuth();
6469

6570
@Valid
6671
@NotNull
@@ -135,6 +140,10 @@ public Auth0Client getAuth0() {
135140
public Auth0Client getAuth0New() {
136141
return auth0New;
137142
}
143+
144+
public DICEAuth getDiceAuth() {
145+
return diceAuth;
146+
}
138147

139148
public LDAPServiceFactory getLdap() {
140149
return ldap;

src/main/java/com/appirio/tech/core/service/identity/M2mAuthConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.appirio.tech.core.service.identity;
22

3+
import com.appirio.tech.core.service.identity.util.m2mscope.User2faFactory;
34
import com.appirio.tech.core.service.identity.util.m2mscope.UserProfilesFactory;
45
import com.fasterxml.jackson.annotation.JsonProperty;
56
import javax.validation.constraints.NotNull;
@@ -65,6 +66,9 @@ public class M2mAuthConfiguration {
6566
@JsonProperty
6667
private UserProfilesFactory userProfiles = new UserProfilesFactory();
6768

69+
@JsonProperty
70+
private User2faFactory user2fa = new User2faFactory();
71+
6872
public UserProfilesFactory getUserProfiles() {
6973
return userProfiles;
7074
}
@@ -73,6 +77,14 @@ public void setUserProfiles(UserProfilesFactory userProfiles) {
7377
this.userProfiles = userProfiles;
7478
}
7579

80+
public User2faFactory getUser2fa() {
81+
return user2fa;
82+
}
83+
84+
public void setUser2fa(User2faFactory user2fa) {
85+
this.user2fa = user2fa;
86+
}
87+
7688
/**
7789
* Get clientId
7890
*

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

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

12+
import javax.ws.rs.ProcessingException;
1213
import javax.ws.rs.client.Client;
1314
import javax.ws.rs.client.Entity;
1415
import javax.ws.rs.client.Invocation;
@@ -81,13 +82,17 @@ public void reFireEvent(EventMessage eventMessage) {
8182
String authToken = Utils.generateAuthToken(m2mAuthConfiguration);
8283

8384
eventMessage.setOriginator(this.config.getAdditionalConfiguration().get("originator"));
85+
LOGGER.info("Fire event {}", new ObjectMapper().writer().writeValueAsString(eventMessage));
8486
Response response = request.header("Authorization", "Bearer " + authToken).post(Entity.entity(eventMessage.getData(), MediaType.APPLICATION_JSON_TYPE));
8587

86-
LOGGER.info("Fire event {}", new ObjectMapper().writer().writeValueAsString(eventMessage));
8788
if (response.getStatusInfo().getStatusCode() != HttpStatus.OK_200 && response.getStatusInfo().getStatusCode()!= HttpStatus.NO_CONTENT_204) {
8889
LOGGER.error("Unable to fire the event: {}", response);
8990
}
90-
} catch (Exception e) {
91+
} catch (ProcessingException e) {
92+
if(!e.getMessage().equals("java.net.SocketTimeoutException: Read timed out")) {
93+
LOGGER.error("Failed to fire the event: {}", e);
94+
}
95+
} catch (Exception e) {
9196
LOGGER.error("Failed to fire the event: {}", e);
9297
}
9398
}

src/main/java/com/appirio/tech/core/service/identity/dao/UserDAO.java

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.appirio.tech.core.service.identity.representation.Achievement;
3737
import com.appirio.tech.core.service.identity.representation.Country;
3838
import com.appirio.tech.core.service.identity.representation.Credential;
39+
import com.appirio.tech.core.service.identity.representation.User2fa;
3940
import com.appirio.tech.core.service.identity.representation.Email;
4041
import com.appirio.tech.core.service.identity.representation.GroupMembership;
4142
import com.appirio.tech.core.service.identity.representation.ProviderType;
@@ -96,47 +97,109 @@ public abstract class UserDAO implements DaoBase<User>, Transactional<UserDAO> {
9697
@RegisterMapperFactory(TCBeanMapperFactory.class)
9798
@SqlQuery(
9899
"SELECT " + USER_COLUMNS + ", " +
99-
"s.password AS credential$encodedPassword, e.address AS email, e.status_id AS emailStatus " +
100+
"s.password AS credential$encodedPassword, e.address AS email, e.status_id AS emailStatus, " +
101+
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
100102
"FROM common_oltp.user AS u " +
101103
"LEFT OUTER JOIN common_oltp.email AS e ON u.user_id = e.user_id AND e.email_type_id = 1 AND e.primary_ind = 1 " +
102104
"LEFT OUTER JOIN common_oltp.security_user AS s ON u.user_id = s.login_id " +
105+
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
103106
"WHERE u.user_id = :id"
104107
)
105108
public abstract User findUserById(@Bind("id") long id);
106109

107110
@RegisterMapperFactory(TCBeanMapperFactory.class)
108111
@SqlQuery(
109112
"SELECT " + USER_COLUMNS + ", " +
110-
"e.address AS email, e.status_id AS emailStatus " +
113+
"e.address AS email, e.status_id AS emailStatus, " +
114+
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
111115
"FROM common_oltp.user AS u " +
112116
"LEFT OUTER JOIN common_oltp.email AS e ON u.user_id = e.user_id AND e.email_type_id = 1 " +
117+
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
113118
"WHERE u.handle_lower = LOWER(:handle)"
114119
)
115120
public abstract User findUserByHandle(@Bind("handle") String handle);
116121

117122
@RegisterMapperFactory(TCBeanMapperFactory.class)
118123
@SqlQuery(
119124
"SELECT " + USER_COLUMNS + ", " +
120-
"e.address AS email, e.status_id AS emailStatus " +
125+
"e.address AS email, e.status_id AS emailStatus, " +
126+
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
121127
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
128+
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
122129
"WHERE LOWER(e.address) = LOWER(:email)"
123130
)
124131
public abstract List<User> findUsersByEmail(@Bind("email") String email);
125132

133+
@RegisterMapperFactory(TCBeanMapperFactory.class)
134+
@SqlQuery(
135+
"SELECT mfa.id AS id, u.user_id AS userId, u.handle AS handle, u.first_name AS firstName, e.address AS email, mfa.enabled AS enabled, mfa.verified AS verified " +
136+
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
137+
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
138+
"WHERE LOWER(e.address) = LOWER(:email)"
139+
)
140+
public abstract List<User2fa> findUser2faByEmail(@Bind("email") String email);
141+
142+
@RegisterMapperFactory(TCBeanMapperFactory.class)
143+
@SqlQuery(
144+
"SELECT mfa.id AS id, u.user_id AS userId, u.handle AS handle, u.first_name AS firstName, e.address AS email, mfa.enabled AS enabled, mfa.verified AS verified " +
145+
"FROM common_oltp.user AS u LEFT JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
146+
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
147+
"WHERE u.user_id = :userId"
148+
)
149+
public abstract User2fa findUser2faById(@Bind("userId") long userId);
150+
151+
@SqlUpdate(
152+
"INSERT INTO common_oltp.user_2fa " +
153+
"(user_id, enabled) VALUES " +
154+
"(:userId, :enabled)")
155+
public abstract int insertUser2fa(@Bind("userId") long userId, @Bind("enabled") boolean enabled);
156+
157+
@SqlUpdate(
158+
"UPDATE common_oltp.user_2fa SET " +
159+
"enabled=:enabled, " +
160+
"verified=:verified " +
161+
"WHERE id=:id")
162+
public abstract int update2fa(@Bind("id") long id, @Bind("enabled") boolean enabled, @Bind("verified") boolean verified);
163+
164+
@SqlUpdate(
165+
"UPDATE common_oltp.user_2fa SET " +
166+
"enabled=:enabled, " +
167+
"verified=:verified " +
168+
"WHERE user_id=:userId")
169+
public abstract int update2faByUserId(@Bind("userId") long userId, @Bind("enabled") boolean enabled, @Bind("verified") boolean verified);
170+
171+
@SqlUpdate(
172+
"UPDATE common_oltp.user_2fa SET " +
173+
"otp=:otp, " +
174+
"otp_expire=current_timestamp + (:duration ||' minutes')::interval " +
175+
"WHERE id=:id")
176+
public abstract int update2faOtp(@Bind("id") long id, @Bind("otp") String otp, @Bind("duration") int duration);
177+
178+
@SqlQuery(
179+
"UPDATE common_oltp.user_2fa x SET otp=null, otp_expire=null " +
180+
"FROM (SELECT id, otp, otp_expire FROM common_oltp.user_2fa WHERE user_id=:userId FOR UPDATE)y " +
181+
"WHERE x.id=y.id " +
182+
"RETURNING CASE WHEN y.otp=:otp and y.otp_expire > current_timestamp THEN 1 ELSE 0 END")
183+
public abstract int verify2faOtp(@Bind("userId") long userId, @Bind("otp") String otp);
184+
126185
@RegisterMapperFactory(TCBeanMapperFactory.class)
127186
@SqlQuery(
128187
"SELECT " + USER_COLUMNS + ", " +
129-
"e.address AS email, e.status_id AS emailStatus " +
188+
"e.address AS email, e.status_id AS emailStatus, " +
189+
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
130190
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
191+
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
131192
"WHERE e.address = :email"
132193
)
133194
public abstract List<User> findUsersByEmailCS(@Bind("email") String email);
134195

135196
@RegisterMapperFactory(TCBeanMapperFactory.class)
136197
@SqlQuery(
137198
"SELECT " + USER_COLUMNS + ", " +
138-
"e.address AS email, e.status_id AS emailStatus " +
199+
"e.address AS email, e.status_id AS emailStatus, " +
200+
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
139201
"FROM common_oltp.user AS u " +
202+
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
140203
"<joinOnEmail> common_oltp.email AS e ON u.user_id = e.user_id AND e.primary_ind = 1 " +
141204
"<condition> " +
142205
"<order> " +
@@ -364,6 +427,22 @@ public User findUserByEmail(String email) {
364427
// nothing matched with email parameter in the result, returns the first one.
365428
return users.get(0);
366429
}
430+
431+
public User2fa findUserCredentialByEmail(String email) {
432+
List<User2fa> users = findUser2faByEmail(email);
433+
if(users==null || users.size()==0)
434+
return null;
435+
436+
if(users.size()==1)
437+
return users.get(0);
438+
439+
for (User2fa user : users) {
440+
if(user.getEmail().equals(email))
441+
return user;
442+
}
443+
444+
return users.get(0);
445+
}
367446

368447
/**
369448
*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.appirio.tech.core.service.identity.representation;
2+
3+
public class CredentialRequest {
4+
5+
private String email;
6+
private String connectionId;
7+
8+
public String getEmail() {
9+
return email;
10+
}
11+
12+
public void setEmail(String email) {
13+
this.email = email;
14+
}
15+
16+
public String getConnectionId() {
17+
return connectionId;
18+
}
19+
20+
public void setConnectionId(String connectionId) {
21+
this.connectionId = connectionId;
22+
}
23+
}

0 commit comments

Comments
 (0)