db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r630124 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 22 Feb 2008 09:19:21 GMT
Author: dag
Date: Fri Feb 22 01:19:18 2008
New Revision: 630124

URL: http://svn.apache.org/viewvc?rev=630124&view=rev
Log:
DERBY-3073 SQL roles: add parser support

Patch DERBY-3073-part4, which:

- lifts restriction on role names to 30 chars; it is now 128 as
  for other identifiers, cf. discussion with Dan in DERBY-2207.
- reserves the SYS prefix on role names

RolesTest is updated with modified/new tests for this. 

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    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/RolesTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=630124&r1=630123&r2=630124&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Fri Feb
22 01:19:18 2008
@@ -1650,12 +1650,6 @@
                                                 getContextManager());
     }
     
-	private void checkAuthorizationLength( String authorization)
-		throws StandardException
-	{
-		checkIdentifierLengthLimit( authorization, Limits.DB2_MAX_USERID_LENGTH);
-	}
-
     /**
         Check to see if the required claues have been added
         to a procedure or function defintion.
@@ -9688,7 +9682,12 @@
 	{
 		checkVersion( DataDictionary.DD_VERSION_DERBY_10_4, "ROLES");
 		checkSqlStandardAccess("CREATE ROLE");
-		checkAuthorizationLength(roleName);
+
+		// Reserve namespace for system roles
+		if (roleName.startsWith("SYS")) {
+			throw StandardException.newException
+                            (SQLState.INVALID_ROLE_SYS, roleName);
+                }
 
 		return (StatementNode) nodeFactory.getNode(
 			C_NodeTypes.CREATE_ROLE_NODE,
@@ -12941,7 +12940,6 @@
 {
     str = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
     {
-        checkAuthorizationLength(str);
         list.add(str);
     }
 |

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=630124&r1=630123&r2=630124&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 Fri Feb 22 01:19:18
2008
@@ -1344,6 +1344,12 @@
             </msg>
 
             <msg>
+                <name>4293A</name>
+                <text>A role cannot be created with the name '{0}', the SYS prefix
is reserved.</text>
+                <arg>authorizationID</arg>
+            </msg>
+
+            <msg>
                 <name>42962</name>
                 <text>Long column type column or parameter '{0}' not permitted in declared
global temporary tables or procedure definitions. </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=630124&r1=630123&r2=630124&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
Fri Feb 22 01:19:18 2008
@@ -1388,6 +1388,12 @@
 	String	INVALID_SCHEMA_SYS											= "42939";
 
 	/*
+	** Modelled on INVALID_SCHEMA_SYS, although not from DB2
+	*/
+	String  INVALID_ROLE_SYS                                        = "4293A";
+
+
+	/*
 		SQL standard 0A - feature not supported
 	*/
 	String UNSUPPORTED_PREFIX="0A";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java?rev=630124&r1=630123&r2=630124&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
Fri Feb 22 01:19:18 2008
@@ -63,13 +63,15 @@
 
     /* SQL states */
     private final static String sqlAuthorizationRequired = "42Z60";
-    private final static String syntaxError = "42X01";
-    private final static String roleDboOnly = "4251A";
-    private final static String invalidRole = "0P000";
-    private final static String tooLongId   = "42622";
-    private final static String revokeWarn  = "01007";
-    private final static String notIdle     = "25001";
+    private final static String syntaxError              = "42X01";
+    private final static String roleDboOnly              = "4251A";
+    private final static String invalidRole              = "0P000";
+    private final static String tooLongId                = "42622";
+    private final static String revokeWarn               = "01007";
+    private final static String notIdle                  = "25001";
+    private final static String invalidRoleName          = "4293A";
 
+    private int MAX_IDENTIFIER_LENGTH = 128;
     /**
      * Users used by all suites when when authLevel == SQLAUTHORIZATION.
      * The TestConfiguration.sqlAuthorizationDecorator decorator presumes
@@ -215,12 +217,18 @@
                syntaxError, syntaxError, syntaxError);
         doStmt("create role current_role", // current_role is reserved word
                syntaxError, syntaxError, syntaxError);
-        String nameWithMoreThan30Chars = ("r123456789" +
-                                          "0123456789" +
-                                          "01234567890"); // 31 long
-        doStmt("create role " + nameWithMoreThan30Chars,
-               sqlAuthorizationRequired, tooLongId, tooLongId);
 
+        char[] longname = new char[MAX_IDENTIFIER_LENGTH + 1];
+        java.util.Arrays.fill(longname, 'a');
+        String nameWithMoreThanMaxChars = new String(longname);
+
+        doStmt("create role " + nameWithMoreThanMaxChars,
+               tooLongId, tooLongId, tooLongId);
+        // Check SYS-prefix ban
+        doStmt("create role sysrole",
+               sqlAuthorizationRequired, invalidRoleName, invalidRoleName);
+        doStmt("create role \"SYSROLE\"",
+               sqlAuthorizationRequired, invalidRoleName, invalidRoleName);
         _stm.close();
     }
 
@@ -250,15 +258,33 @@
         // "role" is not a reserved word, either:
         doStmt("create role role", n_a, null, n_a);
 
-        assertSysRolesRowCount(n_a_cnt, 2, n_a_cnt);
+        // Check that role name can be longer than present user name
+        // (max 30, cf.  Limits.DB2_MAX_USERID_LENGTH).
+        String nameWithMoreThan30Chars = ("r123456789" +
+                                          "0123456789" +
+                                          "01234567890"); // 31 long
+        doStmt("create role " + nameWithMoreThan30Chars,
+               n_a, null, n_a);
+
+        assertSysRolesRowCount(n_a_cnt, 3, n_a_cnt);
 
         doStmt("grant trigger to foo", n_a, null, n_a);
         doStmt("grant role to foo", n_a, null, n_a);
         doStmt("revoke trigger from foo", n_a, null, n_a);
         doStmt("revoke role from foo", n_a, null, n_a);
 
+        doStmt("set role " + nameWithMoreThan30Chars, n_a, null, n_a);
+
+        doStmt("create table mytab(i int)", n_a, null, n_a);
+        doStmt("grant select on mytab to " + nameWithMoreThan30Chars,
+               n_a, null, n_a);
+        doStmt("revoke select on mytab from " + nameWithMoreThan30Chars,
+               n_a, null, n_a);
+        doStmt("drop table mytab", n_a, null, n_a);
+
         doStmt("drop role trigger", n_a, null, n_a);
         doStmt("drop role role", n_a, null, n_a);
+        doStmt("drop role " + nameWithMoreThan30Chars, n_a, null, n_a);
 
         assertSysRolesRowCount(n_a_cnt, 0, n_a_cnt);
 



Mime
View raw message