org.apache.directory.api.ldap.model.message.Control Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.message.Control. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistentSearchFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
    PersistentSearch persistentSearch = ( PersistentSearch ) control;
    int start = buffer.getPos();

    // The returnECs flag
    BerValue.encodeBoolean( buffer, persistentSearch.isReturnECs() );

    // The changeOnly flag
    BerValue.encodeBoolean( buffer, persistentSearch.isChangesOnly() );

    // The changeTypes
    BerValue.encodeInteger( buffer, persistentSearch.getChangeTypes() );

    // The PersistentSearch sequence
    BerValue.encodeSequence( buffer, start );
}
 
Example #2
Source File: SortResponseFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
    SortResponse sortResponse = ( SortResponse ) control;

    int start = buffer.getPos();

    // The attributeType, if any
    if ( sortResponse.getAttributeName() != null )
    {
        BerValue.encodeOctetString( buffer, ( byte ) ATTRIBUTE_TYPE_TAG,
            Strings.getBytesUtf8Ascii( sortResponse.getAttributeName() ) );
    }

    // The sortResult
    BerValue.encodeEnumerated( buffer, sortResponse.getSortResult().getVal() );

    // The overall sequence
    BerValue.encodeSequence( buffer, start );
}
 
Example #3
Source File: StoreControlValue.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<Message> container ) throws DecoderException
{
    TLV tlv = container.getCurrentTLV();

    Control control = container.getCurrentControl();

    // Get the current control
    BerValue value = tlv.getValue();

    // Store the value - have to handle the special case of a 0 length value
    if ( tlv.getLength() >= 0 )
    {
        ControlFactory<?> factory = container.getControlFactory();
        factory.decodeValue( control, value.getData() );
    }

    // We can have an END transition
    container.setGrammarEndAllowed( true );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_08203_CONTROL_VALUE, Strings.dumpBytes( value.getData() ) ) );
    }
}
 
Example #4
Source File: AdDirSyncRequestFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
    AdDirSyncRequest adDirSync = ( AdDirSyncRequest ) control;
    int start = buffer.getPos();

    // Encode the cookie
    BerValue.encodeOctetString( buffer, adDirSync.getCookie() );

    // Encode the MaxAttributeCount
    BerValue.encodeInteger( buffer, adDirSync.getMaxAttributeCount() );

    // Encode the ParentFirst value
    BerValue.encodeInteger( buffer, adDirSync.getParentsFirst() );

    // Encode the SEQ
    BerValue.encodeSequence( buffer, start );
}
 
Example #5
Source File: SortRequestFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
    SortRequest sortRequest = ( SortRequest ) control;

    int start = buffer.getPos();

    // Iterate on all the sort keys
    List<SortKey> sortKeys = sortRequest.getSortKeys();

    encodeSortKeys( buffer, sortKeys.iterator() );

    // The overall sequence
    BerValue.encodeSequence( buffer, start );
}
 
Example #6
Source File: JndiUtils.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Convert some LDAP API controls to JNDI controls
 * @param codec The LDAP API service to use
 * @param controls The controls to convert
 * @return Array of JNDI control
 * @throws EncoderException If the conversion failed
 * @deprecated We don't use JNDI anymore
 */
@Deprecated
public static javax.naming.ldap.Control[] toJndiControls( LdapApiService codec, Control... controls )
    throws EncoderException
{
    if ( controls != null )
    {
        javax.naming.ldap.Control[] jndiControls = new javax.naming.ldap.Control[controls.length];
        int i = 0;

        for ( Control control : controls )
        {
            jndiControls[i++] = toJndiControl( codec, control );
        }

        return jndiControls;
    }
    else
    {
        return null;
    }
}
 
Example #7
Source File: AdDirSyncResponseContainer.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new AdDirSyncResponseControl object.
 *
 * @param control The AdDirSyncResponse control to store
 */
public AdDirSyncResponseContainer( Control control )
{
    super();
    this.control = control;
    setGrammar( AdDirSyncResponseGrammar.getInstance() );
    setTransition( AdDirSyncResponseStatesEnum.START_STATE );
}
 
Example #8
Source File: SearchResultReferenceTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element with empty value
 */
@Test
public void testResponseWith1ControlEmptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( SearchResultReferenceTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultReference searchResultReference = ( ( SearchResponse ) parser.getBatchResponse()
        .getCurrentResponse().getDecorated() ).getCurrentSearchResultReference();
    Map<String, Control> controls = searchResultReference.getControls();

    assertEquals( 1, searchResultReference.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #9
Source File: PersistentSearchContainer.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new PSearchControlContainer object pre-populated with a
 * PersistentSearch control
 *
 * @param control The PersistentSearch Control.
 */
public PersistentSearchContainer( Control control )
{
    super();
    setGrammar( PersistentSearchGrammar.getInstance() );
    setTransition( PersistentSearchStates.START_STATE );
    this.control = control;
}
 
Example #10
Source File: StandaloneLdapApiService.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Loads a list of controls from their FQCN.
 *
 * @param controlsList The list of controls to load
 * @param controlFactories The set of control factories already loaded
 * @throws Exception if a control could not be loaded
 */
private void loadControls( List<String> controlsList, Map<String, ControlFactory<? extends Control>> controlFactories )
    throws Exception
{
    // Adding all controls
    if ( !controlsList.isEmpty() )
    {
        for ( String controlFQCN : controlsList )
        {
            loadControl( controlFQCN, controlFactories );
        }
    }
}
 
Example #11
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 3 (optional) Control elements without value
 */
@Test
public void testRequestWith3ControlsWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = addRequest.getControls();

    assertEquals( 3, addRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #12
Source File: ExtendedResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( ExtendedResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = extendedResponse.getControls();

    assertEquals( 1, extendedResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #13
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with Base64 value
 */
@Test
public void testRequestWith1ControlBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput(
            AddRequestTest.class.getResource( "request_with_1_control_base64_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = addRequest.getControls();

    assertEquals( 1, addRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #14
Source File: ExtendedResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element with empty value
 */
@Test
public void testResponseWith1ControlEmptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( ExtendedResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = extendedResponse.getControls();

    assertEquals( 1, extendedResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #15
Source File: ExtendedRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 2 (optional) Control elements
 */
@Test
public void testRequestWith2Controls()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ExtendedRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedRequestDsml<?, ?> extendedRequest =
        ( ExtendedRequestDsml<?, ?> ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = extendedRequest.getControls();

    assertEquals( 2, extendedRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #16
Source File: AuthRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 3 (optional) Control elements without value
 */
@Test
public void testRequestWith3ControlsWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AuthRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = abandonRequest.getControls();

    assertEquals( 3, abandonRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #17
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with empty value
 */
@Test
public void testRequestWith1ControlEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = addRequest.getControls();

    assertEquals( 1, addRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #18
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 1, delResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #19
Source File: UpdateControls.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int hashCode()
{
    int hash = 37;

    hash = hash * 17 + messageId;
    
    for ( Control control : controls )
    {
        hash = hash * 17 + control.hashCode();
    }

    return hash;
}
 
Example #20
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry lookup( Dn dn, Control[] controls, String... attrIds ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );

    if ( controls != null )
    {
        lookupContext.addRequestControls( controls );
    }

    Entry entry = operationManager.lookup( lookupContext );

    return entry;
}
 
Example #21
Source File: AuthRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 2 (optional) Control elements
 */
@Test
public void testRequestWith2Controls()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AuthRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = abandonRequest.getControls();

    assertEquals( 2, abandonRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #22
Source File: PagedResultsFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
    int start = buffer.getPos();

    // The cookie
    BerValue.encodeOctetString( buffer, ( ( PagedResults ) control ).getCookie() );

    // The size
    BerValue.encodeInteger( buffer, ( ( PagedResults ) control ).getSize() );

    // The sequence
    BerValue.encodeSequence( buffer, start );
}
 
Example #23
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Get Password Policy Response Control from LDAP client.
 *
 * @param resp contains reference to LDAP pw policy response.
 * @return PasswordPolicy response control.
 */
protected PasswordPolicy getPwdRespCtrl( Response resp )
{
    Control control = resp.getControls().get( PP_REQ_CTRL.getOid() );
    if ( control == null )
    {
        return null;
    }

    return ( ( PasswordPolicyDecorator ) control ).getDecorated();
}
 
Example #24
Source File: DelRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with empty value
 */
@Test
public void testRequestWith1ControlEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( DelRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteRequest delRequest = ( DeleteRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = delRequest.getControls();

    assertEquals( 1, delRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #25
Source File: DelRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element
 */
@Test
public void testRequestWith1ControlBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput(
            DelRequestTest.class.getResource( "request_with_1_control_base64_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteRequest delRequest = ( DeleteRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = delRequest.getControls();

    assertEquals( 1, delRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #26
Source File: DelRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element
 */
@Test
public void testRequestWith1Control()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( DelRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteRequest delRequest = ( DeleteRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = delRequest.getControls();

    assertEquals( 1, delRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #27
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 2 (optional) Control elements
 */
@Test
public void testResponseWith2Controls()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AddResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 2, addResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #28
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 3 (optional) Control elements without value
 */
@Test
public void testRequestWith3ControlsWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = compareRequest.getControls();

    assertEquals( 3, compareRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #29
Source File: StandaloneLdapApiService.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Loads a control from its FQCN.
 *
 * @param controlFQCN The control FQCN
 * @param controlFactories The set of control factories already loaded
 * @throws Exception If the control could not be loaded
 */
private void loadControl( String controlFQCN, Map<String, ControlFactory<? extends Control>> controlFactories )
    throws Exception
{
    if ( controlFactories.containsKey( controlFQCN ) )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_06003_CONTROL_FACTORY_ALREADY_LOADED, controlFQCN ) );
        }

        return;
    }

    Class<?>[] types = new Class<?>[]
        { LdapApiService.class };
    // note, trimming whitespace doesnt hurt as it is a class name and
    // helps DI containers that use xml config as xml ignores whitespace
    @SuppressWarnings("unchecked")
    Class<? extends ControlFactory<?>> clazz = ( Class<? extends ControlFactory<?>> ) Class
        .forName( controlFQCN.trim() );
    Constructor<?> constructor = clazz.getConstructor( types );

    ControlFactory<?> factory = ( ControlFactory<?> ) constructor.newInstance( this );
    controlFactories.put( factory.getOid(), factory );

    if ( LOG.isInfoEnabled() )
    {
        LOG.info( I18n.msg( I18n.MSG_06004_REGISTERED_CONTROL_FACTORY, factory.getOid() ) );
    }
}
 
Example #30
Source File: AuthResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 3 (optional) Control elements without value
 */
@Test
public void testResponseWith3ControlsWithoutValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AuthResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = bindResponse.getControls();

    assertEquals( 3, bindResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}