use of com.novell.ldapchai.exception.ChaiPasswordPolicyException in project ldapchai by ldapchai.
the class UserImpl method changePassword.
public final void changePassword(final String oldPassword, final String newPassword) throws ChaiUnavailableException, ChaiPasswordPolicyException, ChaiOperationException {
final String quotedOldPwd = '"' + oldPassword + '"';
final String quotedNewPwd = '"' + newPassword + '"';
final byte[] littleEndianEncodedOldPwd;
final byte[] littleEndianEncodedNewPwd;
try {
littleEndianEncodedOldPwd = quotedOldPwd.getBytes("UTF-16LE");
littleEndianEncodedNewPwd = quotedNewPwd.getBytes("UTF-16LE");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("unexpected error, missing 'UTF-16LE' character encoder", e);
}
try {
replaceBinaryAttribute("unicodePwd", littleEndianEncodedOldPwd, littleEndianEncodedNewPwd);
} catch (ChaiOperationException e) {
if (e.getErrorCode() == ChaiError.UNKNOWN) {
throw new ChaiPasswordPolicyException(e.getMessage(), ChaiError.PASSWORD_BADPASSWORD);
} else {
throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
}
}
}
use of com.novell.ldapchai.exception.ChaiPasswordPolicyException in project ldapchai by ldapchai.
the class InetOrgPersonImpl method setPassword.
public void setPassword(final String newPassword, final boolean enforcePasswordPolicy) throws ChaiUnavailableException, ChaiPasswordPolicyException {
final boolean useNmasSetting = this.getChaiProvider().getChaiConfiguration().getBooleanSetting(ChaiSetting.EDIRECTORY_ENABLE_NMAS);
if (!useNmasSetting) {
try {
writeStringAttribute(ATTR_PASSWORD, newPassword);
} catch (ChaiOperationException e) {
throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
}
} else {
final SetPwdRequest request = new SetPwdRequest();
request.setData(newPassword);
request.setObjectDN(this.getEntryDN());
final ExtendedResponse response;
try {
response = getChaiProvider().extendedOperation(request);
} catch (ChaiOperationException e) {
throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
}
if (response != null) {
final SetPwdResponse setResponse = (SetPwdResponse) response;
final int responseCode = setResponse.getNmasRetCode();
if (responseCode != 0) {
LOGGER.debug("error setting nmas password: " + responseCode);
final String errorString = "nmas error " + responseCode;
throw new ChaiPasswordPolicyException(errorString, ChaiErrors.getErrorForMessage(errorString));
}
}
}
}
Aggregations