org.apache.directory.api.ldap.model.url.LdapUrl Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.url.LdapUrl. 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: ApiLdapModelOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Override
protected void useBundleClasses() throws Exception
{
    new Dn( "dc=example,dc=com" ); // uses FastDnParser
    new Dn( "cn=a+sn=b,dc=example,dc=com" ); // uses ComplexDnparser (antlr based)
    new Value( "foo" );
    new DefaultAttribute( "cn" );
    new DefaultEntry();

    AttributeUtils.toJndiAttribute( new DefaultAttribute( "cn" ) );
    
    new BindRequestImpl();

    new EqualityNode<String>( "cn", "foo" );

    new LdapUrl( "ldap://ldap.example.com:10389/dc=example,dc=com?objectclass" );

    new ObjectClassDescriptionSchemaParser()
        .parse( "( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )" );
    
    SchemaObject schemaObject = new LdapSyntax( "1.2.3" );
    new Registries().getGlobalOidRegistry().register( schemaObject );
    new Registries().getLoadedSchemas();
}
 
Example #2
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test UTF-8 values in extension values.
 */
@Test
public void testLdapURLExtensionWithUtf8Values() throws Exception
{
    String germanChars = new String(
        new byte[]
            { ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                ( byte ) 0xC3, ( byte ) 0xBC }, StandardCharsets.UTF_8 );

    LdapUrl url1 = new LdapUrl();
    url1.setHost( "localhost" );
    url1.setPort( 123 );
    url1.setDn( Dn.EMPTY_DN );
    url1.getExtensions().add( new Extension( false, "X-CONNECTION-NAME", germanChars ) );
    assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=%C3%84%C3%96%C3%9C%C3%9F%C3%A4%C3%B6%C3%BC", url1
        .toString() );

    LdapUrl url2 = new LdapUrl(
        "ldap://localhost:123/????X-CONNECTION-NAME=%c3%84%c3%96%c3%9c%c3%9f%c3%a4%c3%b6%c3%bc" );
    assertEquals( germanChars, url1.getExtensionValue( "X-CONNECTION-NAME" ) );
    assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=%C3%84%C3%96%C3%9C%C3%9F%C3%A4%C3%B6%C3%BC", url2
        .toString() );
}
 
Example #3
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test the setScheme() method
 */
@Test
public void testDnSetScheme() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl();
    assertEquals( "ldap://", url.getScheme() );

    url.setScheme( "invalid" );
    assertEquals( "ldap://", url.getScheme() );

    url.setScheme( "ldap://" );
    assertEquals( "ldap://", url.getScheme() );

    url.setScheme( "ldaps://" );
    assertEquals( "ldaps://", url.getScheme() );

    url.setScheme( null );
    assertEquals( "ldap://", url.getScheme() );
}
 
Example #4
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test the setPort() method
 */
@Test
public void testDnSetPort() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl();
    assertEquals( -1, url.getPort() );

    url.setPort( 389 );
    assertEquals( 389, url.getPort() );
    assertEquals( "ldap://:389/", url.toString() );

    url.setPort( 0 );
    assertEquals( -1, url.getPort() );
    assertEquals( "ldap:///", url.toString() );

    url.setPort( 65536 );
    assertEquals( -1, url.getPort() );
    assertEquals( "ldap:///", url.toString() );
}
 
Example #5
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test the setDn() method
 */
@Test
public void testDnSetDn() throws LdapURLEncodingException, LdapInvalidDnException
{
    LdapUrl url = new LdapUrl();
    assertNull( url.getDn() );

    Dn dn = new Dn( "dc=example,dc=com" );
    url.setDn( dn );
    assertEquals( dn, url.getDn() );
    assertEquals( "ldap:///dc=example,dc=com", url.toString() );

    url.setDn( null );
    assertNull( url.getDn() );
    assertEquals( "ldap:///", url.toString() );
}
 
Example #6
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test the setScope() method
 */
@Test
public void testDnSetScope() throws LdapURLEncodingException, LdapInvalidDnException
{
    LdapUrl url = new LdapUrl();
    assertEquals( SearchScope.OBJECT, url.getScope() );

    url.setDn( new Dn( "dc=example,dc=com" ) );

    url.setScope( SearchScope.ONELEVEL );
    assertEquals( SearchScope.ONELEVEL, url.getScope() );
    assertEquals( "ldap:///dc=example,dc=com??one", url.toString() );

    url.setScope( SearchScope.SUBTREE );
    assertEquals( SearchScope.SUBTREE, url.getScope() );
    assertEquals( "ldap:///dc=example,dc=com??sub", url.toString() );

    url.setScope( -1 );
    assertEquals( SearchScope.OBJECT, url.getScope() );
    assertEquals( "ldap:///dc=example,dc=com", url.toString() );
}
 
Example #7
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test the setFilter() method
 */
@Test
public void testDnSetFilter() throws LdapURLEncodingException, LdapInvalidDnException
{
    LdapUrl url = new LdapUrl();
    assertNull( url.getFilter() );

    url.setDn( new Dn( "dc=example,dc=com" ) );

    url.setFilter( "(objectClass=person)" );
    assertEquals( "(objectClass=person)", url.getFilter() );
    assertEquals( "ldap:///dc=example,dc=com???(objectClass=person)", url.toString() );

    url.setFilter( "(cn=Babs Jensen)" );
    assertEquals( "(cn=Babs Jensen)", url.getFilter() );
    assertEquals( "ldap:///dc=example,dc=com???(cn=Babs%20Jensen)", url.toString() );

    url.setFilter( null );
    assertNull( url.getFilter() );
    assertEquals( "ldap:///dc=example,dc=com", url.toString() );
}
 
Example #8
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test a LdapUrl without a host but with a Dn
 *
 */
@Test
public void testLdapURLNoHostDN() throws LdapURLEncodingException
{
    try
    {
        LdapUrl url = new LdapUrl( "ldap:///ou=system" );

        assertEquals( "ldap:///ou=system", url.toString() );

    }
    catch ( LdapURLEncodingException luee )
    {
        fail();
    }
}
 
Example #9
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test 9 from RFC 2255 LdapUrl
 */
@Test
public void testLdapRFC2255_9() throws LdapURLEncodingException
{
    assertEquals( "ldap:///??sub??!bindname=cn=Manager%2co=Foo", new LdapUrl(
        "ldap:///??sub??!bindname=cn=Manager%2co=Foo" ).toString() );
}
 
Example #10
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, some attributes, a base scope, a filter and some extensions
 *
 */
@Test
public void testLdapURLNoDNAttrsScopeBaseFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/?cn,dc,ou?base?(cn=test)?!a=b,!c" );

    assertEquals( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c", url.toString() );
}
 
Example #11
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test an simple ldaps:// LdapUrl
 */
@Test
public void testDnSimpleLdaps() throws LdapURLEncodingException
{
    assertEquals( "ldaps://directory.apache.org:80/", new LdapUrl( "ldaps://directory.apache.org:80/" )
        .toString() );
}
 
Example #12
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, some attributes an scope base
 *
 */
@Test
public void testLdapURLNoDNAttrsScopeBase() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/?ou,cn?base" );

    assertEquals( "ldap://localhost:123/?ou,cn", url.toString() );
}
 
Example #13
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test the setHost() method
 */
@Test
public void testDnSetHost() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl();
    assertNull( url.getHost() );

    url.setHost( "ldap.apache.org" );
    assertEquals( "ldap.apache.org", url.getHost() );
    assertEquals( "ldap://ldap.apache.org/", url.toString() );

    url.setHost( null );
    assertNull( url.getHost() );
    assertEquals( "ldap:///", url.toString() );
}
 
Example #14
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, some attributes an scope
 *
 */
@Test
public void testLdapURLNoDNAttrsScope() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/?ou,cn?sub" );

    assertEquals( "ldap://localhost:123/?ou,cn?sub", url.toString() );
}
 
Example #15
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test with RFC 3986 reserved characters in extension value.
 *
 *   reserved    = gen-delims / sub-delims
 *   gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
 *   sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
 *                 / "*" / "+" / "," / ";" / "="
 *
 * RFC 4516 specifies that '?' and a ',' must be percent encoded.
 *
 */
@Test
public void testLdapURLExtensionWithRFC3986ReservedCharsAndRFC4616Exception() throws Exception
{
    LdapUrl url1 = new LdapUrl();
    url1.setHost( "localhost" );
    url1.setPort( 123 );
    url1.setDn( Dn.EMPTY_DN );
    url1.getExtensions().add( new Extension( false, "X-CONNECTION-NAME", ":/?#[]@!$&'()*+,;=" ) );
    assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=:/%3F#[]@!$&'()*+%2c;=", url1.toString() );

    LdapUrl url2 = new LdapUrl( "ldap://localhost:123/????X-CONNECTION-NAME=:/%3f#[]@!$&'()*+%2c;=" );
    assertEquals( ":/?#[]@!$&'()*+,;=", url1.getExtensionValue( "X-CONNECTION-NAME" ) );
    assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=:/%3F#[]@!$&'()*+%2c;=", url2.toString() );
}
 
Example #16
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, no attributes, no scope, no filter and some extensions
 *
 */
@Test
public void testLdapURLNoDNNoAttrsNoScopeNoFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/????!a=b,!c" );

    assertEquals( "ldap://localhost:123/????!a=b,!c", url.toString() );
}
 
Example #17
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, no attributes and no scope
 *
 */
@Test
public void testLdapURLNoDNNoAttrsNoScope() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/??" );

    assertEquals( "ldap://localhost:123/", url.toString() );
}
 
Example #18
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn, no attributes, no scope and no filter
 *
 */
@Test
public void testLdapURLNoDNNoAttrsNoScopeNoFilter() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/???" );

    assertEquals( "ldap://localhost:123/", url.toString() );
}
 
Example #19
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with no Dn and attributes
 *
 */
@Test
public void testLdapURLDN() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system" );

    assertEquals( "ldap://localhost:123/ou=system", url.toString() );
}
 
Example #20
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test 8 from RFC 2255 LdapUrl
 */
@Test
public void testLdapRFC2255_8() throws LdapURLEncodingException
{
    assertEquals( "ldap:///??sub??bindname=cn=Manager%2co=Foo", new LdapUrl(
        "ldap:///??sub??bindname=cn=Manager%2co=Foo" ).toString() );
}
 
Example #21
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test 7 from RFC 2255 LdapUrl
 */
@Test
public void testLdapRFC2255_7() throws LdapURLEncodingException
{
    assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5C00%5C00%5C00%5C04)", new LdapUrl(
        "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)" ).toString() );
}
 
Example #22
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with a Dn, some attributes, no scope, no filter and some extensions
 *
 */
@Test
public void testLdapURLDNAttrsNoScopeNoFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c" );

    assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
}
 
Example #23
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with a Dn, no attributes, a base scope, no filter and some extensions
 *
 */
@Test
public void testLdapURLDNNoAttrsScopeBaseNoFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system??base??!a=b,!c" );

    assertEquals( "ldap://localhost:123/ou=system????!a=b,!c", url.toString() );
}
 
Example #24
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with a Dn, some attributes, a base scope, no filter and some extensions
 *
 */
@Test
public void testLdapURLDNAttrsScopeBaseNoFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system?cn,ou,dc?base??!a=b,!c" );

    assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
}
 
Example #25
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a LdapUrl with an extension after an empty extension.
 */
@Test
public void testLdapURLExtensionAfterEmptyExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/????!a=b,!c,d=e" );

    assertEquals( "ldap://localhost:123/????!a=b,!c,d=e", url.toString() );
}
 
Example #26
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test 2 from RFC 2255 LdapUrl
 */
@Test
public void testLdapRFC2255_2() throws LdapURLEncodingException
{
    assertEquals( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", new LdapUrl(
        "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US" ).toString() );
}
 
Example #27
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with a Dn, no attributes, no scope, a filter and some extensions
 *
 */
@Test
public void testLdapURLDNNoAttrsNoScopeFilterExtension() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c" );

    assertEquals( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c", url.toString() );
}
 
Example #28
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test 1 from RFC 2255 LdapUrl
 */
@Test
public void testLdapRFC2255_1() throws LdapURLEncodingException
{
    assertEquals( "ldap:///o=University%20of%20Michigan,c=US", new LdapUrl(
        "ldap:///o=University%20of%20Michigan,c=US" ).toString() );
}
 
Example #29
Source File: LdapUrlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test a LdapUrl with a Dn, some attributes an scope
 *
 */
@Test
public void testLdapURLDNAttrsScope() throws LdapURLEncodingException
{
    LdapUrl url = new LdapUrl( "ldap://localhost:123/ou=system?ou,cn?sub" );

    assertEquals( "ldap://localhost:123/ou=system?ou,cn?sub", url.toString() );
}
 
Example #30
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private LdapReferralException buildReferralException( Entry parentEntry, Dn childDn ) throws LdapException
{
    // Get the Ref attributeType
    Attribute refs = parentEntry.get( SchemaConstants.REF_AT );

    List<String> urls = new ArrayList<String>();

    try
    {
        // manage each Referral, building the correct URL for each of them
        for ( Value<?> url : refs )
        {
            // we have to replace the parent by the referral
            LdapUrl ldapUrl = new LdapUrl( url.getString() );

            // We have a problem with the Dn : we can't use the UpName,
            // as we may have some spaces around the ',' and '+'.
            // So we have to take the Rdn one by one, and create a
            // new Dn with the type and value UP form

            Dn urlDn = ldapUrl.getDn().add( childDn );

            ldapUrl.setDn( urlDn );
            urls.add( ldapUrl.toString() );
        }
    }
    catch ( LdapURLEncodingException luee )
    {
        throw new LdapOperationErrorException( luee.getMessage(), luee );
    }

    // Return with an exception
    LdapReferralException lre = new LdapReferralException( urls );
    lre.setRemainingDn( childDn );
    lre.setResolvedDn( parentEntry.getDn() );
    lre.setResolvedObject( parentEntry );

    return lre;
}