Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
912dac6
deploying on dev
May 18, 2022
8ed808b
Update build-image.sh
Gunasekar-K May 18, 2022
01b853c
add 2fa endpoints
eisbilir Jul 2, 2022
2a7f6b0
Merge pull request #71 from appirio-tech/auth0-kt [skip ci]
Gunasekar-K Jul 4, 2022
adb9af8
Merge pull request #70 from eisbilir/feature/2fa
ThomasKranitsas Jul 4, 2022
5e1d7e9
update property
eisbilir Jul 4, 2022
b48f53a
fix tokenproperties
eisbilir Jul 4, 2022
bf08b11
Merge pull request #72 from eisbilir/feature/2fa
ThomasKranitsas Jul 4, 2022
552ef40
log request
eisbilir Jul 4, 2022
3e960b2
Merge pull request #73 from eisbilir/feature/2fa
eisbilir Jul 5, 2022
a575a9f
add mfa info to user object
eisbilir Jul 7, 2022
7216551
Merge pull request #74 from appirio-tech/feature/2fa
eisbilir Jul 7, 2022
c88a757
add 2fa invitation endpoint
eisbilir Jul 10, 2022
0e00a0a
Merge pull request #75 from appirio-tech/feature/2fa
eisbilir Jul 10, 2022
bdc9f91
update dice urls
eisbilir Jul 21, 2022
721c0c2
echo token properties
eisbilir Jul 21, 2022
c14151f
Revert "echo token properties"
eisbilir Jul 21, 2022
9a924ae
update url
eisbilir Jul 21, 2022
74f457a
fix token
eisbilir Jul 21, 2022
3b50824
add api to update user2fa
eisbilir Jul 21, 2022
b6c55d7
fix sql query
eisbilir Jul 21, 2022
6280122
fix sql query
eisbilir Jul 21, 2022
7649da1
register mapping
eisbilir Jul 21, 2022
6c6a043
reset 2fa if user reset password
eisbilir Jul 21, 2022
8e62c8f
add reset 2fa
eisbilir Jul 21, 2022
c12fd6f
add mfa to roles endpoint
eisbilir Jul 25, 2022
92c9d12
update dice conf
eisbilir Jul 28, 2022
97b23f5
Merge pull request #76 from appirio-tech/feature/2fa
eisbilir Jul 29, 2022
7266e7e
update token
eisbilir Jul 29, 2022
55b2dde
update log statements
eisbilir Jul 29, 2022
0902a8d
add otp endpoints
eisbilir Aug 1, 2022
b5ce980
Merge pull request #77 from appirio-tech/feature/2fa
eisbilir Aug 1, 2022
e2a140e
fix sql query
eisbilir Aug 1, 2022
9be0e04
fix annotation
eisbilir Aug 1, 2022
e1ea805
update 2fa m2m scopes
eisbilir Aug 3, 2022
f6aa138
update dice endpoints
eisbilir Aug 3, 2022
272bc44
Merge pull request #78 from appirio-tech/feature/2fa
eisbilir Aug 3, 2022
ef51926
update 2faVerification endpoint
eisbilir Aug 4, 2022
dca8473
make otp life configurable
eisbilir Aug 10, 2022
1866c9d
Merge pull request #80 from appirio-tech/feature/2fa
eisbilir Aug 10, 2022
7dbe1c3
fix token property
eisbilir Aug 10, 2022
a72750a
add log to roles endpoint
eisbilir Aug 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ workflows:
context : org-global
filters:
branches:
only: [dev, 'feature/jira-plat-152']
only: [dev, 'feature/jira-plat-152', 'auth0-kt']
# Production build is executed on "master" branch only.
- "build-prod":
context : org-global
Expand Down
8 changes: 7 additions & 1 deletion build/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ VER=`date "+%Y%m%d%H%M"`
# }

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

# Elastic Beanstalk Application name
# dev
Expand Down Expand Up @@ -97,6 +97,12 @@ cat $WORK_DIR/config/sumo-template.conf | sed -e "s/@APINAME@/${SERVICE}/g" | se
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
cat $WORK_DIR/config/newrelic-template.yml | sed -e "s/@APINAME@/${SERVICE}/g" | sed -e "s/@CONFIG@/${CONFIG}/g" > $DOCKER_DIR/newrelic.yml

echo "Logging into docker"
echo "############################"
DOCKER_USER=$(aws ssm get-parameter --name /$CONFIG/build/dockeruser --with-decryption --output text --query Parameter.Value)
DOCKER_PASSWD=$(aws ssm get-parameter --name /$CONFIG/build/dockercfg --with-decryption --output text --query Parameter.Value)
echo $DOCKER_PASSWD | docker login -u $DOCKER_USER --password-stdin

echo "building docker image: ${IMAGE}"
docker build -t $TAG $DOCKER_DIR
handle_error "docker build failed."
Expand Down
22 changes: 22 additions & 0 deletions buildtokenproperties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ AUTH0_NEW_ID=$(eval "echo \$${ENV}_AUTH0_NEW_ID")
AUTH0_NEW_ID_SECRET=$(eval "echo \$${ENV}_AUTH0_NEW_ID_SECRET")
AUTH0_NEW_NONINTERACTIVE_ID=$(eval "echo \$${ENV}_AUTH0_NEW_NONINTERACTIVE_ID")
AUTH0_NEW_NONINTERACTIVE_ID_SECRET=$(eval "echo \$${ENV}_AUTH0_NEW_NONINTERACTIVE_ID_SECRET")
DICEAUTH_DICE_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_URL")
DICEAUTH_DICE_API_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_URL")
DICEAUTH_DICE_VERIFIER=$(eval "echo \$${ENV}_DICEAUTH_DICE_VERIFIER")
DICEAUTH_DICE_API_KEY=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_KEY")
DICEAUTH_CREDDEFID=$(eval "echo \$${ENV}_DICEAUTH_CREDDEFID")
DICEAUTH_OTP_DURATION=$(eval "echo \$${ENV}_DICEAUTH_OTP_DURATION")
ZENDESK_ID=$(eval "echo \$${ENV}_ZENDESK_ID")
SERVICEACC02_UID=$(eval "echo \$${ENV}_SERVICEACC02_UID")
AUTH_SECRET=$(eval "echo \$${ENV}_AUTH_SECRET")
Expand All @@ -33,6 +39,9 @@ M2MAUTHCONFIG_USERPROFILES_CREATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFIL
M2MAUTHCONFIG_USERPROFILES_UPDATE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_UPDATE")
M2MAUTHCONFIG_USERPROFILES_READ=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_READ")
M2MAUTHCONFIG_USERPROFILES_DELETE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USERPROFILES_DELETE")
M2MAUTHCONFIG_USER2FA_ENABLE=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_ENABLE")
M2MAUTHCONFIG_USER2FA_VERIFY=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_VERIFY")
M2MAUTHCONFIG_USER2FA_CREDENTIAL=$(eval "echo \$${ENV}_M2MAUTHCONFIG_USER2FA_CREDENTIAL")

DOMAIN=$(eval "echo \$${ENV}_DOMAIN")
SMTP=$(eval "echo \$${ENV}_SMTP")
Expand All @@ -47,6 +56,8 @@ SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_RESE
SENDGRID_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_WELCOME_EMAIL_TEMPLATE_ID")
SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID")
SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID")
SENDGRID_2FA_INVITATION_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_2FA_INVITATION_TEMPLATE_ID")
SENDGRID_2FA_OTP_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_2FA_OTP_TEMPLATE_ID")


if [[ -z "$ENV" ]] ; then
Expand Down Expand Up @@ -79,6 +90,12 @@ perl -pi -e "s/\{\{AUTH0_NEW_ID\}\}/$AUTH0_NEW_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{AUTH0_NEW_ID_SECRET\}\}/$AUTH0_NEW_ID_SECRET/g" $CONFFILENAME
perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID\}\}/$AUTH0_NEW_NONINTERACTIVE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID_SECRET\}\}/$AUTH0_NEW_NONINTERACTIVE_ID_SECRET/g" $CONFFILENAME
perl -pi -e "s|\{\{DICEAUTH_DICE_URL\}\}|$DICEAUTH_DICE_URL|g" $CONFFILENAME
perl -pi -e "s|\{\{DICEAUTH_DICE_API_URL\}\}|$DICEAUTH_DICE_API_URL|g" $CONFFILENAME
perl -pi -e "s|\{\{DICEAUTH_DICE_VERIFIER\}\}|$DICEAUTH_DICE_VERIFIER|g" $CONFFILENAME
perl -pi -e "s|\{\{DICEAUTH_DICE_API_KEY\}\}|$DICEAUTH_DICE_API_KEY|g" $CONFFILENAME
perl -pi -e "s/\{\{DICEAUTH_CREDDEFID\}\}/$DICEAUTH_CREDDEFID/g" $CONFFILENAME
perl -pi -e "s/\{\{DICEAUTH_OTP_DURATION\}\}/$DICEAUTH_OTP_DURATION/g" $CONFFILENAME
perl -pi -e "s/\{\{ZENDESK_KEY\}\}/$ZENDESK_KEY/g" $CONFFILENAME
perl -pi -e "s/\{\{ZENDESK_ID\}\}/$ZENDESK_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SERVICEACC01_CID\}\}/$SERVICEACC01_CID/g" $CONFFILENAME
Expand Down Expand Up @@ -109,9 +126,14 @@ perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_CREATE\}\}|$M2MAUTHCONFIG_USERPROF
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_UPDATE\}\}|$M2MAUTHCONFIG_USERPROFILES_UPDATE|g" $CONFFILENAME
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_READ\}\}|$M2MAUTHCONFIG_USERPROFILES_READ|g" $CONFFILENAME
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROFILES_DELETE|g" $CONFFILENAME
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_ENABLE\}\}|$M2MAUTHCONFIG_USER2FA_ENABLE|g" $CONFFILENAME
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_VERIFY\}\}|$M2MAUTHCONFIG_USER2FA_VERIFY|g" $CONFFILENAME
perl -pi -e "s|\{\{M2MAUTHCONFIG_USER2FA_CREDENTIAL\}\}|$M2MAUTHCONFIG_USER2FA_CREDENTIAL|g" $CONFFILENAME
perl -pi -e "s/\{\{AUTH0_NEW_DOMAIN\}\}/$AUTH0_NEW_DOMAIN/g" $CONFFILENAME
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_SELF_SERVICE_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_SELF_SERVICE_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_2FA_INVITATION_TEMPLATE_ID\}\}/$SENDGRID_2FA_INVITATION_TEMPLATE_ID/g" $CONFFILENAME
perl -pi -e "s/\{\{SENDGRID_2FA_OTP_TEMPLATE_ID\}\}/$SENDGRID_2FA_OTP_TEMPLATE_ID/g" $CONFFILENAME
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ public void run(IdentityConfiguration configuration, Environment environment) th
configuration.getEventBusServiceClientConfig(), configuration.getM2mAuthConfiguration());
// Resources::users
CacheService cacheService = configuration.getCache().createCacheService();
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles());
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles(), configuration.getM2mAuthConfiguration().getUser2fa());
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
userResource.setDiceAuth(configuration.getDiceAuth());
userResource.setDomain(configuration.getAuthDomain());
userResource.setSendgridTemplateId(Utils.getString("sendGridTemplateId"));
userResource.setSendgridWelcomeTemplateId(Utils.getString("sendGridWelcomeTemplateId"));
userResource.setSendgridSelfServiceTemplateId(Utils.getString("sendGridSelfServiceTemplateId"));
userResource.setSendgridSelfServiceWelcomeTemplateId(Utils.getString("sendGridSelfServiceWelcomeTemplateId"));
userResource.setSendgrid2faInvitationTemplateId(Utils.getString("sendGrid2faInvitationTemplateId"));
userResource.setSendgrid2faOtpTemplateId(Utils.getString("sendGrid2faOtpTemplateId"));
// this secret _used_ to be different from the one used in AuthorizationResource.
// it _was_ the secret x2. (userResource.setSecret(getSecret()+getSecret());)
// we assume this was done to further limit the usability of the oneTimeToken generated in userResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.appirio.clients.BaseClientConfiguration;
import com.appirio.tech.core.api.v3.dropwizard.APIBaseConfiguration;
import com.appirio.tech.core.service.identity.util.auth.Auth0Client;
import com.appirio.tech.core.service.identity.util.auth.DICEAuth;
import com.appirio.tech.core.service.identity.util.auth.ServiceAccountAuthenticatorFactory;
import com.appirio.tech.core.service.identity.util.cache.CacheServiceFactory;
import com.appirio.tech.core.service.identity.util.event.EventSystemFactory;
Expand Down Expand Up @@ -61,6 +62,10 @@ public class IdentityConfiguration extends APIBaseConfiguration {
@Valid
@JsonProperty
private Auth0Client auth0New = new Auth0Client();

@Valid
@JsonProperty
private DICEAuth diceAuth = new DICEAuth();

@Valid
@NotNull
Expand Down Expand Up @@ -135,6 +140,10 @@ public Auth0Client getAuth0() {
public Auth0Client getAuth0New() {
return auth0New;
}

public DICEAuth getDiceAuth() {
return diceAuth;
}

public LDAPServiceFactory getLdap() {
return ldap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.appirio.tech.core.service.identity;

import com.appirio.tech.core.service.identity.util.m2mscope.User2faFactory;
import com.appirio.tech.core.service.identity.util.m2mscope.UserProfilesFactory;
import com.fasterxml.jackson.annotation.JsonProperty;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -65,6 +66,9 @@ public class M2mAuthConfiguration {
@JsonProperty
private UserProfilesFactory userProfiles = new UserProfilesFactory();

@JsonProperty
private User2faFactory user2fa = new User2faFactory();

public UserProfilesFactory getUserProfiles() {
return userProfiles;
}
Expand All @@ -73,6 +77,14 @@ public void setUserProfiles(UserProfilesFactory userProfiles) {
this.userProfiles = userProfiles;
}

public User2faFactory getUser2fa() {
return user2fa;
}

public void setUser2fa(User2faFactory user2fa) {
this.user2fa = user2fa;
}

/**
* Get clientId
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
Expand Down Expand Up @@ -81,13 +82,17 @@ public void reFireEvent(EventMessage eventMessage) {
String authToken = Utils.generateAuthToken(m2mAuthConfiguration);

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

LOGGER.info("Fire event {}", new ObjectMapper().writer().writeValueAsString(eventMessage));
if (response.getStatusInfo().getStatusCode() != HttpStatus.OK_200 && response.getStatusInfo().getStatusCode()!= HttpStatus.NO_CONTENT_204) {
LOGGER.error("Unable to fire the event: {}", response);
}
} catch (Exception e) {
} catch (ProcessingException e) {
if(!e.getMessage().equals("java.net.SocketTimeoutException: Read timed out")) {
LOGGER.error("Failed to fire the event: {}", e);
}
} catch (Exception e) {
LOGGER.error("Failed to fire the event: {}", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.appirio.tech.core.service.identity.representation.Achievement;
import com.appirio.tech.core.service.identity.representation.Country;
import com.appirio.tech.core.service.identity.representation.Credential;
import com.appirio.tech.core.service.identity.representation.User2fa;
import com.appirio.tech.core.service.identity.representation.Email;
import com.appirio.tech.core.service.identity.representation.GroupMembership;
import com.appirio.tech.core.service.identity.representation.ProviderType;
Expand Down Expand Up @@ -96,47 +97,109 @@ public abstract class UserDAO implements DaoBase<User>, Transactional<UserDAO> {
@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"SELECT " + USER_COLUMNS + ", " +
"s.password AS credential$encodedPassword, e.address AS email, e.status_id AS emailStatus " +
"s.password AS credential$encodedPassword, e.address AS email, e.status_id AS emailStatus, " +
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
"FROM common_oltp.user AS u " +
"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 " +
"LEFT OUTER JOIN common_oltp.security_user AS s ON u.user_id = s.login_id " +
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
"WHERE u.user_id = :id"
)
public abstract User findUserById(@Bind("id") long id);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"SELECT " + USER_COLUMNS + ", " +
"e.address AS email, e.status_id AS emailStatus " +
"e.address AS email, e.status_id AS emailStatus, " +
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
"FROM common_oltp.user AS u " +
"LEFT OUTER JOIN common_oltp.email AS e ON u.user_id = e.user_id AND e.email_type_id = 1 " +
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
"WHERE u.handle_lower = LOWER(:handle)"
)
public abstract User findUserByHandle(@Bind("handle") String handle);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"SELECT " + USER_COLUMNS + ", " +
"e.address AS email, e.status_id AS emailStatus " +
"e.address AS email, e.status_id AS emailStatus, " +
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
"LEFT JOIN common_oltp.user_2fa mfa ON mfa.user_id = u.user_id " +
"WHERE LOWER(e.address) = LOWER(:email)"
)
public abstract List<User> findUsersByEmail(@Bind("email") String email);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"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 " +
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
"WHERE LOWER(e.address) = LOWER(:email)"
)
public abstract List<User2fa> findUser2faByEmail(@Bind("email") String email);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"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 " +
"FROM common_oltp.user AS u LEFT JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
"WHERE u.user_id = :userId"
)
public abstract User2fa findUser2faById(@Bind("userId") long userId);

@SqlUpdate(
"INSERT INTO common_oltp.user_2fa " +
"(user_id, enabled) VALUES " +
"(:userId, :enabled)")
public abstract int insertUser2fa(@Bind("userId") long userId, @Bind("enabled") boolean enabled);

@SqlUpdate(
"UPDATE common_oltp.user_2fa SET " +
"enabled=:enabled, " +
"verified=:verified " +
"WHERE id=:id")
public abstract int update2fa(@Bind("id") long id, @Bind("enabled") boolean enabled, @Bind("verified") boolean verified);

@SqlUpdate(
"UPDATE common_oltp.user_2fa SET " +
"enabled=:enabled, " +
"verified=:verified " +
"WHERE user_id=:userId")
public abstract int update2faByUserId(@Bind("userId") long userId, @Bind("enabled") boolean enabled, @Bind("verified") boolean verified);

@SqlUpdate(
"UPDATE common_oltp.user_2fa SET " +
"otp=:otp, " +
"otp_expire=current_timestamp + (:duration ||' minutes')::interval " +
"WHERE id=:id")
public abstract int update2faOtp(@Bind("id") long id, @Bind("otp") String otp, @Bind("duration") int duration);

@SqlQuery(
"UPDATE common_oltp.user_2fa x SET otp=null, otp_expire=null " +
"FROM (SELECT id, otp, otp_expire FROM common_oltp.user_2fa WHERE user_id=:userId FOR UPDATE)y " +
"WHERE x.id=y.id " +
"RETURNING CASE WHEN y.otp=:otp and y.otp_expire > current_timestamp THEN 1 ELSE 0 END")
public abstract int verify2faOtp(@Bind("userId") long userId, @Bind("otp") String otp);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"SELECT " + USER_COLUMNS + ", " +
"e.address AS email, e.status_id AS emailStatus " +
"e.address AS email, e.status_id AS emailStatus, " +
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
"FROM common_oltp.user AS u JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
"WHERE e.address = :email"
)
public abstract List<User> findUsersByEmailCS(@Bind("email") String email);

@RegisterMapperFactory(TCBeanMapperFactory.class)
@SqlQuery(
"SELECT " + USER_COLUMNS + ", " +
"e.address AS email, e.status_id AS emailStatus " +
"e.address AS email, e.status_id AS emailStatus, " +
"mfa.enabled AS mfaEnabled, mfa.verified AS mfaVerified " +
"FROM common_oltp.user AS u " +
"LEFT JOIN common_oltp.user_2fa AS mfa ON mfa.user_id = u.user_id " +
"<joinOnEmail> common_oltp.email AS e ON u.user_id = e.user_id AND e.primary_ind = 1 " +
"<condition> " +
"<order> " +
Expand Down Expand Up @@ -364,6 +427,22 @@ public User findUserByEmail(String email) {
// nothing matched with email parameter in the result, returns the first one.
return users.get(0);
}

public User2fa findUserCredentialByEmail(String email) {
List<User2fa> users = findUser2faByEmail(email);
if(users==null || users.size()==0)
return null;

if(users.size()==1)
return users.get(0);

for (User2fa user : users) {
if(user.getEmail().equals(email))
return user;
}

return users.get(0);
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.appirio.tech.core.service.identity.representation;

public class CredentialRequest {

private String email;
private String connectionId;

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getConnectionId() {
return connectionId;
}

public void setConnectionId(String connectionId) {
this.connectionId = connectionId;
}
}
Loading