Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ maven_configuration_v1: &maven_configuration_v1
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
MVNSERVERSETTING='<server>\n <id>tcreposnap</id> \n <username>${env.MVNUSERNAME}</username> \n <password>${env.MVNPASSWD}</password> \n </server> '
C=$(echo $MVNSERVERSETTING | sed 's/\//\\\//g')
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
sudo sed -i '/<mirror>/,/<\/mirror>/d' /opt/apache-maven/conf/settings.xml

restore_mvn_offline: &restore_mvn_offline
name: maven restore go offline
Expand Down Expand Up @@ -145,7 +146,7 @@ workflows:
context : org-global
filters:
branches:
only: [dev, 'feature/api-call-optimization']
only: [dev, 'shapeup3']
# Production build is executed on "master" branch only.
- "build-prod":
context : org-global
Expand Down
3 changes: 3 additions & 0 deletions buildtokenproperties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ AUTH_DB_HOST=$(eval "echo \$${ENV}_AUTH_DB_HOST")
AUTH0_NEW_DOMAIN=$(eval "echo \$${ENV}_AUTH0_NEW_DOMAIN")
AUTH0_DOMAIN=$(eval "echo \$${ENV}_AUTH0_DOMAIN")

SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID")



if [[ -z "$ENV" ]] ; then
Expand Down Expand Up @@ -107,3 +109,4 @@ perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_READ\}\}|$M2MAUTHCONFIG_USERPROFIL
perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROFILES_DELETE|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
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void run(IdentityConfiguration configuration, Environment environment) th
UserResource userResource = new UserResource(userDao, roleDao, cacheService, eventProducer, eventBusServiceClient, configuration.getM2mAuthConfiguration().getUserProfiles());
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
userResource.setDomain(configuration.getAuthDomain());
userResource.setSendgridTemplateId(Utils.getString("sendGridTemplateId"));
// 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 @@ -44,7 +44,7 @@ public EventBusServiceClient(Client client, BaseClientConfiguration config, M2mA
}

/**
* Fire event
* reFire event
*
* @param eventMessage the eventMessage to use
*/
Expand All @@ -59,6 +59,30 @@ public void fireEvent(EventMessage eventMessage) {
eventMessage.setTopic(this.config.getAdditionalConfiguration().get("topic"));
Response response = request.header("Authorization", "Bearer " + authToken).post(Entity.entity(eventMessage.getData(), MediaType.APPLICATION_JSON_TYPE));

LOGGER.info("refiring 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) {
LOGGER.error("Failed to fire the event: {}", e);
}
}

/**
* Fire event
*
* @param eventMessage the eventMessage to use
*/
public void reFireEvent(EventMessage eventMessage) {
try {
String url = this.config.getEndpoint();
WebTarget target = this.client.target(url);
final Invocation.Builder request = target.request(MediaType.APPLICATION_JSON_TYPE);
String authToken = Utils.generateAuthToken(m2mAuthConfiguration);

eventMessage.setOriginator(this.config.getAdditionalConfiguration().get("originator"));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -100,6 +102,8 @@ public class UserResource implements GetResource<User>, DDLResource<User> {
private int oneTimeTokenExpirySeconds = 10 * 60; //10min

private String domain;

private String sendgridTemplateId;

protected UserDAO userDao;

Expand Down Expand Up @@ -857,6 +861,78 @@ public ApiResponse changePassword(
return ApiResponseFactory.createResponse("password updated successfully.");
}

/**
* API to resend activation email
* This is supposed to be called from Auth0 custom connection.
* @param email
* @param request
* @return
* @throws Exception
*/
@POST
@Path("/resendEmail")
@Consumes("application/x-www-form-urlencoded")
@Timed
public ApiResponse resendEmail(
@FormParam("email") String email,
@FormParam("handle") String handle,
@Context HttpServletRequest request) throws Exception {

if(Utils.isEmpty(email) && Utils.isEmpty(handle))
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "email/handle"));

User user = null;
if (!Utils.isEmpty(handle)) {
user = userDao.findUserByHandle(handle);
} else {
// email address - case sensitive - for auth0 sepecific
user = userDao.findUserByEmailCS(email);
}

if(user==null) {
throw new APIRuntimeException(SC_UNAUTHORIZED, "Credentials are incorrect.");
}

// return 400 if user has been activated
if(user.isActive())
throw new APIRuntimeException(SC_BAD_REQUEST, MSG_TEMPLATE_USER_ALREADY_ACTIVATED);

EventMessage msg = EventMessage.getDefault();
msg.setTopic("external.action.email");

Map<String,Object> payload = new LinkedHashMap<String,Object>();

Map<String,Object> data = new LinkedHashMap<String,Object>();
data.put("handle", user.getHandle());
data.put("code", user.getCredential().getActivationCode());
data.put("domain", getDomain());
data.put("subDomain", "www");

if (user.getRegSource() != null && user.getRegSource().matches("tcBusiness")) {
data.put("subDomain", "connect");
}

payload.put("data", data);

Map<String,Object> from = new LinkedHashMap<String,Object>();
from.put("email", String.format("Topcoder <noreply@%s>", getDomain()));
payload.put("from", from);

payload.put("version", "v3");
payload.put("sendgrid_template_id", this.getSendgridTemplateId());

ArrayList<String> recipients = new ArrayList<String>();
recipients.add(user.getEmail());

payload.put("recipients", recipients);

msg.setPayload(payload);
this.eventBusServiceClient.reFireEvent(msg);

return ApiResponseFactory.createResponse(user);
}


//TODO: should be PATCH?
@PUT
@Path("/activate")
Expand Down Expand Up @@ -1660,6 +1736,14 @@ public void setDomain(String domain) {
this.domain = domain;
}

public String getSendgridTemplateId() {
return sendgridTemplateId;
}

public void setSendgridTemplateId(String sendgridTemplateId) {
this.sendgridTemplateId = sendgridTemplateId;
}

public String getSecret() {
return secret;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ context:
defaultPassword: @application.password.default@
passwordHashKey: @application.password.key@
ssoTokenSalt: @application.ssotoken.salt@
sendGridTemplateId: @application.sendgrid.template.id@
jwtExpirySeconds: 600
cookieExpirySeconds: 7776000

Expand Down
5 changes: 4 additions & 1 deletion token.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
@application.database.host@={{DB_HOST_IP}}
@application.database.port@=5432

#sendgrid
@application.sendgrid.template.id@={{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID}}

@ldap.host@={{LDAP_SERVER}}
@ldap.port@=389
@ldap.password@={{LDAP_PASSWORD}}
Expand Down Expand Up @@ -79,4 +82,4 @@
@m2mAuthConfig.userProfiles.create@={{M2MAUTHCONFIG_USERPROFILES_CREATE}}
@m2mAuthConfig.userProfiles.read@={{M2MAUTHCONFIG_USERPROFILES_READ}}
@m2mAuthConfig.userProfiles.update@={{M2MAUTHCONFIG_USERPROFILES_UPDATE}}
@m2mAuthConfig.userProfiles.delete@={{M2MAUTHCONFIG_USERPROFILES_DELETE}}
@m2mAuthConfig.userProfiles.delete@={{M2MAUTHCONFIG_USERPROFILES_DELETE}}