Search in sources :

Example 76 with Attributes

use of javax.naming.directory.Attributes in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserRFC2849Sample3VariousSpacing.

@Test
public void testLdifParserRFC2849Sample3VariousSpacing() throws LdapLdifException, Exception {
    String ldif = "objectclass:top\n" + "objectclass:   person   \n" + "objectclass:organizationalPerson\n" + "cn:Gern Jensen\n" + "cn:Gern O Jensen\n" + "sn:Jensen\n" + "uid:gernj\n" + "telephonenumber:+1 408 555 1212  \n" + "description::  V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu  ";
    LdifAttributesReader reader = new LdifAttributesReader();
    Attributes attributes = reader.parseAttributes(ldif);
    javax.naming.directory.Attribute attr = attributes.get("objectclass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains("person"));
    assertTrue(attr.contains("organizationalPerson"));
    attr = attributes.get("cn");
    assertTrue(attr.contains("Gern Jensen"));
    assertTrue(attr.contains("Gern O Jensen"));
    attr = attributes.get("sn");
    assertTrue(attr.contains("Jensen"));
    attr = attributes.get("uid");
    assertTrue(attr.contains("gernj"));
    attr = attributes.get("telephonenumber");
    assertTrue(attr.contains("+1 408 555 1212"));
    attr = attributes.get("description");
    assertTrue(attr.contains("What a careful reader you are!  This value is base-64-encoded because it has a control character in it (a CR).\r  By the way, you should really get out more.".getBytes(StandardCharsets.UTF_8)));
    reader.close();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 77 with Attributes

use of javax.naming.directory.Attributes in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserCommentsEmptyLines.

@Test
public void testLdifParserCommentsEmptyLines() throws NamingException, Exception {
    String ldif = "#\n" + "#  Licensed to the Apache Software Foundation (ASF) under one\n" + "#  or more contributor license agreements.  See the NOTICE file\n" + "#  distributed with this work for additional information\n" + "#  regarding copyright ownership.  The ASF licenses this file\n" + "#  to you under the Apache License, Version 2.0 (the\n" + "#  \"License\"); you may not use this file except in compliance\n" + "#  with the License.  You may obtain a copy of the License at\n" + "#  \n" + "#    http://www.apache.org/licenses/LICENSE-2.0\n" + "#  \n" + "#  Unless required by applicable law or agreed to in writing,\n" + "#  software distributed under the License is distributed on an\n" + "#  \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + "#  KIND, either express or implied.  See the License for the\n" + "#  specific language governing permissions and limitations\n" + "#  under the License. \n" + "#  \n" + "#\n" + "#\n" + "#   EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" + "#\n" + "#   http://www.rfc-editor.org/rfc/rfc2606.txt\n" + "#\n" + "#\n" + "\n" + "#\n" + "# This ACI allows brouse access to the root suffix and one level below that to anyone.\n" + "# At this level there is nothing critical exposed.  Everything that matters is one or\n" + "# more levels below this.\n" + "#\n" + "\n" + "objectClass: top\n" + "objectClass: subentry\n" + "objectClass: accessControlSubentry\n" + "subtreeSpecification: { maximum 1 }\n" + "prescriptiveACI: { identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }\n";
    LdifAttributesReader reader = new LdifAttributesReader();
    Attributes attributes = reader.parseAttributes(ldif);
    javax.naming.directory.Attribute attr = attributes.get("objectClass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains(SchemaConstants.SUBENTRY_OC));
    assertTrue(attr.contains("accessControlSubentry"));
    attr = attributes.get("subtreeSpecification");
    assertTrue(attr.contains("{ maximum 1 }"));
    attr = attributes.get("prescriptiveACI");
    assertTrue(attr.contains("{ identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }"));
    reader.close();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 78 with Attributes

use of javax.naming.directory.Attributes in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserRFC2849Sample4.

@Test
public void testLdifParserRFC2849Sample4() throws NamingException, Exception {
    String ldif = "# dn:: ou=���������,o=Airius\n" + "objectclass: top\n" + "objectclass: organizationalUnit\n" + "ou:: 5Za25qWt6YOo\n" + "# ou:: ���������\n" + "ou;lang-ja:: 5Za25qWt6YOo\n" + "# ou;lang-ja:: ���������\n" + "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" + "# ou;lang-ja:: ������������������\n" + "ou;lang-en: Sales\n" + "description: Japanese office\n";
    LdifAttributesReader reader = new LdifAttributesReader();
    Attributes attributes = reader.parseAttributes(ldif);
    String[][] values = { { "objectclass", "top" }, { "objectclass", "organizationalUnit" }, { "ou", "\u55b6\u696d\u90e8" }, { "ou;lang-ja", "\u55b6\u696d\u90e8" }, // 3048 = ���, 3044 = ���, 304e = ���
    { "ou;lang-ja;phonetic", "\u3048\u3044\u304e\u3087\u3046\u3076" }, // 3087 = ���, 3046 = ���, 3076 = ���
    { "ou;lang-en", "Sales" }, { "description", "Japanese office" } };
    for (int j = 0; j < values.length; j++) {
        javax.naming.directory.Attribute attr = attributes.get(values[j][0]);
        if (attr.contains(values[j][1])) {
            assertTrue(true);
        } else {
            assertTrue(attr.contains(values[j][1].getBytes(StandardCharsets.UTF_8)));
        }
    }
    reader.close();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 79 with Attributes

use of javax.naming.directory.Attributes in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserRFC2849Sample3.

@Test
public void testLdifParserRFC2849Sample3() throws LdapLdifException, Exception {
    String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Gern Jensen\n" + "cn: Gern O Jensen\n" + "sn: Jensen\n" + "uid: gernj\n" + "telephonenumber: +1 408 555 1212\n" + "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu";
    LdifAttributesReader reader = new LdifAttributesReader();
    Attributes attributes = reader.parseAttributes(ldif);
    javax.naming.directory.Attribute attr = attributes.get("objectclass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains("person"));
    assertTrue(attr.contains("organizationalPerson"));
    attr = attributes.get("cn");
    assertTrue(attr.contains("Gern Jensen"));
    assertTrue(attr.contains("Gern O Jensen"));
    attr = attributes.get("sn");
    assertTrue(attr.contains("Jensen"));
    attr = attributes.get("uid");
    assertTrue(attr.contains("gernj"));
    attr = attributes.get("telephonenumber");
    assertTrue(attr.contains("+1 408 555 1212"));
    attr = attributes.get("description");
    assertTrue(attr.contains("What a careful reader you are!  This value is base-64-encoded because it has a control character in it (a CR).\r  By the way, you should really get out more.".getBytes(StandardCharsets.UTF_8)));
    reader.close();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 80 with Attributes

use of javax.naming.directory.Attributes in project directory-ldap-api by apache.

the class LdifUtilsTest method testConvertToLdifAttrWithNullValues.

/**
 * Tests that null values are correctly encoded
 *
 * @throws NamingException
 */
@Test
public void testConvertToLdifAttrWithNullValues() throws LdapException {
    Attributes attributes = new BasicAttributes("cn", null);
    String ldif = LdifUtils.convertToLdif(attributes);
    assertEquals("cn:\n", ldif);
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) Test(org.junit.Test)

Aggregations

Attributes (javax.naming.directory.Attributes)252 Attribute (javax.naming.directory.Attribute)135 SearchResult (javax.naming.directory.SearchResult)87 NamingException (javax.naming.NamingException)84 BasicAttributes (javax.naming.directory.BasicAttributes)72 ArrayList (java.util.ArrayList)61 BasicAttribute (javax.naming.directory.BasicAttribute)56 SearchControls (javax.naming.directory.SearchControls)55 DirContext (javax.naming.directory.DirContext)49 NamingEnumeration (javax.naming.NamingEnumeration)44 Test (org.junit.Test)34 InitialDirContext (javax.naming.directory.InitialDirContext)32 LdapContext (javax.naming.ldap.LdapContext)29 HashMap (java.util.HashMap)25 InitialLdapContext (javax.naming.ldap.InitialLdapContext)24 Hashtable (java.util.Hashtable)20 HashSet (java.util.HashSet)18 Map (java.util.Map)17 IOException (java.io.IOException)16 Identity (org.olat.core.id.Identity)16