publishSyncError(eControlArea, errors, ele);
return;
}
// Determine whether the user exists is the directory server.
LightweightPerson lPerson = newEntUserPassword.getEnterpriseUser()
.getLightweightPerson();
String userName = "";
if (lPerson.getName() != null) userName = lPerson.getName().getFirstName()
+ " " + lPerson.getName().getLastName();
logger.debug("[" + getServiceName() + ".execute] Querying the directory to " +
"determine if the user whose password has changed already exists " +
"in the directory.");
// Specify the search filter for the directory service query using
// the employeeNumber.
String filter = "employeeNumber=" + lPerson.getInstitutionalId();
logger.debug("[" + getServiceName() + ".execute] Search filter is: " + filter);
// Specify the providerUrl.
String providerUrl = getUserDirectoryTreeBase();
logger.debug("[" + getServiceName() + ".execute] providerUrl is: " +
providerUrl);
// Specify search controls that set the scope of the search.
SearchControls cons = new SearchControls();
cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
String[] attrs = new String[1];
attrs[0] = "uid";
cons.setReturningAttributes(attrs);
// Search for user entries that match the employeeNumber, retrieving
// the uid.
NamingEnumeration results = null;
boolean userExists = false;
try {
logger.debug("[" + getServiceName() + ".execute] Querying the directory " +
"server.");
results = getDirContext().search(providerUrl, filter, cons);
if (results != null && results.hasMore() == true) userExists = true;
}
catch (NamingException ne) {
// An error occurred querying the directory server to determine whether
// the user exists. Log it, publich a error message, and return.
String errMsg = "An error occurred querying the directory server to " +
"determine whether the user exists.";
logger.debug("[" + getServiceName() + ".execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("DirectoryServiceGateway-2002");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ne);
return;
}
// If there are no matching entries, the user does not exist. If the
// createMissingUsers property is true, create the user with attribute
// and password indicated in the new data of the message. If the
// createMissingUsers property is false, publish a Sync.Error-Sync
// indicating that the password cannot be set for this user, because
// the user does not exist.
if (userExists == false) {
logger.info("[" + getServiceName() + ".execute] The user " + userName +
"(" + lPerson.getInstitutionalId() +
") does not exist in the directory.");
if (getCreateMissingUsers() == true) {
// Create the user.
// -- Build the attributes for the new directory entry.
BasicAttributes attributes = buildDirectoryUser(newEntUserPassword);
// -- Create the new subcontext for the entry.
String dn = "uid=" + getEnterpriseId(newEntUserPassword
.getEnterpriseUser()).getPrincipal() + "," +
getUserDirectoryTreeBase();
logger.debug("[" + getServiceName() + ".execute] dn for the new " +
"directory context is: " + dn);
try {
logger.debug("[" + getServiceName() + ".execute] Creating directory " +
"user with attributes: " + attributes.toString());
Context result = getDirContext().createSubcontext(dn, attributes);
logger.info("[" + getServiceName() + ".execute] Created directory " +
"user.");
}
catch (NamingException ne) {
// An error occurred creating the entry for the user in the
// directory server. Log it, publich a error message, and return.
String errMsg = "An error occurred creating the entry for the " +
"user in the directory server.";
logger.debug("[" + getServiceName() + ".execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("DirectoryServiceGateway-2002");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ne);
return;
}
return;
}
else {
// The createMissingUsers property is false, so we will not create
// the missing user.
logger.info("[" + getServiceName() + ".execute] createMissingUsers is " +
"false, so the missing user will not be created and the " +
"cannot be set.");
return;
}
}
else {
// Otherwise, the user already exists, so the user does not have to be
// created. Log it and return.
logger.info("[" + getServiceName() + ".execute] The directory user already "
+ "exists, so the user does not need to be created.");
return;
}
}
// Handle an EnterpriseUserPassword.Update-Sync
if (messageAction.equalsIgnoreCase("Update")) {
// Get the baseline state of the EnterpriseUserPassword and build an
// EnterpriseUserPassword object.
Element eBaselinePassword = inDoc.getRootElement().getChild("DataArea")
.getChild("BaselineData").getChild("EnterpriseUserPassword");
try {
currentEntUserPassword.buildObjectFromInput(eBaselinePassword);
}
catch (EnterpriseLayoutException ele) {
// An error occurred building the EnterpriseUserPassword object from the
// EnterpriseUserPassword element contained in the BaselineData element
// of the message. Log it and publish a sync error message.
Error error = new Error();
error.setType("system");
error.setErrorNumber("DirectoryServiceGateway-1001");
error.setErrorDescription("An error occurred building the " +
"EnterpriseUserPassword object from the EnterpriseUserPassword " +
"element contained in the BaselineData element of the message. The " +
"exception is: " + ele.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ele);
return;
}
// 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("DirectoryServiceGateway-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 is the directory server.
LightweightPerson lPerson = newEntUserPassword.getEnterpriseUser()
.getLightweightPerson();
String userName = "";
if (lPerson.getName() != null) userName = lPerson.getName().getFirstName()
+ " " + lPerson.getName().getLastName();
logger.debug("[" + getServiceName() + ".execute] Querying the directory to " +
"see if the user whose password has changed already exists in the " +
"directory.");
// Specify the search filter for the directory service query using
// the uniqueMember and the uniquePermission built above.
String filter = "employeeNumber=" + lPerson.getInstitutionalId();
logger.debug("[" + getServiceName() + ".execute] Search filter is: " + filter);
// Specify the providerUrl.
String providerUrl = getUserDirectoryTreeBase();
logger.debug("[" + getServiceName() + ".execute] providerUrl is: " +
providerUrl);
// Specify search controls that set the scope of the search.
SearchControls cons = new SearchControls();
cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
String[] attrs = new String[1];
attrs[0] = "uid";
cons.setReturningAttributes(attrs);
// Search for user entries that match the employeeNumber, retrieving
// the uid.
try {
logger.debug("[" + getServiceName() + ".execute] Querying the directory " +
"server.");
NamingEnumeration results = getDirContext().search(providerUrl, filter,
cons);
// If there are no matching entries, publish a error message indicating
// that the user does not exist.
if (results == null || results.hasMore() == false) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("DirectoryServiceGateway-1005");
error.setErrorDescription("No user " + userName + "(" +
lPerson.getInstitutionalId() + ") exists in the directory. " +
"Cannot reset the password for this user.");
logger.fatal("[" + getServiceName() + ".execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);