Author: shawkins
Date: 2011-06-01 14:19:08 -0400 (Wed, 01 Jun 2011)
New Revision: 3211
Modified:
branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
Log:
TEIID-1611 adding a reauthentication statement and cleaning up set value syntax
Modified: branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-06-01 16:37:30
UTC (rev 3210)
+++ branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-06-01 18:19:08
UTC (rev 3211)
@@ -58,6 +58,7 @@
<LI><B>Runtime Updates of Metadata</B> - ALTER statements have been
added to change view/procedure/INSTEAD OF trigger (update procedure) definitions. A
CREATE TRIGGER statement is also available to add an INSTEAD OF trigger (update
procedures) to views.
System procedures were added to set extension metadata and stat values. By default all
effects of metadata updates happen only on running vdbs across the cluster. To make the
changes persistent see the Developers Guide Runtime Updates section.
<LI><B>ODBC SSL</B> - added support for SSL encrypted ODBC
connections.
+ <LI><B>Reauthentication Statement</B> - SET SESSION AUTHORIZATION can
now be used to perform a reauthentication via JDBC or ODBC.
</UL>
<h2><a name="Compatibility">Compatibility
Issues</a></h2>
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java 2011-06-01
16:37:30 UTC (rev 3210)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java 2011-06-01
18:19:08 UTC (rev 3211)
@@ -972,6 +972,21 @@
throw SqlUtil.createFeatureNotSupportedException();
}
+ Object setPassword(Object newPassword) {
+ if (newPassword != null) {
+ return this.connectionProps.put(TeiidURL.CONNECTION.PASSWORD, newPassword);
+ }
+ return this.connectionProps.remove(TeiidURL.CONNECTION.PASSWORD);
+ }
+
+ String getPassword() {
+ Object result = this.connectionProps.get(TeiidURL.CONNECTION.PASSWORD);
+ if (result == null) {
+ return null;
+ }
+ return result.toString();
+ }
+
@Override
public void changeUser(String userName, String newPassword)
throws SQLException {
@@ -983,11 +998,7 @@
} else {
oldName = this.connectionProps.remove(TeiidURL.CONNECTION.USER_NAME);
}
- if (newPassword != null) {
- oldPassword = this.connectionProps.put(TeiidURL.CONNECTION.PASSWORD, newPassword);
- } else {
- oldPassword = this.connectionProps.remove(TeiidURL.CONNECTION.PASSWORD);
- }
+ oldPassword = setPassword(newPassword);
boolean success = false;
try {
this.serverConn.authenticate();
@@ -1003,11 +1014,7 @@
} else {
this.connectionProps.remove(TeiidURL.CONNECTION.USER_NAME);
}
- if (oldPassword != null) {
- this.connectionProps.put(TeiidURL.CONNECTION.PASSWORD, oldPassword);
- } else {
- this.connectionProps.remove(TeiidURL.CONNECTION.PASSWORD);
- }
+ setPassword(oldPassword);
}
}
}
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-06-01
16:37:30 UTC (rev 3210)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-06-01
18:19:08 UTC (rev 3211)
@@ -66,6 +66,7 @@
import org.teiid.core.util.SqlUtil;
import org.teiid.core.util.StringUtil;
import org.teiid.jdbc.CancellationTimer.CancelTask;
+import org.teiid.net.TeiidURL;
public class StatementImpl extends WrapperImpl implements TeiidStatement {
@@ -163,7 +164,7 @@
protected Map outParamIndexMap = new HashMap();
private static Pattern TRANSACTION_STATEMENT =
Pattern.compile("\\s*(commit|rollback|(start\\s+transaction))\\s*;?",
Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
- private static Pattern SET_STATEMENT =
Pattern.compile("\\s*set\\s+(\\w+)\\s*([^;]*);?", Pattern.CASE_INSENSITIVE);
//$NON-NLS-1$
+ private static Pattern SET_STATEMENT = Pattern.compile("\\s*set\\s+((?:session
authorization)|(?:\\w+))\\s+(?:([a-zA-Z](?:\\w|_)*)|((?:'[^']*')+));?",
Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern SHOW_STATEMENT =
Pattern.compile("\\s*show\\s+(\\w*);?", Pattern.CASE_INSENSITIVE);
//$NON-NLS-1$
/**
* Factory Constructor
@@ -429,8 +430,19 @@
}
String key = match.group(1);
String value = match.group(2);
- if (ExecutionProperties.NEWINSTANCE.equalsIgnoreCase(key) &&
Boolean.valueOf(value)) {
- this.getMMConnection().getServerConnection().cleanUp();
+ if (value == null) {
+ value = match.group(3);
+ value = StringUtil.replaceAll(value, "''",
"'"); //$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(1, value.length() - 1);
+ }
+ if ("SESSION AUTHORIZATION".equalsIgnoreCase(key)) { //$NON-NLS-1$
+ this.getMMConnection().changeUser(value,
this.getMMConnection().getPassword());
+ } else if (key.equalsIgnoreCase(TeiidURL.CONNECTION.PASSWORD)) {
+ this.getMMConnection().setPassword(value);
+ } else if (ExecutionProperties.NEWINSTANCE.equalsIgnoreCase(key)) {
+ if (Boolean.valueOf(value)) {
+ this.getMMConnection().getServerConnection().cleanUp();
+ }
} else {
JDBCURL.addNormalizedProperty(key, value,
this.driverConnection.getExecutionProperties());
}
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-06-01
16:37:30 UTC (rev 3210)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-06-01
18:19:08 UTC (rev 3211)
@@ -62,8 +62,20 @@
StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
assertFalse(statement.execute("set foo bar")); //$NON-NLS-1$
assertEquals("bar", p.get("foo")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertFalse(statement.execute("set foo 'b''ar'"));
//$NON-NLS-1$
+ assertEquals("b'ar", p.get("foo")); //$NON-NLS-1$
//$NON-NLS-2$
}
+ @Test public void testSetAuthorizationStatement() throws Exception {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ Properties p = new Properties();
+ Mockito.stub(conn.getExecutionProperties()).toReturn(p);
+ StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+ assertFalse(statement.execute("set session authorization bar"));
//$NON-NLS-1$
+ Mockito.verify(conn).changeUser("bar", null);
+ }
+
@Test public void testPropertiesOverride() throws Exception {
ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
Properties p = new Properties();
Modified:
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
===================================================================
---
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-06-01
16:37:30 UTC (rev 3210)
+++
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-06-01
18:19:08 UTC (rev 3211)
@@ -551,7 +551,7 @@
The Teiid driver/DataSource should then typically be configured to just use the
single host/port of your load balancer.</para>
</section>
</section>
- <section>
+ <section id="reauthentication">
<title>Reauthentication</title>
<para>Teiid connections (defined by the
<code>org.teiid.jdbc.TeiidConnection</code> interface) support the changeUser
method to reauthenticate a given connection.
If the reauthentication is successful the current connection my be used with the
given identity.
Modified:
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
===================================================================
---
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-06-01
16:37:30 UTC (rev 3210)
+++
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-06-01
18:19:08 UTC (rev 3211)
@@ -185,7 +185,7 @@
<para>SET Syntax:
</para>
<listitem>
- <para>SET parameter value
+ <para>SET (parameter|SESSION AUTHORIZATION) value
</para>
</listitem>
</itemizedlist>
@@ -193,10 +193,10 @@
<para>Syntax Rules:
</para>
<listitem>
- <para>Both parameter and value must be simple literals - they
cannot contain spaces.</para>
+ <para>The parameter must be a non-quoted identifier - it cannot
contain spaces.</para>
</listitem>
<listitem>
- <para>The value is also not treated as an expression and will not
be evaluated prior to being set as the parameter value.</para>
+ <para>The value may be either a non-quoted identifier or a quoted
string literal value.</para>
</listitem>
</itemizedlist>
<para>The SET statement is most commonly used to control planning and
execution.</para>
@@ -208,7 +208,6 @@
<para>SET NOEXEC (ON|OFF)</para>
</listitem>
</itemizedlist>
-
<example id="plan_debug">
<title>Enabling Plan Debug</title>
<programlisting>Statement s = connection.createStatement();
@@ -222,6 +221,16 @@
String debugLog = planRs.getString("DEBUG_LOG");
</programlisting>
</example>
+ <para>The SET statement may also be used to control authorization.
+ A SET SESSION AUTHORIZATION statement will perform a <xref
linkend="reauthentication"/> given the credentials currently set on the
connection.
+ The connection credentials may be changed by issuing a SET PASSWORD statement. A
SET PASSWORD statement does not perform a reauthentication.</para>
+ <example>
+ <title>Changing Session Authorization</title>
+ <programlisting>Statement s = connection.createStatement();
+s.execute("SET PASSWORD 'someval'");
+s.execute("SET SESSION AUTHORIZATION 'newuser'");
+ </programlisting>
+ </example>
</section>
<section id="show_statement">