publishSyncError(eControlArea, errors);
return;
}
// Get two configured EnterpriseUserPassword from AppConfig.
EnterpriseUserPassword currentEntUserPassword = null;
EnterpriseUserPassword newEntUserPassword = null;
try {
currentEntUserPassword = (EnterpriseUserPassword)getAppConfig()
.getObject("EnterpriseUserPassword");
newEntUserPassword = (EnterpriseUserPassword)getAppConfig()
.getObject("EnterpriseUserPassword");
}
catch (EnterpriseConfigurationObjectException ecoe) {
// An error occurred getting an object from AppConfig. Log it and
// publish a sync error message.
Error error = new Error();
error.setType("application");
error.setErrorNumber("OpenEAI-3001");
error.setErrorDescription("An error occurred getting an object from " +
"AppConfig. the exception is: " + ecoe.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ecoe);
return;
}
// Handle an EnterpriseUserPassword.CreateSync
if (messageAction.equalsIgnoreCase("Create")) {
// Get the new state of the EnterpriseUserPassword and build an
// EnterpriseUserPassword object.
Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
.getChild("NewData").getChild("EnterpriseUserPassword");
try {
newEntUserPassword.buildObjectFromInput(eNewPassword);
}
catch (EnterpriseLayoutException ele) {
// An error occurred building the EnterpriseUserPassword object from the
// EnterpriseUserPassword element contained in the NewData element of
// the message. Log it and publish a sync error message.
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1002");
error.setErrorDescription("An error occurred building the " +
"EnterpriseUserPassword object from the EnterpriseUserPassword " +
"element contained in the NewData element of the message. The " +
"exception is: " + ele.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ele);
return;
}
// Determine whether the user exists in the database.
String userId = getUserId(newEntUserPassword);
String instId = newEntUserPassword.getEnterpriseUser()
.getLightweightPerson().getInstitutionalId();
BasicPerson bp=null;
try {
logger.info("[PasswordSyncCommand.execute] Querying for BasicPerson.");
bp = getBasicPerson(instId);
logger.info("[PasswordSyncCommand.execute] Queried for BasicPerson.");
} catch (EnterpriseConfigurationObjectException e) {
// Log it, publish a error message, and return.
String errMsg = "EnterpriseConfigurationObjectException: " + e.getMessage();
logger.error("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1014");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
publishSyncError(eControlArea, errors);
return;
} catch (EnterpriseFieldException e) {
// Log it, publish a error message, and return.
String errMsg = "EnterpriseFieldException: " + e.getMessage();
logger.error("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1014");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
publishSyncError(eControlArea, errors);
return;
} catch (EnterpriseObjectQueryException e) {
// Log it, publish a error message, and return.
String errMsg = "EnterpriseObjectQueryException: " + e.getMessage();
logger.error("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1014");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
publishSyncError(eControlArea, errors);
return;
}
if (bp==null) {
// No BasicPerson exists for this instId.
// Log it, publish a error message, and return.
String errMsg = "No BasicPerson exists for " + instId;
logger.debug("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-1012");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors);
return;
}
PortalPerson portalPerson = null;
try { portalPerson = retrievePortalPersonByUserId(userId); }
catch (CommandException ce) {
// An error occurred querying the portal database to determine whether
// the user exists. Log it, publish a error message, and return.
String errMsg = "An error occurred querying the portal database to " +
"determine whether the user exists.";
logger.debug("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-2001");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ce);
return;
}
// If the user does exist, publish a error message indicating
// that the user already exists.
if (portalPerson != null) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-1011");
error.setErrorDescription("User with user ID " + userId +
") exists in the portal. Cannot reset the password for this user.");
logger.fatal("[PasswordSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors);
return;
}
// Create the portal user with info from BasicPerson and the
// user's password to be the new value indicated in the message.
else {
logger.info("[PasswordSyncCommand.execute] BasicPerson="+bp);
portalPerson = new PortalPerson();
portalPerson.setEmailAddress(getEmailAddress(bp.getEmail()));
portalPerson.setUserId(userId);
portalPerson.setInstId(instId);
portalPerson.setFirstName(bp.getName().getFirstName());
portalPerson.setLastName(bp.getName().getLastName());
// Encypt the password.
String encryptedPassword=null;
String cleartextPassword = newEntUserPassword.getPassword().getValue();
try {
encryptedPassword = hashPassword(cleartextPassword);
logger.info("[PasswordSyncCommand.execute] cleartext password is: " +
cleartextPassword);
logger.info("[PasswordSyncCommand.execute] excrypted password is: " +
encryptedPassword);
} catch (NoSuchAlgorithmException nsae) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-1002");
error.setErrorDescription("A NoSuchAlgorithmException occurred encrypting the user " +
"password. The exception is: " + nsae.getMessage());
logger.fatal("[PasswordSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, nsae);
return;
} catch (MessagingException nsae) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-1002");
error.setErrorDescription("A MessagingException occurred encrypting the user " +
"password. The exception is: " + nsae.getMessage());
logger.fatal("[PasswordSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, nsae);
return;
} catch (IOException nsae) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-2022");
error.setErrorDescription("An IOException occurred encrypting the user " +
"password. The exception is: " + nsae.getMessage());
logger.fatal("[PasswordSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, nsae);
return;
}
portalPerson.setPassword(encryptedPassword);
try {
createPortalPerson(portalPerson);
} catch (CommandException e) {
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1020");
String errmsg = "An error occurred building the portal person. The exception is: " +
e.getMessage();
error.setErrorDescription(errmsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, e);
logger.error("[PasswordSyncCommand.execute] Can't create portal person. \n"+errmsg);
return;
}
}
}
// Handle an EnterpriseUserPassword.Update-Sync.
if (messageAction.equalsIgnoreCase("Update")) {
// Get the new state of the EnterpriseUserPassword and build an
// EnterpriseUserPassword object.
Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
.getChild("NewData").getChild("EnterpriseUserPassword");
try {
newEntUserPassword.buildObjectFromInput(eNewPassword);
}
catch (EnterpriseLayoutException ele) {
// An error occurred building the EnterpriseUserPassword object from the
// EnterpriseUserPassword element contained in the NewData element of
// the message. Log it and publish a sync error message.
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-1002");
error.setErrorDescription("An error occurred building the " +
"EnterpriseUserPassword object from the EnterpriseUserPassword " +
"element contained in the NewData element of the message. The " +
"exception is: " + ele.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ele);
return;
}
// Determine whether the user exists in the database.
String userId = getUserId(newEntUserPassword);
PortalPerson portalPerson = null;
try {
portalPerson = retrievePortalPersonByUserId(userId);
}
catch (CommandException ce) {
// An error occurred querying the portal database to determine whether
// the user exists. Log it, publish a error message, and return.
String errMsg = "An error occurred querying the portal database to " +
"determine whether the user exists.";
logger.debug("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("SakaiGateway-2001");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ce);
return;
}
// If the user does not exist, publish a error message indicating
// that the user does not exist.
if (portalPerson == null) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("SakaiGateway-1001");
error.setErrorDescription("No user with user ID " + userId +
") exists in the portal. Cannot reset the password for this user.");
logger.fatal("[PasswordSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors);
return;
}
// Otherwise, the user already exists in the portal, so reset the
// user's password to be the new value indicated in the message.
else {
// Encypt the password.
String encryptedPassword=null;
String cleartextPassword = newEntUserPassword.getPassword().getValue();
try {
encryptedPassword = hashPassword(cleartextPassword);
logger.info("[PasswordSyncCommand.execute] cleartext password is: " +
cleartextPassword);
logger.info("[PasswordSyncCommand.execute] excrypted password is: " +