You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2008/10/06 23:14:55 UTC

svn commit: r702266 - in /db/derby/code/trunk/java: engine/org/apache/derby/diag/ engine/org/apache/derby/impl/sql/catalog/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apac...

Author: dag
Date: Mon Oct  6 14:14:54 2008
New Revision: 702266

URL: http://svn.apache.org/viewvc?rev=702266&view=rev
Log:
DERBY-3886 SQL roles: ij show enabled and settable roles

Adds a VTI table function SYSCS_DIAG.ENABLED_ROLES and two new ij
commands; "show settable_roles" and "show enabled_roles", plus new
tests.  Also tweaks ScriptTestCase to be able to run scripts that need
SQL authorization.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_dbo.sql   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_usr.sql   (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
    db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties

Added: db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java?rev=702266&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java Mon Oct  6 14:14:54 2008
@@ -0,0 +1,139 @@
+/*
+
+   Derby - Class org.apache.derby.diag.EnabledRoles
+
+   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.derby.diag;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.RoleClosureIterator;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.Limits;
+import org.apache.derby.iapi.error.PublicAPI;
+
+import org.apache.derby.vti.VTITemplate;
+import org.apache.derby.vti.VTICosting;
+import org.apache.derby.vti.VTIEnvironment;
+
+import org.apache.derby.impl.jdbc.EmbedResultSetMetaData;
+import org.apache.derby.iapi.sql.ResultColumnDescriptor;
+
+
+/**
+ * EnabledRoles shows all enabled roles for the current session.
+ *
+ * <p>To use it, query it as follows:
+ * </p>
+ * <pre> SELECT * FROM SYSCS_DIAG.ENABLED_ROLES; </pre>
+ [
+ * <p>The following columns will be returned:
+ *    <ul><li>ROLEID -- VARCHAR(128) NOT NULL
+ *        </li>
+ *    </ul>
+ *
+ */
+public final class EnabledRoles extends VTITemplate {
+
+    RoleClosureIterator rci;
+    String nextRole;
+    boolean initialized;
+
+    public EnabledRoles() {
+    }
+
+    /**
+     * @see java.sql.ResultSet#next
+     */
+    public boolean next() throws SQLException {
+        try {
+			// Need to defer initialization here to make sure we have an
+			// activation.
+            if (!initialized) {
+                initialized = true;
+                LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
+                String role = lcc.getCurrentRoleId(lcc.getLastActivation());
+
+                if (role != null) {
+                    DataDictionary dd = lcc.getDataDictionary();
+                    lcc.beginNestedTransaction(true);
+                    try {
+                        int mode = dd.startReading(lcc);
+                        try {
+                            rci = dd.createRoleClosureIterator
+                                (lcc.getLastActivation().
+                                     getTransactionController(),
+                                 role, true);
+                        } finally {
+                            dd.doneReading(mode, lcc);
+                        }
+                    } finally {
+                        // make sure we commit; otherwise, we will end up with
+                        // mismatch nested level in the language connection
+                        // context.
+                        lcc.commitNestedTransaction();
+                    }
+                }
+            }
+
+            return rci != null && ((nextRole = rci.next()) != null);
+
+        } catch (StandardException e) {
+            throw PublicAPI.wrapStandardException(e);
+        }
+    }
+
+
+    /**
+     * @see java.sql.ResultSet#close
+     */
+    public void close() {
+    }
+
+
+    /**
+     * @see java.sql.ResultSet#getMetaData
+     */
+    public ResultSetMetaData getMetaData() {
+        return metadata;
+    }
+
+    /**
+     * @see java.sql.ResultSet#getString
+     */
+    public String getString(int columnIndex) throws SQLException {
+        return nextRole;
+    }
+
+    /*
+     * Metadata
+     */
+    private static final ResultColumnDescriptor[] columnInfo = {
+        EmbedResultSetMetaData.getResultColumnDescriptor
+        ("ROLEID", Types.VARCHAR, false, Limits.MAX_IDENTIFIER_LENGTH)
+    };
+
+    private static final ResultSetMetaData metadata =
+		new EmbedResultSetMetaData(columnInfo);
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/diag/EnabledRoles.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Mon Oct  6 14:14:54 2008
@@ -12060,7 +12060,7 @@
 			{"STATEMENT_CACHE", "org.apache.derby.diag.StatementCache"},
 			{"TRANSACTION_TABLE", "org.apache.derby.diag.TransactionTable"},
 			{"ERROR_MESSAGES", "org.apache.derby.diag.ErrorMessages"},
-			
+			{"ENABLED_ROLES", "org.apache.derby.diag.EnabledRoles"},
 			
 	};
 	

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out Mon Oct  6 14:14:54 2008
@@ -82,6 +82,13 @@
                                -- lists tables, views, procedures or synonyms
   SHOW INDEXES { IN schema | FROM table };
                                -- lists indexes in a schema, or for a table
+  SHOW ROLES;                  -- lists all defined roles in the database,
+                               -- sorted
+  SHOW ENABLED_ROLES;          -- lists the enabled roles for the current
+                               -- connection (to see current role use
+                               -- VALUES CURRENT_ROLE), sorted
+  SHOW SETTABLE_ROLES;         -- lists the roles which can be set for the
+                               -- current connection, sorted
   DESCRIBE name;               -- lists columns in the named table
   COMMIT;                      -- commits the current transaction
   ROLLBACK;                    -- rolls back the current transaction

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out?rev=702266&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out Mon Oct  6 14:14:54 2008
@@ -0,0 +1,28 @@
+ij> -- Run via ToolScripts.java
+show roles;
+ROLEID                        
+------------------------------
+"eve"                         
+A                             
+B                             
+PUBLICROLE                    
+ij> set role b;
+0 rows inserted/updated/deleted
+ij> show enabled_roles;
+ROLEID                        
+------------------------------
+A                             
+B                             
+ij> set role none;
+0 rows inserted/updated/deleted
+ij> show enabled_roles;
+ROLEID                        
+------------------------------
+ij> show settable_roles;
+ROLEID                        
+------------------------------
+"eve"                         
+A                             
+B                             
+PUBLICROLE                    
+ij> 

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_dbo.out
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out?rev=702266&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out Mon Oct  6 14:14:54 2008
@@ -0,0 +1,26 @@
+ij> -- Run via ToolScripts.java
+show roles;
+ROLEID                        
+------------------------------
+"eve"                         
+A                             
+B                             
+PUBLICROLE                    
+ij> set role b;
+0 rows inserted/updated/deleted
+ij> show enabled_roles;
+ROLEID                        
+------------------------------
+A                             
+B                             
+ij> set role none;
+0 rows inserted/updated/deleted
+ij> show enabled_roles;
+ROLEID                        
+------------------------------
+ij> show settable_roles;
+ROLEID                        
+------------------------------
+B                             
+PUBLICROLE                    
+ij> 
\ No newline at end of file

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles_usr.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java Mon Oct  6 14:14:54 2008
@@ -678,6 +678,23 @@
         st.close();
     }
 
+    /**
+     * Basic sanity test for SYSCS_DIAG.ENABLED_ROLES. See also the
+     * tools/ij_show_roles.sql test for a test that actually defines roles.
+     */
+    public void testEnabledRoles() throws SQLException
+    {
+        Statement   st = createStatement();
+
+        ResultSet rs = st.executeQuery
+            ("select * from syscs_diag.enabled_roles");
+
+        JDBC.assertEmpty(rs);
+
+        rs.close();
+        st.close();
+    }
+
     /* All statements in this method should fail because a VTI table-
      * mapping that takes arguments can only be used as part of the TABLE 
      * constructor.  Any other uses of, or attempts to modify, such a

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java Mon Oct  6 14:14:54 2008
@@ -19,6 +19,9 @@
  */
 package org.apache.derbyTesting.functionTests.tests.tools;
 
+import java.sql.Statement;
+import java.sql.SQLException;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -78,8 +81,9 @@
     /**
      * Tests that run with authentication and SQL authorization on.
      */
-    private static final String[][] SQLAUTHORIZATION_TESTS = {
-        {"ij_show_roles", "test_dbo"}
+    private static final String[][][] SQLAUTHORIZATION_TESTS = {
+        {{"ij_show_roles_dbo"}, {"test_dbo", "donald"}, {"test_dbo"}},
+        {{"ij_show_roles_usr"}, {"test_dbo", "donald"}, {"donald"}}
     };
 
     /**
@@ -128,6 +132,10 @@
         super(toolTest);
     }
 
+    private ToolScripts(String toolTest, String user){
+        super(toolTest, null /* default encoding */, user);
+    }
+
     /**
      * Return a suite of tool tests from the list of
      * script names. Each test is surrounded in a decorator
@@ -146,22 +154,44 @@
     /**
      * Return a suite of tool tests from the list of script names. Each test is
      * surrounded in a decorator that cleans the database, and adds
-     * authentication and authorization given the user for each script.
+     * authentication and authorization for each script.
+     * @param list <ul><li>list[i][0][0]: script name,
+     *                 <li>list[i][1]: users,
+     *                 <li>list[i][2][0]: run-as-user
+     *             </ul>
      */
-    private static Test getAuthorizationSuite(String[][] list) {
+    private static Test getAuthorizationSuite(String[][][] list) {
         TestSuite suite = new TestSuite("Tool scripts w/authorization");
         final String PWSUFFIX = "pwSuffix";
 
         for (int i = 0; i < list.length; i++) {
-            Test clean = new CleanDatabaseTestSetup(
-                new ToolScripts(list[i][0]));
+            Test clean;
+
+            if (list[i][0][0].startsWith("ij_show_roles")) {
+                clean = new CleanDatabaseTestSetup(
+                    new ToolScripts(list[i][0][0], list[i][2][0])) {
+                        protected void decorateSQL(Statement s)
+                                throws SQLException {
+                            s.execute("create role a");
+                            s.execute("create role b");
+                            s.execute("create role \"\"\"eve\"\"\"");
+                            s.execute("create role publicrole");
+                            s.execute("grant a to b");
+                            s.execute("grant publicrole to public");
+                            s.execute("grant b to donald");
+                        }
+                    };
+            } else {
+                clean = new CleanDatabaseTestSetup(
+                    new ToolScripts(list[i][0][0], list[i][2][0]));
+            }
+
             suite.addTest(
                 TestConfiguration.sqlAuthorizationDecorator(
                     DatabasePropertyTestSetup.builtinAuthentication(
-                        clean, new String[]{list[i][1]}, PWSUFFIX)));
+                        clean, list[i][1], PWSUFFIX)));
         }
 
         return getIJConfig(suite);
     }
-
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_dbo.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_dbo.sql?rev=702266&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_dbo.sql (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_dbo.sql Mon Oct  6 14:14:54 2008
@@ -0,0 +1,7 @@
+-- Run via ToolScripts.java
+show roles;
+set role b;
+show enabled_roles;
+set role none;
+show enabled_roles;
+show settable_roles;

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_usr.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_usr.sql?rev=702266&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_usr.sql (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles_usr.sql Mon Oct  6 14:14:54 2008
@@ -0,0 +1,7 @@
+-- Run via ToolScripts.java
+show roles;
+set role b;
+show enabled_roles;
+set role none;
+show enabled_roles;
+show settable_roles;

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java Mon Oct  6 14:14:54 2008
@@ -36,6 +36,7 @@
 public abstract class ScriptTestCase extends CanonTestCase {
 	
 	private final String inputEncoding;
+	private final String user;
 
 	/**
 	 * Create a ScriptTestCase to run a single test
@@ -47,6 +48,7 @@
 	{
 		super(script);
 		inputEncoding = "US-ASCII";
+		user = null;
 	}
 	
     /**
@@ -60,6 +62,29 @@
     {
         super(script);
         inputEncoding = encoding;
+		user = null;
+    }
+
+    /**
+     * Create a ScriptTestCase to run a single test
+     * using a connection obtained from getConnection() with a
+     * different encoding.
+     * @param script     Base name of the .sql script
+     *                   excluding the .sql suffix.
+     * @param encoding   Run using encoding if not null, else use "US-ASCII".
+     * @param user       Run script as user
+     */
+    public ScriptTestCase(String script, String encoding, String user)
+    {
+        super(script);
+
+		if (encoding != null) {
+			inputEncoding = encoding;
+		} else {
+			inputEncoding = "US-ASCII";
+		}
+
+		this.user = user;
     }
 
     /**
@@ -120,8 +145,15 @@
 		assertNotNull("SQL script missing: " + resource, sql);
 		
 		InputStream sqlIn = openTestResource(sql);
-					
-		Connection conn = getConnection();
+
+		Connection conn;
+
+		if (user != null) {
+			conn = openUserConnection(user);
+		} else {
+			conn = getConnection();
+		}
+
 		org.apache.derby.tools.ij.runScript(
 				conn,
 				sqlIn,

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Mon Oct  6 14:14:54 2008
@@ -862,6 +862,88 @@
 		}
 	}
 
+	/**
+	 * Return a resultset of enabled roles, sorted on ROLEID. No information
+	 * schema is available, we select from VTI SYSCS_DIAG.ENABLED_ROLES instead.
+	 */
+	public ijResult showEnabledRoles() throws SQLException {
+		ResultSet rs = null;
+		try {
+			haveConnection();
+
+			if (currentConnEnv.getSession().getIsDNC() ||
+				currentConnEnv.getSession().getIsEmbeddedDerby()) {
+				rs = theConnection.createStatement().executeQuery
+					("SELECT * FROM SYSCS_DIAG.ENABLED_ROLES ORDER BY ROLEID");
+
+				int[] displayColumns = new int[] {
+					rs.findColumn("ROLEID")
+				};
+				int[] columnWidths = new int[] {
+					30
+				};
+
+				return new ijResultSetResult(rs, displayColumns, columnWidths);
+			} else {
+				throw ijException.notAvailableForDriver(
+					theConnection.getMetaData().getDriverName());
+			}
+		} catch (SQLException e) {
+			if(rs!=null)
+				rs.close();
+			throw e;
+		}
+	}
+
+
+	/**
+	 * Return a resultset of settable roles, sorted on ROLEID.  This has the
+	 * side effect of starting a transaction if one is not already active, so
+	 * we should perhaps give warning when not in autocommit mode.
+	 */
+	public ijResult showSettableRoles() throws SQLException {
+		ResultSet rs = null;
+		final String query  =
+			// Ordinary user is restricted to roles explicitly granted:
+			"select distinct * from (" +
+			"  select roleid from sys.sysroles s" +
+			"    where s.grantee = current_user or s.grantee = 'PUBLIC'" +
+			"  union" +
+			// Data base owner can set all roles:
+			"  select roleid from sys.sysroles s" +
+			"    where s.isdef='Y' and current_user in" +
+			"        (select authorizationid from sys.sysschemas" +
+			"             where schemaname = 'SYS')) t " +
+			"order by roleid";
+
+		try {
+			haveConnection();
+
+			if (currentConnEnv.getSession().getIsDNC() ||
+				currentConnEnv.getSession().getIsEmbeddedDerby()) {
+				rs = theConnection.createStatement().executeQuery(query);
+
+				int[] displayColumns = new int[] {
+					rs.findColumn("ROLEID")
+				};
+				int[] columnWidths = new int[] {
+					30
+				};
+
+				return new ijResultSetResult(rs, displayColumns, columnWidths);
+			} else {
+				throw ijException.notAvailableForDriver(
+					theConnection.getMetaData().getDriverName());
+			}
+		} catch (SQLException e) {
+			if(rs!=null)
+				rs.close();
+			throw e;
+		}
+	}
+
+
+
 
 	/**
 	   Outputs the names of all fields of given table. Outputs field
@@ -1012,6 +1094,7 @@
 |	<DISCONNECT: "disconnect">
 |	<DRIVER: "driver">
 |	<ELAPSEDTIME: "elapsedtime">
+|	<ENABLED_ROLES: "enabled_roles">
 |	<END: "end">
 |	<EQUALS_OPERATOR: "=">
 |	<EXECUTE: "execute">
@@ -1051,7 +1134,7 @@
 |	<RELATIVE: "relative">
 |	<REMOVE: "remove">
 |	<RESOURCE: "resource">
-|       <ROLES: "roles">
+|	<ROLES: "roles">
 |	<ROLLBACK: "rollback">
 |	<RUN: "run">
 |	<TO: "to">
@@ -1060,6 +1143,7 @@
 |	<SCROLL: "scroll">
 |	<SENSITIVE: "sensitive">
 |	<SET: "set">
+|	<SETTABLE_ROLES: "settable_roles">
 |	<SHOW: "show">
 |	<SHUTDOWN: "shutdown">
 |	<STATEMENT: "statement">
@@ -1854,6 +1938,14 @@
         {
             return showRoles();
         }
+|       <SHOW> <ENABLED_ROLES>
+        {
+            return showEnabledRoles();
+        }
+|       <SHOW> <SETTABLE_ROLES>
+        {
+            return showSettableRoles();
+        }
 }
 
 /**

Modified: db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties?rev=702266&r1=702265&r2=702266&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties Mon Oct  6 14:14:54 2008
@@ -70,6 +70,13 @@
 \                               -- lists tables, views, procedures or synonyms\n\
 \  SHOW INDEXES { IN schema | FROM table };\n\
 \                               -- lists indexes in a schema, or for a table\n\
+\  SHOW ROLES;                  -- lists all defined roles in the database,\n\
+\                               -- sorted\n\
+\  SHOW ENABLED_ROLES;          -- lists the enabled roles for the current\n\
+\                               -- connection (to see current role use\n\
+\                               -- VALUES CURRENT_ROLE), sorted\n\
+\  SHOW SETTABLE_ROLES;         -- lists the roles which can be set for the\n\
+\                               -- current connection, sorted\n\
 \  DESCRIBE name;               -- lists columns in the named table\n\
 \ \n\
 \  COMMIT;                      -- commits the current transaction\n\