use of javax.naming.ldap.BasicControl in project ldapsdk by pingidentity.
the class JNDIConverterTestCase method testToSDKControlWithValue.
/**
* Provides test coverage for the method used to convert a non-{@code null}
* JNDI control to an SDK control for a control which has a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testToSDKControlWithValue() throws Exception {
BasicControl jndiControl = new BasicControl("1.2.3.4", true, new ASN1OctetString("foo").encode());
Control sdkControl = JNDIConverter.convertControl(jndiControl);
assertNotNull(sdkControl);
assertNotNull(sdkControl.getOID());
assertEquals(sdkControl.getOID(), "1.2.3.4");
assertTrue(sdkControl.isCritical());
assertNotNull(sdkControl.getValue());
assertEquals(sdkControl.getValue().stringValue(), "foo");
}
use of javax.naming.ldap.BasicControl in project ldapsdk by pingidentity.
the class JNDIConverterTestCase method testToSDKControls.
/**
* Provides test coverage for the method used to convert a non-empty array of
* JNDI controls to an array of SDK controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testToSDKControls() throws Exception {
Control[] sdkControls = JNDIConverter.convertControls(new BasicControl("1.2.3.4", false, null), new BasicControl("1.2.3.5", true, new ASN1OctetString("foo").encode()));
assertNotNull(sdkControls);
assertEquals(sdkControls.length, 2);
assertEquals(sdkControls[0].getOID(), "1.2.3.4");
assertEquals(sdkControls[1].getOID(), "1.2.3.5");
}
use of javax.naming.ldap.BasicControl in project ldapsdk by pingidentity.
the class JNDIConverterTestCase method testToSDKControlWithoutValue.
/**
* Provides test coverage for the method used to convert a non-{@code null}
* JNDI control to an SDK control for a control which does not have a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testToSDKControlWithoutValue() throws Exception {
BasicControl jndiControl = new BasicControl("1.2.3.4", false, null);
Control sdkControl = JNDIConverter.convertControl(jndiControl);
assertNotNull(sdkControl);
assertNotNull(sdkControl.getOID());
assertEquals(sdkControl.getOID(), "1.2.3.4");
assertFalse(sdkControl.isCritical());
assertNull(sdkControl.getValue());
}
use of javax.naming.ldap.BasicControl in project directory-ldap-api by apache.
the class DefaultLdapCodecService method toJndiControl.
/**
* {@inheritDoc}
*/
@Override
public javax.naming.ldap.Control toJndiControl(Control control) throws EncoderException {
// We don't know if it's a request or a response control. Test with request contriols
ControlFactory<?> factory = requestControlFactories.get(control.getOid());
if (factory == null) {
if (control instanceof OpaqueControl) {
return new BasicControl(control.getOid(), control.isCritical(), ((OpaqueControl) control).getEncodedValue());
} else {
return new BasicControl(control.getOid(), control.isCritical(), null);
}
} else {
Asn1Buffer asn1Buffer = new Asn1Buffer();
factory.encodeValue(asn1Buffer, control);
return new BasicControl(control.getOid(), control.isCritical(), asn1Buffer.getBytes().array());
}
}
use of javax.naming.ldap.BasicControl in project keycloak by keycloak.
the class LDAPServerPolicyHintsDecorator method beforeLDAPOperation.
@Override
public void beforeLDAPOperation(LdapContext ldapContext, LDAPOperationManager.LdapOperation ldapOperation) throws NamingException {
logger.debug("Applying LDAP_PASSWORD_POLICY_HINTS_OID before update password");
final byte[] controlData = { 48, (byte) 132, 0, 0, 0, 3, 2, 1, 1 };
// Rather using deprecated OID as it works from MSAD 2008-R2 when the newer works from MSAD 2012
BasicControl control = new BasicControl(LDAP_SERVER_POLICY_HINTS_DEPRECATED_OID, true, controlData);
BasicControl[] controls = new BasicControl[] { control };
ldapContext.setRequestControls(controls);
}
Aggregations