Package org.apache.directory.shared.ldap.model.schema

Examples of org.apache.directory.shared.ldap.model.schema.SchemaObject


     * @throws ParseException
     */
    public static void testNumericOid( AbstractSchemaParser parser, String required ) throws ParseException
    {
        String value = null;
        SchemaObject asd = null;

        // null test
        try
        {
            parser.parse( value );
            fail("Exception expected, null");
        }
        catch ( ParseException pe )
        {
            // expected
        }

        // no oid
        value = "( )";
        try
        {
            parser.parse( value );
            fail("Exception expected, no NUMERICOID");
        }
        catch ( ParseException pe )
        {
            // expected
        }

        // simple
        value = "( 0.1.2.3.4.5.6.7.8.9 " + required + " )";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // simple
        value = "( 123.4567.890 " + required + ")";
        asd = parser.parse( value );
        assertEquals("123.4567.890", asd.getOid());

        // simple with multiple spaces
        value = "(          0.1.2.3.4.5.6.7.8.9         " + required + " )";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // simple w/o spaces
        value = "(0.1.2.3.4.5.6.7.8.9 " + required + ")";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // simple with tabs, newline, comment.
        value = "(\t0.1.2.3.4.5.6.7.8.9\n#comment\n" + required + "\r\n)\r";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // quoted OID
        value = "( '0.1.2.3.4.5.6.7.8.9' " + required + " )";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // quoted OID in parentheses
        value = "( ('0.1.2.3.4.5.6.7.8.9') " + required + " )";
        asd = parser.parse( value );
        assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());

        // too short
        value = "( 1 " + required + " )";
        try
        {
View Full Code Here


     * @throws ParseException
     */
    public static void testNames( AbstractSchemaParser parser, String oid, String required ) throws ParseException
    {
        String value = null;
        SchemaObject asd = null;

        // alpha
        value = "( " + oid + " " + required + " NAME 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' )";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", asd.getNames().get(0));

        // alpha-num-hypen
        value = "( " + oid + " " + required
            + " NAME 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' )";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", asd.getNames().get(0));

        // with parentheses
        value = "( " + oid + " " + required + " NAME ( 'a-z-0-9' ) )";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("a-z-0-9", asd.getNames().get(0));

        // with parentheses, without space
        value = "(" + oid + " " + required + " NAME('a-z-0-9'))";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("a-z-0-9", asd.getNames().get(0));

        // multi with space
        value = " ( " + oid + " " + required + " NAME ( 'test1' 'test2' ) ) ";
        asd = parser.parse( value );
        assertEquals(2, asd.getNames().size());
        assertEquals("test1", asd.getNames().get(0));
        assertEquals("test2", asd.getNames().get(1));

        // multi without space
        value = "(" + oid + " " + required + " NAME('test1''test2''test3'))";
        asd = parser.parse( value );
        assertEquals(3, asd.getNames().size());
        assertEquals("test1", asd.getNames().get(0));
        assertEquals("test2", asd.getNames().get(1));
        assertEquals("test3", asd.getNames().get(2));

        // multi with many spaces
        value = "(          " + oid + " " + required
            + "          NAME          (          'test1'          'test2'          'test3'          )          )";
        asd = parser.parse( value );
        assertEquals(3, asd.getNames().size());
        assertEquals("test1", asd.getNames().get(0));
        assertEquals("test2", asd.getNames().get(1));
        assertEquals("test3", asd.getNames().get(2));

        // multi with tabs, newline, comment, etc.
        value = "(\r\n" + oid + "\r" + required
            + "\nNAME\t(\t\t\t'test1'\t\n\t'test2'\t\r\t'test3'\t\r\n\t)\n#comment\n)";
        asd = parser.parse( value );
        assertEquals(3, asd.getNames().size());
        assertEquals("test1", asd.getNames().get(0));
        assertEquals("test2", asd.getNames().get(1));
        assertEquals("test3", asd.getNames().get(2));

        // lowercase NAME
        value = "( " + oid + " " + required + " name 'test' )";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("test", asd.getNames().get(0));

        // unquoted NAME value
        value = "( " + oid + " " + required + " NAME test )";
        asd = parser.parse( value );
        assertEquals(1, asd.getNames().size());
        assertEquals("test", asd.getNames().get(0));

        // multi unquoted NAME values
        value = " ( " + oid + " " + required + " NAME (test1 test2) ) ";
        asd = parser.parse( value );
        assertEquals(2, asd.getNames().size());
        assertEquals("test1", asd.getNames().get(0));
        assertEquals("test2", asd.getNames().get(1));

        // NAM unknown
        value = "( " + oid + " " + required + " NAM 'test' )";
        try
        {
View Full Code Here

     */
    public static void testDescription( AbstractSchemaParser parser, String oid, String required )
        throws ParseException
    {
        String value = null;
        SchemaObject asd = null;

        // simple
        value = "(" + oid + " " + required + " DESC 'Descripton')";
        asd = parser.parse( value );
        assertEquals("Descripton", asd.getDescription());

        // simple with tabs, newline, comment, etc.
        value = "(" + oid + "\n" + required + "\tDESC#comment\n\n\r\n\r\t'Descripton')";
        asd = parser.parse( value );
        assertEquals("Descripton", asd.getDescription());

        // simple w/o space
        value = "(" + oid + " " + required + " DESC'Descripton')";
        asd = parser.parse( value );
        assertEquals("Descripton", asd.getDescription());

        // simple parentheses and quotes
        value = "(" + oid + " " + required + " DESC ('Descripton') )";
        asd = parser.parse( value );
        assertEquals("Descripton", asd.getDescription());

        // unicode
        value = "( " + oid + " " + required + " DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' )";
        asd = parser.parse( value );
        assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", asd.getDescription());

        // escaped characters
        value = "( " + oid + " " + required + " DESC 'test\\5Ctest' )";
        asd = parser.parse( value );
        assertEquals("test\\test", asd.getDescription());
        value = "( " + oid + " " + required + " DESC 'test\\5ctest' )";
        asd = parser.parse( value );
        assertEquals("test\\test", asd.getDescription());
        value = "( " + oid + " " + required + " DESC 'test\\27test' )";
        asd = parser.parse( value );
        assertEquals("test'test", asd.getDescription());
        value = "( " + oid + " " + required + " DESC '\\5C\\27\\5c' )";
        asd = parser.parse( value );
        assertEquals("\\'\\", asd.getDescription());

        // lowercase DESC
        value = "( " + oid + " " + required + " desc 'Descripton' )";
        asd = parser.parse( value );
        assertEquals("Descripton", asd.getDescription());

        // empty DESC
        value = "( " + oid + " " + required + " DESC '' )";
        asd = parser.parse( value );
        assertEquals("", asd.getDescription());

        // multiple not allowed
        value = "(" + oid + " " + required + " DESC ( 'Descripton1' 'Description 2' )  )";
        try
        {
View Full Code Here

     * @throws ParseException
     */
    public static void testExtensions( AbstractSchemaParser parser, String oid, String required ) throws ParseException
    {
        String value = null;
        SchemaObject asd = null;

        // no extension
        value = "( " + oid + " " + required + " )";
        asd = parser.parse( value );
        assertEquals(0, asd.getExtensions().size());

        // single extension with one value
        value = "( " + oid + " " + required + " X-TEST 'test' )";
        asd = parser.parse( value );
        assertEquals(1, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-TEST"));
        assertEquals(1, asd.getExtensions().get("X-TEST").size());
        assertEquals("test", asd.getExtensions().get("X-TEST").get(0));

        // single extension with multiple values
        value = "( " + oid + " " + required
            + " X-TEST-ABC ('test1' 'test \u00E4\u00F6\u00FC\u00DF'       'test \u90E8\u9577' ) )";
        asd = parser.parse( value );
        assertEquals(1, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-TEST-ABC"));
        assertEquals(3, asd.getExtensions().get("X-TEST-ABC").size());
        assertEquals("test1", asd.getExtensions().get("X-TEST-ABC").get(0));
        assertEquals("test \u00E4\u00F6\u00FC\u00DF", asd.getExtensions().get("X-TEST-ABC").get(1));
        assertEquals("test \u90E8\u9577", asd.getExtensions().get("X-TEST-ABC").get(2));

        // multiple extensions
        value = "(" + oid + " " + required + " X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2'))";
        asd = parser.parse( value );
        assertEquals(2, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-TEST-a"));
        assertEquals(2, asd.getExtensions().get("X-TEST-a").size());
        assertEquals("test1-1", asd.getExtensions().get("X-TEST-a").get(0));
        assertEquals("test1-2", asd.getExtensions().get("X-TEST-a").get(1));
        assertNotNull(asd.getExtensions().get("X-TEST-b"));
        assertEquals(2, asd.getExtensions().get("X-TEST-b").size());
        assertEquals("test2-1", asd.getExtensions().get("X-TEST-b").get(0));
        assertEquals("test2-2", asd.getExtensions().get("X-TEST-b").get(1));

        // multiple extensions, no spaces
        value = "(" + oid + " " + required + " X-TEST-a('test1-1''test1-2')X-TEST-b('test2-1''test2-2'))";
        asd = parser.parse( value );
        assertEquals(2, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-TEST-a"));
        assertEquals(2, asd.getExtensions().get("X-TEST-a").size());
        assertEquals("test1-1", asd.getExtensions().get("X-TEST-a").get(0));
        assertEquals("test1-2", asd.getExtensions().get("X-TEST-a").get(1));
        assertNotNull(asd.getExtensions().get("X-TEST-b"));
        assertEquals(2, asd.getExtensions().get("X-TEST-b").size());
        assertEquals("test2-1", asd.getExtensions().get("X-TEST-b").get(0));
        assertEquals("test2-2", asd.getExtensions().get("X-TEST-b").get(1));

        // multiple extensions, tabs, newline, comments
        value = "(" + oid + "\n#comment\n" + required
            + "\nX-TEST-a\n(\t'test1-1'\t\n'test1-2'\n\r)\tX-TEST-b\n(\n'test2-1'\t'test2-2'\t)\r)";
        asd = parser.parse( value );
        assertEquals(2, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-TEST-a"));
        assertEquals(2, asd.getExtensions().get("X-TEST-a").size());
        assertEquals("test1-1", asd.getExtensions().get("X-TEST-a").get(0));
        assertEquals("test1-2", asd.getExtensions().get("X-TEST-a").get(1));
        assertNotNull(asd.getExtensions().get("X-TEST-b"));
        assertEquals(2, asd.getExtensions().get("X-TEST-b").size());
        assertEquals("test2-1", asd.getExtensions().get("X-TEST-b").get(0));
        assertEquals("test2-2", asd.getExtensions().get("X-TEST-b").get(1));

        // some more complicated
        value = "(" + oid + " " + required
            + " X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ('\\5C\\27\\5c'))";
        asd = parser.parse( value );
        assertEquals(1, asd.getExtensions().size());
        assertNotNull(asd.getExtensions().get("X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
        assertEquals(1, asd.getExtensions().get("X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
                .size());
        assertEquals("\\'\\", asd.getExtensions().get(
                "X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").get(0));

        // invalid extension, no number allowed
        value = "( " + oid + " " + required + " X-TEST1 'test' )";
        try
View Full Code Here

     * @throws ParseException
     */
    public static void testObsolete( AbstractSchemaParser parser, String oid, String required ) throws ParseException
    {
        String value = null;
        SchemaObject asd = null;

        // not obsolete
        value = "( " + oid + " " + required + " )";
        asd = parser.parse( value );
        assertFalse(asd.isObsolete());

        // not obsolete
        value = "( " + oid + " " + required + " NAME 'test' DESC 'Descripton' )";
        asd = parser.parse( value );
        assertFalse(asd.isObsolete());

        // obsolete
        value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLETE)";
        asd = parser.parse( value );
        assertTrue(asd.isObsolete());

        // obsolete
        value = "(" + oid + " " + required + " OBSOLETE)";
        asd = parser.parse( value );
        assertTrue(asd.isObsolete());

        // lowercased obsolete
        value = "(" + oid + " " + required + " obsolete)";
        asd = parser.parse( value );
        assertTrue(asd.isObsolete());

        // invalid
        value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLET )";
        try
        {
View Full Code Here

    public static void testQuirksMode( AbstractSchemaParser parser, String required ) throws ParseException
    {
        try
        {
            String value = null;
            SchemaObject asd = null;
           
            parser.setQuirksMode( true );
           
            // alphanum OID
            value = "( abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 " + required + " )";
            asd = parser.parse( value );
            assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789", asd
                    .getOid());

            // start with hypen
            value = "( -oid " + required + " )";
            asd = parser.parse( value );
            assertEquals("-oid", asd.getOid());

            // start with number
            value = "( 1oid " + required + " )";
            asd = parser.parse( value );
            assertEquals("1oid", asd.getOid());

            // start with dot
            value = "( .oid " + required + " )";
            asd = parser.parse( value );
            assertEquals(".oid", asd.getOid());
        }
        finally
        {
            parser.setQuirksMode( false );
        }
View Full Code Here

    }


    private SchemaObject copy( SchemaObject schemaObject )
    {
        SchemaObject copy = null;

        if ( !( schemaObject instanceof LoadableSchemaObject ) )
        {
            copy = schemaObject.copy();
        }
View Full Code Here

    {
        // First, clear the errors
        errors.clear();

        // Clone the schemaObject
        SchemaObject copy = copy( schemaObject );

        if ( copy == null )
        {
            return false;
        }

        if ( registries.isRelaxed() )
        {
            // Apply the addition right away
            registries.add( errors, copy, true );

            return errors.isEmpty();
        }
        else
        {
            // Clone, apply, check, then apply again if ok
            // The new schemaObject's OID must not already exist
            if ( checkOidExist( copy ) )
            {
                LdapSchemaException ldapSchemaException = new LdapSchemaException(
                    LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err( I18n.ERR_11008, schemaObject.getOid() ) );
                ldapSchemaException.setSourceObject( schemaObject );
                errors.add( ldapSchemaException );

                return false;
            }

            // Build the new AttributeType from the given entry
            String schemaName = getSchemaName( copy );

            if ( schemaName == null )
            {
                // The schema associated with the SchemaaObject does not exist. This is not valid.

                LdapSchemaException ldapSchemaException = new LdapSchemaException(
                    LdapSchemaExceptionCodes.NONEXISTENT_SCHEMA, I18n.err( I18n.ERR_11009, schemaObject.getOid(),
                        copy.getSchemaName() ) );
                ldapSchemaException.setSourceObject( schemaObject );
                ldapSchemaException.setRelatedId( copy.getSchemaName() );
                errors.add( ldapSchemaException );

                return false;
            }

            // At this point, the constructed AttributeType has not been checked against the
            // existing Registries. It may be broken (missing SUP, or such), it will be checked
            // there, if the schema and the AttributeType are both enabled.
            Schema schema = getLoadedSchema( schemaName );

            if ( schema == null )
            {
                // The SchemaObject must be associated with an existing schema
                String msg = I18n.err( I18n.ERR_11010, copy.getOid() );
                LOG.info( msg );
                Throwable error = new LdapProtocolErrorException( msg );
                errors.add( error );
                return false;
            }

            if ( schema.isEnabled() && copy.isEnabled() )
            {
                // As we may break the registries, work on a cloned registries
                Registries clonedRegistries = null;

                try
                {
                    clonedRegistries = registries.clone();
                }
                catch ( CloneNotSupportedException cnse )
                {
                    throw new LdapOtherException( cnse.getMessage() );
                }

                // Inject the new SchemaObject in the cloned registries
                clonedRegistries.add( errors, copy, true );

                // Remove the cloned registries
                clonedRegistries.clear();

                // If we didn't get any error, apply the addition to the real retistries
                if ( errors.isEmpty() )
                {
                    // Copy again as the clonedRegistries clear has removed the previous copy
                    copy = copy( schemaObject );

                    // Apply the addition to the real registries
                    registries.add( errors, copy, true );

                    LOG.debug( "Added {} into the enabled schema {}", copy.getName(), schemaName );

                    return true;
                }
                else
                {
                    // We have some error : reject the addition and get out
                    String msg = "Cannot add the SchemaObject " + copy.getOid() + " into the registries, "
                        + "the resulting registries would be inconsistent :" + Strings.listToString( errors );
                    LOG.info( msg );

                    return false;
                }
            }
            else
            {
                // At least, we register the OID in the globalOidRegistry, and associates it with the
                // schema
                registries.associateWithSchema( errors, copy );

                LOG.debug( "Added {} into the disabled schema {}", copy.getName(), schemaName );
                return errors.isEmpty();
            }
        }
    }
View Full Code Here

                errors.add( error );
                return false;
            }

            // Get the SchemaObject to delete if it's not a LoadableSchemaObject
            SchemaObject toDelete = getSchemaObject( schemaObject );

            // First check that this SchemaObject does not have any referencing SchemaObjects
            Set<SchemaObjectWrapper> referencing = registries.getReferencing( toDelete );

            if ( ( referencing != null ) && !referencing.isEmpty() )
            {
                String msg = I18n.err( I18n.ERR_11012, schemaObject.getOid(), Strings.setToString( referencing ) );

                Throwable error = new LdapProtocolErrorException( msg );
                errors.add( error );
                return false;
            }

            String schemaName = getSchemaName( toDelete );

            // At this point, the deleted AttributeType may be referenced, it will be checked
            // there, if the schema and the AttributeType are both enabled.
            Schema schema = getLoadedSchema( schemaName );

            if ( schema == null )
            {
                // The SchemaObject must be associated with an existing schema
                String msg = I18n.err( I18n.ERR_11013, schemaObject.getOid() );
                LOG.info( msg );
                Throwable error = new LdapProtocolErrorException( msg );
                errors.add( error );
                return false;
            }

            if ( schema.isEnabled() && schemaObject.isEnabled() )
            {
                // As we may break the registries, work on a cloned registries
                Registries clonedRegistries = null;

                try
                {
                    clonedRegistries = registries.clone();
                }
                catch ( CloneNotSupportedException cnse )
                {
                    throw new LdapOtherException( cnse.getMessage() );
                }

                // Delete the SchemaObject from the cloned registries
                clonedRegistries.delete( errors, toDelete );

                // Remove the cloned registries
                clonedRegistries.clear();

                // If we didn't get any error, apply the deletion to the real retistries
                if ( errors.isEmpty() )
                {
                    // Apply the deletion to the real registries
                    registries.delete( errors, toDelete );

                    LOG.debug( "Removed {} from the enabled schema {}", toDelete.getName(), schemaName );

                    return true;
                }
                else
                {
View Full Code Here

        {
            Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();

            for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
            {
                SchemaObject schemaObject = schemaObjectWrapper.get();

                if ( schemaObject instanceof AttributeType )
                {
                    AttributeType attributeType = ( AttributeType ) schemaObject;
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.schema.SchemaObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.