s.close();
}
private static void testDSRequestAuthentication() throws SQLException {
EmbeddedDataSource ds = new EmbeddedDataSource();
System.out.println("DataSource - EMPTY");
dsConnectionRequests(ds);
System.out.println("DataSource - connectionAttributes=databaseName=wombat");
ds.setConnectionAttributes("databaseName=wombat");
dsConnectionRequests(ds);
ds.setConnectionAttributes(null);
System.out.println("DataSource - attributesAsPassword=true");
ds.setAttributesAsPassword(true);
dsConnectionRequests(ds);
ds.setAttributesAsPassword(false);
System.out.println("DataSource - attributesAsPassword=true, connectionAttributes=databaseName=kangaroo");
ds.setAttributesAsPassword(true);
ds.setConnectionAttributes("databaseName=kangaroo");
dsConnectionRequests(ds);
ds.setAttributesAsPassword(false);
ds.setConnectionAttributes(null);
System.out.println("Enable Authentication");
ds.setDatabaseName("wombat");
Connection cadmin = ds.getConnection();
CallableStatement cs = cadmin.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
cs.setString(1, "derby.user.fred");
cs.setString(2, "wilma");
cs.execute();
cs.setString(1, "derby.authentication.provider");
cs.setString(2, "BUILTIN");
cs.execute();
cs.setString(1, "derby.connection.requireAuthentication");
cs.setString(2, "true");
cs.execute();
cs.close();
cadmin.close();
ds.setShutdownDatabase("shutdown");
try {
ds.getConnection();
} catch (SQLException sqle) {
System.out.println(sqle.getSQLState() + ":" + sqle.getMessage() );
}
ds.setDatabaseName(null);
ds.setShutdownDatabase(null);
System.out.println("AUTHENTICATION NOW ENABLED");
System.out.println("DataSource - attributesAsPassword=true");
ds.setAttributesAsPassword(true);
dsConnectionRequests(ds);
ds.setAttributesAsPassword(false);
// ensure the DS property password is not treated as a set of attributes.
System.out.println("DataSource - attributesAsPassword=true, user=fred, password=databaseName=wombat;password=wilma");
ds.setAttributesAsPassword(true);
ds.setUser("fred");
ds.setPassword("databaseName=wombat;password=wilma");
dsConnectionRequests(ds);
ds.setAttributesAsPassword(false);
ds.setUser(null);
ds.setPassword(null);
ds = null;
// now with ConnectionPoolDataSource
EmbeddedConnectionPoolDataSource cpds = new EmbeddedConnectionPoolDataSource();
System.out.println("ConnectionPoolDataSource - EMPTY");