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

The following examples show how to use org.apache.directory.api.ldap.model.message.AliasDerefMode. 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: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( Dn dn, String filter, boolean ignoreReferrals ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    ExprNode filterNode = null;

    try
    {
        filterNode = FilterParser.parse( directoryService.getSchemaManager(), filter );
    }
    catch ( ParseException pe )
    {
        throw new LdapInvalidSearchFilterException( pe.getMessage() );
    }

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, SearchScope.OBJECT, filterNode,
        ( String ) null );
    searchContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
    setReferralHandling( searchContext, ignoreReferrals );

    return operationManager.search( searchContext );
}
 
Example #2
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with derefAliases attribute to derefAlways value
 * @throws NamingException
 */
@Test
public void testRequestWithDerefAliasesDerefAlways()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "request_with_derefAliases_derefAlways.xml" )
            .openStream(), "UTF-8" );

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

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
}
 
Example #3
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with derefAliases attribute to derefFindingBaseObj value
 * @throws NamingException
 */
@Test
public void testRequestWithDerefAliasesDerefFindingBaseObj()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "request_with_derefAliases_derefFindingBaseObj.xml" )
            .openStream(), "UTF-8" );

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

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( AliasDerefMode.DEREF_FINDING_BASE_OBJ, searchRequest.getDerefAliases() );
}
 
Example #4
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with derefAliases attribute to derefinSearching value
 * @throws NamingException
 */
@Test
public void testRequestWithDerefAliasesDerefinSearching()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "request_with_derefAliases_derefInSearching.xml" )
            .openStream(), "UTF-8" );

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

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( AliasDerefMode.DEREF_IN_SEARCHING, searchRequest.getDerefAliases() );
}
 
Example #5
Source File: SearchRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with derefAliases attribute to neverDerefAliases value
 * @throws NamingException
 */
@Test
public void testRequestWithDerefAliasesNeverDerefAliases()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( SearchRequestTest.class.getResource( "request_with_derefAliases_neverDerefAliases.xml" )
            .openStream(), "UTF-8" );

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

    SearchRequest searchRequest = ( SearchRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( AliasDerefMode.NEVER_DEREF_ALIASES, searchRequest.getDerefAliases() );
}
 
Example #6
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private void fillGroups(Dn baseDn, String searchQ, List<Dn> groups) throws IOException, LdapException, CursorException {
	try (EntryCursor cursor = new EntryCursorImpl(conn.search(
			new SearchRequestImpl()
				.setBase(baseDn)
				.setFilter(searchQ)
				.setScope(SearchScope.SUBTREE)
				.addAttributes("*")
				.setDerefAliases(AliasDerefMode.DEREF_ALWAYS))))
	{
		while (cursor.next()) {
			try {
				Entry e = cursor.get();
				groups.add(e.getDn());
			} catch (CursorLdapReferralException cle) {
				log.warn(WARN_REFERRAL);
			}
		}
	}
}
 
Example #7
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SearchFuture searchAsync( Dn baseDn, String filter, SearchScope scope, String... attributes )
    throws LdapException
{
    // Create a new SearchRequest object
    SearchRequest searchRequest = new SearchRequestImpl();

    searchRequest.setBase( baseDn );
    searchRequest.setFilter( filter );
    searchRequest.setScope( scope );
    searchRequest.addAttributes( attributes );
    searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );

    // Process the request in blocking mode
    return searchAsync( searchRequest );
}
 
Example #8
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Cursor<Entry> search( Dn dn, String filter, boolean ignoreReferrals ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();
    ExprNode filterNode = null;

    try
    {
        filterNode = FilterParser.parse( directoryService.getSchemaManager(), filter );
    }
    catch ( ParseException pe )
    {
        throw new LdapInvalidSearchFilterException( pe.getMessage() );
    }

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, SearchScope.OBJECT, filterNode,
        ( String ) null );
    searchContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
    setReferralHandling( searchContext, ignoreReferrals );

    return operationManager.search( searchContext );
}
 
Example #9
Source File: DereferenceAliasesProperty.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public AliasDerefMode parseValue(String value) throws GuacamoleException {

    // No value provided, so return null.
    if (value == null)
        return null;

    // Never dereference aliases
    if (value.equals("never"))
        return AliasDerefMode.NEVER_DEREF_ALIASES;

    // Dereference aliases during search operations, but not at base
    if (value.equals("searching"))
        return AliasDerefMode.DEREF_IN_SEARCHING;

    // Dereference aliases to locate base, but not during searches
    if (value.equals("finding"))
        return AliasDerefMode.DEREF_FINDING_BASE_OBJ;

    // Always dereference aliases
    if (value.equals("always"))
        return AliasDerefMode.DEREF_ALWAYS;

    // Anything else is invalid and results in an error
    throw new GuacamoleServerException("Dereference aliases must be one of \"never\", \"searching\", \"finding\", or \"always\".");

}
 
Example #10
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public EntryFilteringCursor list( Dn dn, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    PresenceNode filter = new PresenceNode( OBJECT_CLASS_AT );
    SearchOperationContext searchContext = new SearchOperationContext( this, dn, SearchScope.ONELEVEL, filter,
        returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #11
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public EntryFilteringCursor search( Dn dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, scope, filter, returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #12
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public Cursor<Entry> list( Dn dn, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    PresenceNode filter = new PresenceNode( OBJECT_CLASS_AT );
    SearchOperationContext searchContext = new SearchOperationContext( this, dn, SearchScope.ONELEVEL, filter,
        returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #13
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public Cursor<Entry> search( Dn dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
    String... returningAttributes ) throws LdapException
{
    OperationManager operationManager = directoryService.getOperationManager();

    SearchOperationContext searchContext = new SearchOperationContext( this, dn, scope, filter, returningAttributes );
    searchContext.setAliasDerefMode( aliasDerefMode );

    return operationManager.search( searchContext );
}
 
Example #14
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes )
    throws LdapException
{
    if ( baseDn == null )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_04138_NULL_DN_SEARCH ) );
        }
        
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04129_NULL_BASE_DN ) );
    }

    // Create a new SearchRequest object
    SearchRequest searchRequest = new SearchRequestImpl();

    searchRequest.setBase( baseDn );
    searchRequest.setFilter( filter );
    searchRequest.setScope( scope );
    searchRequest.addAttributes( attributes );
    searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );

    // Process the request in blocking mode
    return new EntryCursorImpl( search( searchRequest ) );
}
 
Example #15
Source File: ScopeNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ScopeNode object.
 * 
 * @param aliasDerefAliases the alias dereferencing mode
 * @param baseDn the search base
 * @param baseId the search ID
 * @param scope the search scope
 */
public ScopeNode( AliasDerefMode aliasDerefAliases, Dn baseDn, String baseId, SearchScope scope )
{
    super( AssertionType.SCOPE );
    this.scope = scope;
    this.baseDn = baseDn;
    this.aliasDerefAliases = aliasDerefAliases;
    this.baseId = baseId;
}
 
Example #16
Source File: SearchRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SearchRequest setDerefAliases( AliasDerefMode aliasDerefAliases )
{
    getDecorated().setDerefAliases( aliasDerefAliases );

    return this;
}
 
Example #17
Source File: SearchRequestDsml.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AliasDerefMode getDerefAliases()
{
    return getDecorated().getDerefAliases();
}
 
Example #18
Source File: SearchRequestMatchingRuleAssertionTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with an extensible match and an
 * empty matchValue
 */
@Test
public void testDecodeSearchRequestExtensibleMatchEmptyMatchValue() throws DecoderException, EncoderException, LdapException
{
    byte[] asn1BER = new byte[]
        {
            0x30, 0x41,
              0x02, 0x01, 0x04,             // messageID
              0x63, 0x3C,
                0x04, 0x1F,                 // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,
                0x0A, 0x01, 0x03,
                0x02, 0x01, 0x00,
                0x02, 0x01, 0x00,
                0x01, 0x01, ( byte ) 0xFF,
                ( byte ) 0xA9, 0x08,
                  ( byte ) 0x81, 0x04,
                    't', 'e', 's', 't',
                  ( byte ) 0x83, 0x00,      //    matchValue      [3] AssertionValue,
                0x30, 0x00                  // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
        };

    ByteBuffer stream = ByteBuffer.allocate( asn1BER.length );
    stream.put( asn1BER );
    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    // Decode a SearchRequest message
    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 4, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 0, searchRequest.getSizeLimit() );
    assertEquals( 0, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // Extended
    ExprNode filter = searchRequest.getFilter();
    ExtensibleNode extensibleNode = ( ExtensibleNode ) filter;
    assertNotNull( extensibleNode );

    assertEquals( "test", extensibleNode.getMatchingRuleId() );
    assertNull( extensibleNode.getAttribute() );
    assertEquals( "", extensibleNode.getValue().getString() );
    assertFalse( extensibleNode.hasDnAttributes() );

    List<String> attributes = searchRequest.getAttributes();

    assertEquals( 0, attributes.size() );

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #19
Source File: SearchRequestMatchingRuleAssertionTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Tests an search request decode with a simple equality match filter.
 */
@Test
public void testDecodeSearchRequestExtensibleMatch() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x63 );
    stream.put( new byte[]
        {
            0x30, 0x61,                         // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,                 // messageID
              0x63, 0x5C,                       //   protocolOp      CHOICE {
                                                //     searchRequest   SearchRequest,
                                                //
                                                // SearchRequest ::= [APPLICATION 3] SEQUENCE {
                0x04, 0x11,                     // "dc=example,dc=com"
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                                                //   scope           ENUMERATED {
                0x0A, 0x01, 0x00,               //      baseObject              (0), ...
                                                //   derefAliases    ENUMERATED {
                0x0A, 0x01, 0x02,               //     derefFindingBaseObj     (2),...
                0x02, 0x01, 0x02,               //   sizeLimit       INTEGER (0 .. maxInt), (2)
                0x02, 0x01, 0x03,               //   timeLimit       INTEGER (0 .. maxInt), (3)
                0x01, 0x01, ( byte ) 0xFF,      //   typesOnly       BOOLEAN, (true)
                ( byte ) 0xA9, 0x21,            //   filter          Filter,
                                                //
                                                // Filter ::= CHOICE {
                                                //   extensibleMatch [9] MatchingRuleAssertion }
                                                //
                                                // MatchingRuleAssertion ::= SEQUENCE {
                  ( byte ) 0x81, 0x13,          //    matchingRule    [1] MatchingRuleId OPTIONAL,
                    '1', '.', '2', '.', '8', '4', '0', '.', '4', '8', '0', '1', '8', '.', '1', '.', '2', '.', '2',
                  ( byte ) 0x82, 0x02,          //    type            [2] AttributeDescription OPTIONAL,
                    'c', 'n',
                  ( byte ) 0x83, 0x03,          //    matchValue      [3] AssertionValue,
                    'a', 'o', 'k',
                                                //    dnAttributes    [4] BOOLEAN DEFAULT FALSE  }
                  ( byte ) 0x84, 0x01, ( byte ) 0xFF,
                0x30, 0x15,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',    // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',    // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2',    // AttributeDescription ::= LDAPString
        });

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.OBJECT, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_FINDING_BASE_OBJ, searchRequest.getDerefAliases() );
    assertEquals( 2, searchRequest.getSizeLimit() );
    assertEquals( 3, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #20
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=*Amos)
 */
@Test
public void testDecodeSearchRequestSubstringFinal() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x67 );
    stream.put( new byte[]
        {
            0x30, 0x65,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x60,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x15,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x06,
                    ( byte ) 0x82, 0x04,
                      'A', 'm', 'o', 's',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( null, substringNode.getInitial() );
    assertEquals( 0, substringNode.getAny().size() );
    assertEquals( "Amos", substringNode.getFinal() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #21
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyAny() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x67 );
    stream.put( new byte[]
        {
            0x30, 0x65,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x60,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x15,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x06,
                    ( byte ) 0x80, 0x01,
                      't',
                    ( byte ) 0x81, 0x01,
                      '*',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',    // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'     // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( "t", substringNode.getInitial() );
    assertEquals( "*", substringNode.getAny().get( 0 ) );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #22
Source File: SearchRequestDsml.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    SearchRequest request = getDecorated();

    // Dn
    if ( request.getBase() != null )
    {
        element.addAttribute( "dn", request.getBase().getName() );
    }

    // Scope
    SearchScope scope = request.getScope();
    if ( scope != null )
    {
        if ( scope == SearchScope.OBJECT )
        {
            element.addAttribute( "scope", "baseObject" );
        }
        else if ( scope == SearchScope.ONELEVEL )
        {
            element.addAttribute( "scope", "singleLevel" );
        }
        else if ( scope == SearchScope.SUBTREE )
        {
            element.addAttribute( "scope", "wholeSubtree" );
        }
    }

    // DerefAliases
    AliasDerefMode derefAliases = request.getDerefAliases();

    switch ( derefAliases )
    {
        case NEVER_DEREF_ALIASES:
            element.addAttribute( DEREF_ALIASES, "neverDerefAliases" );
            break;

        case DEREF_ALWAYS:
            element.addAttribute( DEREF_ALIASES, "derefAlways" );
            break;

        case DEREF_FINDING_BASE_OBJ:
            element.addAttribute( DEREF_ALIASES, "derefFindingBaseObj" );
            break;

        case DEREF_IN_SEARCHING:
            element.addAttribute( DEREF_ALIASES, "derefInSearching" );
            break;

        default:
            throw new IllegalStateException( I18n.err( I18n.ERR_03043_UNEXPECTED_DEREF_ALIAS, derefAliases ) );
    }

    // SizeLimit
    if ( request.getSizeLimit() != 0L )
    {
        element.addAttribute( "sizeLimit", Long.toString( request.getSizeLimit() ) );
    }

    // TimeLimit
    if ( request.getTimeLimit() != 0 )
    {
        element.addAttribute( "timeLimit", Integer.toString( request.getTimeLimit() ) );
    }

    // TypesOnly
    if ( request.getTypesOnly() )
    {
        element.addAttribute( "typesOnly", "true" );
    }

    // Filter
    Element filterElement = element.addElement( "filter" );
    toDsml( filterElement, request.getFilter() );

    // Attributes
    List<String> attributes = request.getAttributes();

    if ( !attributes.isEmpty() )
    {
        Element attributesElement = element.addElement( "attributes" );

        for ( String entryAttribute : attributes )
        {
            attributesElement.addElement( "attribute" ).addAttribute( NAME, entryAttribute );
        }
    }

    return element;
}
 
Example #23
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Entry lookup( Dn dn, Control[] controls, String... attributes ) throws LdapException
{
    Entry entry = null;

    try
    {
        SearchRequest searchRequest = new SearchRequestImpl();

        searchRequest.setBase( dn );
        searchRequest.setFilter( LdapConstants.OBJECT_CLASS_STAR );
        searchRequest.setScope( SearchScope.OBJECT );
        searchRequest.addAttributes( attributes );
        searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );

        if ( ( controls != null ) && ( controls.length > 0 ) )
        {
            searchRequest.addAllControls( controls );
        }

        try ( Cursor<Response> cursor = search( searchRequest ) )
        {
            // Read the response
            if ( cursor.next() )
            {
                // cursor will always hold SearchResultEntry objects cause there is no ManageDsaITControl passed with search request
                entry = ( ( SearchResultEntry ) cursor.get() ).getEntry();
            }

            // Pass through the SaerchResultDone, or stop
            // if we have other responses
            cursor.next();
        }
    }
    catch ( CursorException e )
    {
        throw new LdapException( e.getMessage(), e );
    }
    catch ( IOException ioe )
    {
        throw new LdapException( ioe.getMessage(), ioe );
    }

    return entry;
}
 
Example #24
Source File: StoreSearchRequestDerefAlias.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    SearchRequest searchRequest = container.getMessage();

    TLV tlv = container.getCurrentTLV();

    // We have to check that this is a correct derefAliases
    BerValue value = tlv.getValue();

    try
    {
        int derefAliases = IntegerDecoder.parse( value, LdapCodecConstants.NEVER_DEREF_ALIASES,
            LdapCodecConstants.DEREF_ALWAYS );
        searchRequest.setDerefAliases( AliasDerefMode.getDerefMode( derefAliases ) );
    }
    catch ( IntegerDecoderException ide )
    {
        String msg = I18n.err( I18n.ERR_05150_BAD_DEREF_ALIAS, value.toString() );
        LOG.error( msg );
        throw new DecoderException( msg, ide );
    }


    if ( LOG.isDebugEnabled() )
    {
        switch ( searchRequest.getDerefAliases() )
        {
            case NEVER_DEREF_ALIASES:
                LOG.debug( I18n.msg( I18n.MSG_05161_HANDLING_OBJECT_STRATEGY, "NEVER_DEREF_ALIASES" ) );
                break;

            case DEREF_IN_SEARCHING:
                LOG.debug( I18n.msg( I18n.MSG_05161_HANDLING_OBJECT_STRATEGY, "DEREF_IN_SEARCHING" ) );
                break;

            case DEREF_FINDING_BASE_OBJ:
                LOG.debug( I18n.msg( I18n.MSG_05161_HANDLING_OBJECT_STRATEGY, "DEREF_FINDING_BASE_OBJ" ) );
                break;

            case DEREF_ALWAYS:
                LOG.debug( I18n.msg( I18n.MSG_05161_HANDLING_OBJECT_STRATEGY, "DEREF_ALWAYS" ) );
                break;

            default:
                LOG.debug( I18n.msg( I18n.MSG_05161_HANDLING_OBJECT_STRATEGY, "UNKNOWN" ) );
        }
    }
}
 
Example #25
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAny() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x64 );
    stream.put( new byte[]
        {
            0x30, 0x62,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x5D,                           //      CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x12,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x03,
                    ( byte ) 0x80, 0x01,
                      't',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( "t", substringNode.getInitial() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #26
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * any filter : (objectclass=*t*)
 */
@Test
public void testDecodeSearchRequestSubstringAny() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x64 );
    stream.put( new byte[]
        {
            0x30, 0x62,                         // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,             // messageID
              0x63, 0x5D,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                     // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,               // scope ENUMERATED {
                                                // baseObject (0),
                                                // singleLevel (1),
                                                // wholeSubtree (2) },
                0x0A, 0x01, 0x03,               // derefAliases ENUMERATED {
                                                // neverDerefAliases (0),
                                                // derefInSearching (1),
                                                // derefFindingBaseObj (2),
                                                // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,// sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,// timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,      // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x12,            // Filter ::= CHOICE {
                                                // substrings [4] SubstringFilter
                                                // }
                                                // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x03,
                    ( byte ) 0x81, 0x01,
                      't',
                0x30, 0x15,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',    // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',    // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'     // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( null, substringNode.getInitial() );
    assertEquals( "t", substringNode.getAny().get( 0 ) );
    assertEquals( null, substringNode.getFinal() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #27
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=*t*t)
 */
@Test
public void testDecodeSearchRequestSubstringAnyFinal() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x67 );
    stream.put( new byte[]
        {
            0x30, 0x65,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x60,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x15,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x06,
                    ( byte ) 0x81, 0x01,
                      't',
                    ( byte ) 0x82, 0x01,
                      't',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( null, substringNode.getInitial() );
    assertEquals( "t", substringNode.getAny().get( 0 ) );
    assertEquals( "t", substringNode.getFinal() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #28
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*t*t)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyFinal()
    throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x6A );
    stream.put( new byte[]
        {
            0x30, 0x68,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x63,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x18,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x09,
                    ( byte ) 0x80, 0x01,
                      't',
                    ( byte ) 0x81, 0x01,
                      't',
                    ( byte ) 0x82, 0x01,
                      't',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( "t", substringNode.getInitial() );
    assertEquals( "t", substringNode.getAny().get( 0 ) );
    assertEquals( "t", substringNode.getFinal() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #29
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyAnyFinal()
    throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x67 );
    stream.put( new byte[]
        {
            0x30, 0x65,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x60,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                ( byte ) 0xA4, 0x15,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter
                                                    // }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x06,
                    ( byte ) 0x80, 0x01,
                      't',
                    ( byte ) 0x81, 0x01,
                      't',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( "t", substringNode.getInitial() );
    assertEquals( "t", substringNode.getAny().get( 0 ) );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #30
Source File: SearchRequestSubstringTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=*t*t*t)
 */
@Test
public void testDecodeSearchRequestSubstringAnyAnyFinal() throws DecoderException, EncoderException, LdapException
{

    ByteBuffer stream = ByteBuffer.allocate( 0x6A );
    stream.put( new byte[]
        {
            0x30, 0x68,                             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,                     // messageID
              0x63, 0x63,                           // CHOICE { ..., searchRequest SearchRequest, ...
                                                    // SearchRequest ::= APPLICATION[3] SEQUENCE {
                0x04, 0x1F,                         // baseObject LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x0A, 0x01, 0x01,                   // scope ENUMERATED {
                                                    // baseObject (0),
                                                    // singleLevel (1),
                                                    // wholeSubtree (2) },
                0x0A, 0x01, 0x03,                   // derefAliases ENUMERATED {
                                                    // neverDerefAliases (0),
                                                    // derefInSearching (1),
                                                    // derefFindingBaseObj (2),
                                                    // derefAlways (3) },
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // sizeLimit INTEGER (0 .. maxInt), (1000)
                0x02, 0x02, 0x03, ( byte ) 0xE8,    // timeLimit INTEGER (0 .. maxInt), (1000)
                0x01, 0x01, ( byte ) 0xFF,          // typesOnly BOOLEAN, (TRUE) filter Filter,
                                                    // filter Filter,
                ( byte ) 0xA4, 0x18,                // Filter ::= CHOICE {
                                                    // substrings [4] SubstringFilter }
                                                    // SubstringFilter ::= SEQUENCE {
                  0x04, 0x0B,
                    'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
                  0x30, 0x09,
                    ( byte ) 0x81, 0x01,
                      't',
                    ( byte ) 0x81, 0x01,
                      't',
                    ( byte ) 0x82, 0x01,
                      't',
                0x30, 0x15,                         // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
                  0x04, 0x05,
                    'a', 't', 't', 'r', '0',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '1',        // AttributeDescription ::= LDAPString
                  0x04, 0x05,
                    'a', 't', 't', 'r', '2'         // AttributeDescription ::= LDAPString
    } );

    stream.flip();

    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    Asn1Decoder.decode( stream, ldapMessageContainer );

    SearchRequest searchRequest = ldapMessageContainer.getMessage();

    assertEquals( 1, searchRequest.getMessageId() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString() );
    assertEquals( SearchScope.ONELEVEL, searchRequest.getScope() );
    assertEquals( AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases() );
    assertEquals( 1000, searchRequest.getSizeLimit() );
    assertEquals( 1000, searchRequest.getTimeLimit() );
    assertEquals( true, searchRequest.getTypesOnly() );

    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = ( SubstringNode ) node;
    assertNotNull( substringNode );

    assertEquals( "objectclass", substringNode.getAttribute() );
    assertEquals( null, substringNode.getInitial() );
    assertEquals( "t", substringNode.getAny().get( 0 ) );
    assertEquals( "t", substringNode.getAny().get( 1 ) );
    assertEquals( "t", substringNode.getFinal() );

    // The attributes
    List<String> attributes = searchRequest.getAttributes();

    for ( String attribute : attributes )
    {
        assertNotNull( attribute );
    }

    // Check the encoding
    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, searchRequest );

    assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}