Name
sn_ad_spoke.ADErrorHandler
Description
Error Handling for AD Actions
Script
var ADErrorHandler = Class.create();
ADErrorHandler.prototype = {
initialize: function() {},
addUserToGroupHandler: function(inputs, outputs) {
outputs.status = "Error";
gs.error("Add user to AD group Failed with error code:" + inputs.errorCode + " and error Message:" + inputs.errorCode);
if (inputs.errorMessage.indexOf("The (&(objectClass=User)(samaccountname=)) search filter is invalid.") != -1) {
outputs.ErrorMessage = "UserName or GroupName cannot be empty";
}
return outputs;
},
changeUserPasswordHandler: function(inputs) {
if (!inputs.userName || inputs.userName.trim() == "") {
gs.error("Flow Designer - Change User Password: User Name field is empty");
this.throwHandler(Error, "User Name field is empty");
}
if (!inputs.oldPassword || inputs.oldPassword.trim() == "") {
gs.error("Flow Designer - Change User Password: Old Password field is empty");
this.throwHandler(Error, "Old Password field is empty");
}
if (!inputs.newPassword || inputs.newPassword.trim() == "") {
gs.error("Flow Designer - Change User Password: New Password field is empty");
this.throwHandler(Error, "New Password field is empty");
}
if (inputs.newPassword.trim() === inputs.oldPassword.trim()) {
gs.error("Flow Designer - Change User Password: New Password and Old Password fields contain same value");
this.throwHandler(Error, "New Password and Old Password fields contain same value");
}
},
resetUserPasswordHandler: function(inputs) {
if (!inputs.userName || inputs.userName.trim() == "") {
gs.error("Flow Designer - Reset AD User Password: User Name field is empty");
this.throwHandler(Error, "User Name field is empty");
}
if (!inputs.password || inputs.password.trim() == "") {
gs.error("Flow Designer - Reset AD User Password: Password field is empty");
this.throwHandler(Error, "Password field is empty");
}
},
verifyProps: function(propsList, objectType) {
if (!propsList || JSON.stringify(propsList) == "") {
gs.error("Flow Designer - Lookup " + objectType + ": Property list is empty");
this.throwHandler(Error, "Property list is empty");
}
},
verifyEmptyValuesinPropsList: function(propsList, definedProperties, objectType) {
var propsNotFound = [];
propsList.forEach(function(prop) {
if (definedProperties.indexOf(prop.trim().toLowerCase()) == -1)
if (prop.trim() == "")
propsNotFound.push("<EmptyValue>");
else
propsNotFound.push(prop);
});
if (propsNotFound.length !== 0) {
gs.error("Flow Designer - Lookup " + objectType + ": Unidentified " + objectType + " object properties");
this.throwHandler(Error, "Unidentified " + objectType + " object properties: " + propsNotFound);
}
},
verifySingleProp: function(prop, objectType) {
if (!prop || prop.trim() == "") {
gs.error("Flow Designer - Lookup " + objectType + ": " + objectType + " Name field is empty");
this.throwHandler(Error, this.capitalizeFirstChar(objectType) + " Name field is empty");
}
},
verifyInput: function(input, name) {
if (!input || input.trim() == "") {
gs.error("Flow Designer - Input Error: " + name + "field is empty");
this.throwHandler(Error, name + " field is empty");
}
},
capitalizeFirstChar: function(input) {
return input.charAt(0).toUpperCase() + input.slice(1);
},
lookupErrorHandler: function(inputs, objectType) {
var propsList = inputs.propertiesList;
var USER = "user";
var GROUP = "group";
this.verifyProps(propsList, objectType);
if (objectType == USER)
this.verifySingleProp(inputs.userName, USER);
if (objectType == GROUP)
this.verifySingleProp(inputs.groupName, GROUP);
},
userErrorHandler: function(inputs) {
var errMessage = inputs.errorMsg;
var errorMessages = {
MGR_USER_SAME: "Manager cannot be the same user"
};
var output = inputs.output;
if (output == errorMessages.MGR_USER_SAME)
this.throwHandler(Error, errorMessages.MGR_USER_SAME);
if(output.indexOf("Error:") !== -1){
if (output.indexOf(inputs.user) !== -1)
this.throwHandler(Error, "User with identity " + inputs.user + " does not exist");
if (inputs.manager && inputs.manager.trim() !== "" && output.indexOf(inputs.manager) !== -1)
this.throwHandler(Error, "User with identity " + inputs.manager + " does not exist");
}
if (errMessage || !inputs.output) {
if (errMessage.indexOf(inputs.user) !== -1)
this.throwHandler(Error, "User with identity " + inputs.user + " does not exist");
if (inputs.manager && inputs.manager.trim() !== "" && errMessage.indexOf(inputs.manager) !== -1)
this.throwHandler(Error, "User with identity " + inputs.manager + " does not exist");
}
},
countryFieldHandler: function(fieldValue) {
var codes = "AF AX AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BQ BA BW BV BR IO UM VG VI BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CD CK CR HR CU CW CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU GT GG GN GW GY HT HM VA HN HK HU IS IN ID CI IR IQ IE IM IL IT JM JP JE JO KZ KE KI KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU YT MX FM MD MC MN ME MS MA MZ MM NA NR NP NL NC NZ NI NE NG NU NF KP MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA XK RE RO RU RW BL SH KN LC MF PM VC WS SM ST SA SN RS SC SL SG SX SK SI SB SO ZA GS KR SS ES LK SD SR SJ SZ SE CH SY TW TJ TZ TH TL TG TK TO TT TN TR TM TC TV UG UA AE GB US UY UZ VU VE VN WF EH YE ZM ZW";
if (fieldValue && (fieldValue.trim() == "" || codes.split(" ").indexOf(fieldValue) == -1)) {
gs.error("Flow Designer - Create/Update User: Country field allows only ISO 3166-1 alpha-2 Codes");
this.throwHandler(Error, "Country field allows only ISO 3166-1 alpha-2 Codes");
}
},
updateUserErrorHandler: function(inputs) {
if (!inputs.SamAccountName || inputs.SamAccountName.trim() == "") {
gs.error("Flow Designer - Update User: User Identity cannot be empty");
this.throwHandler(Error, "User Identity cannot be empty");
}
this.countryFieldHandler(inputs.Country);
},
createUserErrorHandler: function(inputs, outputs) {
var errMessage = inputs.errorMessage;
var actionErrors = {
OBJECT_ALREADY_EXISTS: "The object already exists",
ACCOUNT_ALREADY_EXISTS: "The specified account already exists",
INVALID_USER_NAME: "The name provided is not a properly formed account name",
INVALID_LENGTH: "Input length exceeded"
};
var errorMessages = {
USER_EXISTS: "A User with the same name already exists in AD",
INVALID_USER_NAME: "Invalid User Name",
USER_NAME_LENGTH_EXCEEDED: "User Name should not exceed 20 characters",
};
if (errMessage.indexOf(actionErrors.OBJECT_ALREADY_EXISTS) != -1 || inputs.errorMessage.indexOf(actionErrors.ACCOUNT_ALREADY_EXISTS) != -1)
outputs.ErrorMessage = errorMessages.USER_EXISTS;
if (errMessage.indexOf(actionErrors.INVALID_USER_NAME) != -1)
outputs.ErrorMessage = errorMessages.INVALID_USER_NAME;
if (inputs.output.indexOf(actionErrors.INVALID_LENGTH) != -1)
outputs.ErrorMessage = errorMessages.USER_NAME_LENGTH_EXCEEDED;
return outputs;
},
queryADErrorHandler: function(inputs, outputs) {
var errMessage = inputs.errorMessage;
var queryResult = inputs.output;
var commErrors = {
INVALID_FILTER: "search filter is invalid",
DIRECTORY_ERROR: "The directory service is unavailable",
PROP_INVALID: "One or more properties are invalid",
PROP_INVALID_FORMAT: "Cannot validate argument on parameter 'Properties'"
};
var errorMessages = {
INVALID_FILTER: "The provided filter is invalid. Please check the filter syntax",
PROP_INVALID_FORMAT: "The properties mentioned are not in comma separated string format."
};
if (queryResult.indexOf(commErrors.INVALID_FILTER) != -1 || queryResult.indexOf(
commErrors.DIRECTORY_ERROR) != -1 || errMessage.indexOf(commErrors.INVALID_FILTER) !=
-1 || errMessage.indexOf(commErrors.DIRECTORY_ERROR) != -1)
outputs.ErrorMessage = errorMessages.INVALID_FILTER;
if (queryResult.indexOf(commErrors.PROP_INVALID) != -1)
outputs.ErrorMessage = queryResult;
if (queryResult.indexOf(commErrors.PROP_INVALID_FORMAT) != -1)
outputs.ErrorMessage = errorMessages.PROP_INVALID_FORMAT;
return outputs;
},
commonErrorHandler: function(inputs, outputs) {
var errMessage = inputs.errorMessage;
var commErrors = {
AUTH_FAILURE: "Authentication failure with the user",
SERVER_UNAVAILABLE: "The RPC server is unavailable",
UNREACHABLE_STATUS: "Failed to access target system. Please check credentials and firewall settings on the target system to ensure accessibility: Access is denied."
};
var errorMessages = {
CREDENTIALS_FAILED: "Invalid credentials for host",
INVALID_HOST: "Invalid hostname in connection or host not reachable from Mid server",
AUTH_FAILED_WITH_MID: "Host credentials incorrect. Authentication error in MID server",
};
if (errMessage.indexOf(commErrors.AUTH_FAILURE) != -1)
outputs.ErrorMessage = errorMessages.CREDENTIALS_FAILED;
if (errMessage.indexOf(commErrors.SERVER_UNAVAILABLE) != -1)
outputs.ErrorMessage = errorMessages.INVALID_HOST;
if (errMessage.indexOf(commErrors.UNREACHABLE_STATUS) != -1)
outputs.ErrorMessage = errorMessages.AUTH_FAILED_WITH_MID;
return outputs;
},
throwHandler: function(errorType, errorMessage) {
throw new errorType(errorMessage);
},
type: 'ADErrorHandler'
};
Sys ID
a43baea553630300eeadddeeff7b12c9