Skip to content

Commit

Permalink
Merge pull request #24 from cilasmarques/develop
Browse files Browse the repository at this point in the history
Adding userEGIScrekeyKey to configure the userEGI registration
  • Loading branch information
bernardoezequias authored Nov 8, 2022
2 parents bb3be59 + 6499ee9 commit b019f82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/dispatcher.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ admin_password=$admin_password
noreply_email=$noreply_email
# NOReply password used for email recourse
noreply_password=$noreply_password
# Default EGI secret key that match with the EGI password
user_egi_secret_key=$user_egi_secret_key
# Temporary storage path mounted by the NFS client
saps_temp_storage_path=$saps_temp_storage_path
# Permanent storage type [swift | nfs]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* (C)2020 */
package saps.dispatcher.core.restlet.resource;

import java.util.Properties;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpStatus;
import org.apache.log4j.Logger;
Expand All @@ -11,6 +12,7 @@
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Post;
import org.restlet.resource.ResourceException;
import saps.common.core.model.SapsUser;

public class UserResource extends BaseResource {

Expand All @@ -24,6 +26,7 @@ public class UserResource extends BaseResource {
private static final String REQUEST_ATTR_USERNOTIFY = "userNotify";
private static final String CREATE_USER_MESSAGE_OK = "User created successfully";
private static final String CREATE_USER_ALREADY_EXISTS = "User already exists";
private static final String EGI_SECRET_KEY = "user_egi_secret_key";

public UserResource() {
super();
Expand All @@ -39,19 +42,29 @@ public Representation createUser(Representation entity) throws Exception {
String userPass = form.getFirstValue(REQUEST_ATTR_USERPASS);
String userPassConfirm = form.getFirstValue(REQUEST_ATTR_USERPASS_CONFIRM);
String userNotify = form.getFirstValue(REQUEST_ATTR_USERNOTIFY);

checkMandatoryAttributes(userName, userEmail, userPass, userPassConfirm);

Properties properties = application.getProperties();
String EGISecretKey = properties.getProperty(EGI_SECRET_KEY);
SapsUser user = application.getUser(userEmail);

LOGGER.debug("Creating user with userEmail " + userEmail + " and userName " + userName);
if (user != null && userPass.equals(EGISecretKey)) {
LOGGER.debug("User [" + userEmail + "] successfully authenticated");
return new StringRepresentation("Success");
} else {
LOGGER.debug("Creating user with userEmail " + userEmail + " and userName " + userName);
}

try {
String md5Pass = DigestUtils.md5Hex(userPass);
boolean userState = userPass.equals(EGISecretKey); //If is an EGI user, automatically his status is enabled
boolean notify = false;
if (userNotify.equals("yes")) {
notify = true;
}
application.createUser(userEmail, userName, md5Pass, false, notify, false);
} catch (Exception e) {
application.createUser(userEmail, userName, md5Pass, userState, notify, false);
} catch (Exception e) {
LOGGER.error("Error while creating user", e);
return new StringRepresentation(CREATE_USER_ALREADY_EXISTS, MediaType.TEXT_PLAIN);
}
Expand Down

0 comments on commit b019f82

Please sign in to comment.