I am creating a WebServiceBeforeOperation rule that interceps the Password during the Change Password operation and encodes it with Base64 and then salts which is an attribute on the application account itself. But the operation doesnt seem to do anything at all, where am I missing the point:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import connector.common.JsonUtil;
import connector.common.Util;
import sailpoint.connector.webservices.EndPoint;
import sailpoint.connector.webservices.WebServicesClient;
import sailpoint.object.Application;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
log.error("Rule - Provisioning Body: running");
Map body = requestEndPoint.getBody();
try {
Map jsonMap = JsonUtil.toMap(jsonBody);
password = "";
if (provisioningPlan != null) {
for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
String attrName = attReq.getName();
if (attrName != null && "password".equalsIgnoreCase(attrName)) {
password = (String) attReq.getValue();
log.error("Rule - Modify Body: password is present in plan = " + password);
try {
// Hash the password with the salt using SHA-256
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] hash = md.digest((password + salt).getBytes("UTF-8"));
// Convert the hash bytes to a hex string
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
hexString.append(String.format("%02x", b));
}
log.error("[BeforeOperation] NewPassword: " + hexString.toString());
// Replace the plain password with the salted hash
attrReq.setValue(hexString.toString());
jsonMap.put("newPassword", hexString.toString());
String finalBody = JsonUtil.render(jsonMap);
body.put("jsonBody", finalBody);
requestEndPoint.setBody(body);
} catch (Exception e) {
logger.debug("Error in BeforeOperation rule: " + e.getMessage(), e);
}
}
}
}
}
} catch (Exception ex) {
log.error("Rule - Modify Body: " + ex);
}
return requestEndPoint;
