db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1339575 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/authentication/ engine/org/apache/derby/jdbc/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionT...
Date Thu, 17 May 2012 12:41:16 GMT
Author: rhillegas
Date: Thu May 17 12:41:16 2012
New Revision: 1339575

URL: http://svn.apache.org/viewvc?rev=1339575&view=rev
Log:
DERBY_5652: Improve error handling when credentials db name ends in trailing garbage.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java?rev=1339575&r1=1339574&r2=1339575&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/authentication/NativeAuthenticationServiceImpl.java
Thu May 17 12:41:16 2012
@@ -197,11 +197,20 @@ public final class NativeAuthenticationS
      * </p>
      */
     private boolean validAuthenticationProvider()
+        throws StandardException
     {
         // If there is no store, then we are booting a system-wide authentication service
         boolean     systemWideAuthentication = ( getServiceName() == null );
 
-        if ( _credentialsDB != null ) { return true; }
+        if ( _credentialsDB != null )
+        {
+            // make sure that it is a well-formed database name
+            if ( Monitor.getMonitor().getCanonicalServiceName( _credentialsDB ) == null )
+            {
+                throw StandardException.newException( SQLState.BAD_CREDENTIALS_DB_NAME, _credentialsDB
);
+            }
+            else { return true; }
+        }
         
         // must have a global credentials db for system-wide authentication
         if ( systemWideAuthentication ) { return false; }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java?rev=1339575&r1=1339574&r2=1339575&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java Thu May 17 12:41:16
2012
@@ -506,13 +506,6 @@ public abstract class InternalDriver imp
 								   );
 		}
 
-		// We should have a Authentication Service (always)
-		//
-		if (SanityManager.DEBUG)
-		{
-			SanityManager.ASSERT(this.authenticationService != null, 
-				"Unexpected - There is no valid authentication service!");
-		}
 		return this.authenticationService;
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1339575&r1=1339574&r2=1339575&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Thu May 17 12:41:16
2012
@@ -1279,6 +1279,12 @@ Guide.
            </msg>
 
             <msg>
+                <name>4251L</name>
+                <text>The derby.authentication.provider property specifies '{0}' as
the name of the credentials database. This is not a valid name for a database.</text>
+                 <arg>dbName</arg>
+           </msg>
+
+            <msg>
                 <name>42601</name>
                 <text>In an ALTER TABLE statement, the column '{0}' has been specified
as NOT NULL and either the DEFAULT clause was not specified or was specified as DEFAULT NULL.</text>
                 <arg>columnName</arg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1339575&r1=1339574&r2=1339575&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Thu May 17 12:41:16 2012
@@ -787,6 +787,7 @@ public interface SQLState {
 	String MISSING_CREDENTIALS_DB                                               = "4251I";
 	String BAD_PASSWORD_LIFETIME                                               = "4251J";
 	String DBO_FIRST                                                                    = "4251K";
+	String BAD_CREDENTIALS_DB_NAME                                          = "4251L";
 
 	String LANG_DB2_NOT_NULL_COLUMN_INVALID_DEFAULT                    = "42601";
 	String LANG_DB2_INVALID_HEXADECIMAL_CONSTANT                    = "42606";

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java?rev=1339575&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java
Thu May 17 12:41:16 2012
@@ -0,0 +1,123 @@
+/*
+ * Class org.apache.derbyTesting.functionTests.tests.lang.Derby5652
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public class Derby5652 extends BaseJDBCTestCase
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String  PROVIDER_PROPERTY = "derby.authentication.provider";
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public Derby5652( String name ) { super(name); }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * Construct top level suite in this JUnit test
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite( "Derby5652" );
+
+        Test    test = new Derby5652( "basicTest" );
+
+        // turn off security manager so that we can change system properties
+        test = SecurityManagerSetup.noSecurityManager( test );
+
+        suite.addTest( test );
+
+        return suite;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TESTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Trailing garbage after the credentials db name should produce a useful
+     * error message instead of an assertion failure.
+     * </p>
+     */
+    public  void    basicTest()  throws  Exception
+    {
+        // run the test in another process because it creates a zombie engine
+        // which can't be killed. see derby-5757.
+        assertLaunchedJUnitTestMethod( getClass().getName() + ".badProperty", null );
+    }
+    
+    /**
+     * <p>
+     * Trailing garbage after the credentials db name should produce a useful
+     * error message.
+     * </p>
+     */
+    public  void    badProperty()  throws  Exception
+    {
+        // bring down the engine in order to have a clean environment
+        getTestConfiguration().shutdownEngine();
+
+        // configure an illegal credentials db name--this one has an illegal trailing colon
+        setSystemProperty( PROVIDER_PROPERTY, "NATIVE:db:" );
+
+        // verify that you can't connect with this provider setting
+        try {
+            openUserConnection( "fooUser" );
+        }
+        catch (SQLException se)
+        {
+            // look for a login failure message. the detailed error is printed to
+            // derby.log and not percolated out of the Monitor.
+            assertSQLState( "08004", se );
+        }
+    }
+    
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Derby5652.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=1339575&r1=1339574&r2=1339575&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Thu May 17 12:41:16 2012
@@ -221,6 +221,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(AutoIncrementTest.suite());
         suite.addTest(HalfCreatedDatabaseTest.suite());
         suite.addTest(NativeAuthenticationServiceTest.suite());
+        suite.addTest(Derby5652.suite());
         return suite;
 	}
 }



Mime
View raw message