WCP 11gR1: Change the Password Programmatically
Recently we implemented a Custom Interface for changing the password in a WebCenter Portal 11.1.1.8 environment. Here I am sharing some of the code to achieve it (taken from WebCenter API).
Java Code Snippet:
As you can see in the code above, the important
JSFF Snippet:
Note: Remember that your LDAP has to be conigured with the rights for allowing users to change the password.
TIP: Validators where not included in this post, but it is using the defined by WebCenter ;).
Java Code Snippet:
public void setPassword(ActionEvent event) {
String METHOD_NAME = "setPassword";
logger.entering(CLASS_NAME, "setPassword");
final String userName = WebCenterSecurityUtils.getUserName();
try {
FacesContext fCtx = FacesContext.getCurrentInstance();
Application app = fCtx.getApplication();
// This managed bean returns if the Change Password is allowed in WebCenter
boolean allowPasswordChange = ((Boolean)ADFContext.getCurrent().getExpressionEvaluator().evaluate("#{o_w_wa_i_v_b_changePasswordBean.passwordChangeAllowed}")).booleanValue()
if (!allowPasswordChange) {
logger.fine(CLASS_NAME, "setPassword", "skipping passwd change as admin has disabled it");
WCApplicationContext.getCurrentInstance().displayWarning(WebCenterResourceBundle.class.getCanonicalName(), "PREFERENCE_PASSWORD_DISABLED", null);
}
else {
String oldPassword = getOldPassword();
String newPassword = getNewPassword();
if (logger.isFiner()) {
logger.finer(CLASS_NAME, "setPassword", "Changing the password for useName = " + userName);
}
WebCenterSecurityUtils.setPassword(userName, oldPassword, newPassword);
setOldPassword("");
setNewPassword("");
setNewPasswordConfirm("");
if (logger.isFiner()) {
logger.finer(CLASS_NAME, "setPassword", "After invoking method binding object for service using EL: #{bindings.setUserPassword.execute}");
}
}
}
catch (Exception ex) {
WebCenterException wex;
if ((ex instanceof WebCenterException)) {
wex = (WebCenterException)ex;
} else {
wex = new WebCenterException("Unable to set the password");
}
WCApplicationContext.getCurrentInstance().displayError(wex);
}
finally {
logger.exiting(CLASS_NAME, "setPassword");
}
}
As you can see in the code above, the important
JSFF Snippet:
<af:panelFormLayout labelWidth="200" rows="3" maxColumns="1"
partialTriggers="save" id="pfl1">
<af:inputText label="Old Password"
value="#{backingBeanScope.myPasswordBean.oldPassword}"
secret="true"
validator="#{webcenterValidator.oldPasswordValidator}"
required="true" id="it1"/>
<af:spacer height="10" id="s3"/>
<af:inputText label="New Password"
value="#{backingBeanScope.myPasswordBean.newPassword}"
secret="true"
validator="#{webcenterValidator.newPasswordValidator}"
required="true" id="it2"/>
<af:spacer height="10" id="s4"/>
<af:inputText label="Confirm New Password"
value="#{backingBeanScope.myPasswordBean.newPasswordConfirm}"
secret="true"
validator="#{webcenterValidator.newPasswordConfirmValidator}"
required="true" id="it3"/>
</af:panelFormLayout>
<af:commandButton id="save" partialSubmit="true"
text="Save"
actionListener="#{backingBeanScope.myPasswordBean.setPassword}"/>
Note: Remember that your LDAP has to be conigured with the rights for allowing users to change the password.
TIP: Validators where not included in this post, but it is using the defined by WebCenter ;).
Hi Daneil, Thanks for the example, can you plz suggest me what is the library/jar name for WebCenterSecurityUtils ?
ReplyDelete