Search in sources :

Example 1 with ChaiRequestControl

use of com.novell.ldapchai.ChaiRequestControl in project ldapchai by ldapchai.

the class UserImpl method setPassword.

public void setPassword(final String newPassword, final boolean enforcePasswordPolicy) throws ChaiUnavailableException, ChaiPasswordPolicyException, ChaiOperationException {
    final String quotedPwd = '"' + newPassword + '"';
    final byte[] littleEndianEncodedPwd;
    try {
        littleEndianEncodedPwd = quotedPwd.getBytes("UTF-16LE");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("unexpected error, missing 'UTF-16LE' character encoder", e);
    }
    final byte[][] multiBA = new byte[][] { littleEndianEncodedPwd };
    try {
        if (enforcePasswordPolicy && this.getChaiProvider().getChaiConfiguration().getBooleanSetting(ChaiSetting.AD_SET_POLICY_HINTS_ON_PW_SET)) {
            // 0x1 berEncoded
            final byte[] value = { 48, (byte) 132, 0, 0, 0, 3, 2, 1, 1 };
            final ChaiRequestControl[] controls = new ChaiRequestControl[] { new ChaiRequestControl(LDAP_SERVER_POLICY_HINTS_OID, true, value) };
            chaiProvider.writeBinaryAttribute(this.getEntryDN(), "unicodePwd", multiBA, true, controls);
        } else {
            writeBinaryAttribute("unicodePwd", multiBA);
        }
    } catch (ChaiOperationException e) {
        if (e.getErrorCode() == ChaiError.UNKNOWN) {
            throw new ChaiOperationException(e.getMessage(), ChaiError.PASSWORD_BADPASSWORD);
        } else {
            throw e;
        }
    }
}
Also used : ChaiRequestControl(com.novell.ldapchai.ChaiRequestControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 2 with ChaiRequestControl

use of com.novell.ldapchai.ChaiRequestControl in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method figureControls.

private static Control[] figureControls(final ChaiRequestControl[] chaiControls) {
    final List<Control> returnObj = new ArrayList<Control>();
    for (final ChaiRequestControl chaiControl : chaiControls) {
        final Control control = new Control() {

            public String getOid() {
                return chaiControl.getId();
            }

            public boolean isCritical() {
                return chaiControl.isCritical();
            }

            public void setCritical(final boolean isCritical) {
            }
        };
        returnObj.add(control);
    }
    return returnObj.toArray(new Control[returnObj.size()]);
}
Also used : Control(org.apache.directory.api.ldap.model.message.Control) ChaiRequestControl(com.novell.ldapchai.ChaiRequestControl) ChaiRequestControl(com.novell.ldapchai.ChaiRequestControl) ArrayList(java.util.ArrayList)

Aggregations

ChaiRequestControl (com.novell.ldapchai.ChaiRequestControl)2 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Control (org.apache.directory.api.ldap.model.message.Control)1