Java Code Examples for org.apache.directory.api.ldap.model.url.LdapUrl#setDn()
The following examples show how to use
org.apache.directory.api.ldap.model.url.LdapUrl#setDn() .
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: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test with RFC 3986 unreserved characters in extension value. * * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */ @Test public void testLdapURLExtensionWithRFC3986UnreservedChars() 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", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~" ) ); assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url1.toString() ); LdapUrl url2 = new LdapUrl( "ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~" ); assertEquals( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url1 .getExtensionValue( "X-CONNECTION-NAME" ) ); assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url2.toString() ); }
Example 6
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * test the setAttributes() method */ @Test public void testDnSetAttributes() throws LdapURLEncodingException, LdapInvalidDnException { LdapUrl url = new LdapUrl(); assertNotNull( url.getAttributes() ); assertTrue( url.getAttributes().isEmpty() ); List<String> attributes = new ArrayList<String>(); url.setDn( new Dn( "dc=example,dc=com" ) ); url.setAttributes( null ); assertNotNull( url.getAttributes() ); assertTrue( url.getAttributes().isEmpty() ); assertEquals( "ldap:///dc=example,dc=com", url.toString() ); attributes.add( "cn" ); url.setAttributes( attributes ); assertNotNull( url.getAttributes() ); assertEquals( 1, url.getAttributes().size() ); assertEquals( "ldap:///dc=example,dc=com?cn", url.toString() ); attributes.add( "userPassword;binary" ); url.setAttributes( attributes ); assertNotNull( url.getAttributes() ); assertEquals( 2, url.getAttributes().size() ); assertEquals( "ldap:///dc=example,dc=com?cn,userPassword;binary", url.toString() ); }
Example 7
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test comma in extension value. */ @Test public void testLdapURLExtensionWithCommaValue() 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=%2c", url1.toString() ); LdapUrl url2 = new LdapUrl( "ldap://localhost:123/????X-CONNECTION-NAME=%2c" ); assertEquals( ",", url1.getExtensionValue( "X-CONNECTION-NAME" ) ); assertEquals( "ldap://localhost:123/????X-CONNECTION-NAME=%2c", url2.toString() ); }
Example 8
Source File: LdapUrlTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: DefaultOperationManager.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
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; }
Example 10
Source File: DefaultOperationManager.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: DefaultOperationManager.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
private LdapReferralException buildReferralExceptionForSearch( Entry parentEntry, Dn childDn, SearchScope scope ) throws LdapException { // Get the Ref attributeType Attribute refs = parentEntry.get( SchemaConstants.REF_AT ); List<String> urls = new ArrayList<String>(); // manage each Referral, building the correct URL for each of them for ( Value<?> url : refs ) { // we have to replace the parent by the referral try { LdapUrl ldapUrl = new LdapUrl( url.getString() ); StringBuilder urlString = new StringBuilder(); if ( ( ldapUrl.getDn() == null ) || ( ldapUrl.getDn() == Dn.ROOT_DSE ) ) { ldapUrl.setDn( parentEntry.getDn() ); } else { // 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 ); } urlString.append( ldapUrl.toString() ).append( "??" ); switch ( scope ) { case OBJECT: urlString.append( "base" ); break; case SUBTREE: urlString.append( "sub" ); break; case ONELEVEL: urlString.append( "one" ); break; } urls.add( urlString.toString() ); } catch ( LdapURLEncodingException luee ) { // The URL is not correct, returns it as is urls.add( url.getString() ); } } // Return with an exception LdapReferralException lre = new LdapReferralException( urls ); lre.setRemainingDn( childDn ); lre.setResolvedDn( parentEntry.getDn() ); lre.setResolvedObject( parentEntry ); return lre; }
Example 12
Source File: DefaultOperationManager.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
private LdapReferralException buildReferralExceptionForSearch( Entry parentEntry, Dn childDn, SearchScope scope ) throws LdapException { // Get the Ref attributeType Attribute refs = parentEntry.get( SchemaConstants.REF_AT ); List<String> urls = new ArrayList<String>(); // manage each Referral, building the correct URL for each of them for ( Value<?> url : refs ) { // we have to replace the parent by the referral try { LdapUrl ldapUrl = new LdapUrl( url.getString() ); StringBuilder urlString = new StringBuilder(); if ( ( ldapUrl.getDn() == null ) || ( ldapUrl.getDn() == Dn.ROOT_DSE ) ) { ldapUrl.setDn( parentEntry.getDn() ); } else { // 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 ); } urlString.append( ldapUrl.toString() ).append( "??" ); switch ( scope ) { case OBJECT: urlString.append( "base" ); break; case SUBTREE: urlString.append( "sub" ); break; case ONELEVEL: urlString.append( "one" ); break; } urls.add( urlString.toString() ); } catch ( LdapURLEncodingException luee ) { // The URL is not correct, returns it as is urls.add( url.getString() ); } } // Return with an exception LdapReferralException lre = new LdapReferralException( urls ); lre.setRemainingDn( childDn ); lre.setResolvedDn( parentEntry.getDn() ); lre.setResolvedObject( parentEntry ); return lre; }