Search in sources :

Example 1 with BasicControl

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");
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) BasicControl(javax.naming.ldap.BasicControl) BasicControl(javax.naming.ldap.BasicControl) Test(org.testng.annotations.Test)

Example 2 with BasicControl

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");
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) BasicControl(javax.naming.ldap.BasicControl) BasicControl(javax.naming.ldap.BasicControl) Test(org.testng.annotations.Test)

Example 3 with BasicControl

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());
}
Also used : Control(com.unboundid.ldap.sdk.Control) BasicControl(javax.naming.ldap.BasicControl) BasicControl(javax.naming.ldap.BasicControl) Test(org.testng.annotations.Test)

Example 4 with BasicControl

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());
    }
}
Also used : Asn1Buffer(org.apache.directory.api.asn1.util.Asn1Buffer) BasicControl(javax.naming.ldap.BasicControl) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl)

Example 5 with BasicControl

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);
}
Also used : BasicControl(javax.naming.ldap.BasicControl)

Aggregations

BasicControl (javax.naming.ldap.BasicControl)7 Test (org.testng.annotations.Test)4 Control (com.unboundid.ldap.sdk.Control)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 NamingEnumeration (javax.naming.NamingEnumeration)1 NamingException (javax.naming.NamingException)1 PartialResultException (javax.naming.PartialResultException)1 Attributes (javax.naming.directory.Attributes)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 LdapContext (javax.naming.ldap.LdapContext)1 Asn1Buffer (org.apache.directory.api.asn1.util.Asn1Buffer)1 OpaqueControl (org.apache.directory.api.ldap.model.message.controls.OpaqueControl)1 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)1 Attribute (org.identityconnectors.framework.common.objects.Attribute)1 ConnectorObjectBuilder (org.identityconnectors.framework.common.objects.ConnectorObjectBuilder)1