You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Hong Ji <ho...@gmail.com> on 2006/09/23 19:36:22 UTC

Re: derby security

The ij is still able to access the database without user name and password.

I set properties and create new database in java as following:

        m_dbProperties = new Properties();
        m_dbProperties.put("user", "admin");
        m_dbProperties.put("password", "adminadmin");
        m_dbProperties.put("derby.driver", "
org.apache.derby.jdbc.EmbeddedDriver");
        m_dbProperties.put("derby.url", "jdbc:derby:");
        m_dbProperties.put("derby.connection.requireAuthentication",
"true");

        m_dbProperties.put("create", "true");

        dbConnection = DriverManager.getConnection(dbUrl, m_dbProperties);

Is something still not set up properly?

Thanks.

Hong



On 8/29/06, Francois Orsini <fr...@gmail.com> wrote:
>
> and make sure to re-boot the database or derby instance for the '
> derby.connection.requireAuthentication' property to be taken into
> account...It is a static property.
>
> On 8/29/06, Fernanda Pizzorno <Fe...@sun.com> wrote:
> >
> > To enable user authentication in Derby you must set the
> > /derby.connection.requireAuthentication/ property to true.
> >
> > You can find more information about derby security on "Derby and
> > Security" in "/Derby Developer's Guide"
> > (http://db.apache.org/derby/docs/dev/devguide/ ).
> >
> > Fernanda
> > /
> > Hong Ji wrote:
> > > Hello,
> > >
> > > I created a derby database in Java with user name and password.
> > > However, the
> > > ij tool can open and view the database without input of the user name
> > or
> > > password.
> > >
> > > So how could a derby database be protected? Anyone can use ij to view
> > the
> > > database?
> > >
> > > Thanks.
> > >
> > > Hong Ji
> > >
> >
> >
>

Re: How to recover from the DB not existing

Posted by John Embretsen <Jo...@Sun.COM>.
Nicholas Negulescu wrote:

[...]
> My problem is that I'm trying to figure out how to load it from an SQL 
> file. Sure, I can do it on the command line like so:
> 
> java -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver 
> org.apache.derby.tools.ij <bogusdb.sql>
> 
> but I was wondering which tool/class to use when you've alread got the 
> driver loaded and you're executing withing the VM already.
[...]

You might want to check out the new ij method called runScript(...), 
which was added in Derby 10.2 (soon to be released).

JavaDoc (for 10.2 runScript method) is here:

http://db.apache.org/derby/docs/10.2/publishedapi/jdbc3/org/apache/derby/tools/ij.html#runScript(java.sql.Connection,%20java.io.InputStream,%20java.lang.String,%20java.io.OutputStream,%20java.lang.String)


-- 
John


Re: How to recover from the DB not existing

Posted by Nicholas Negulescu <ni...@gmail.com>.
I was thinking just the other way around. =)

The only time the exception will be thrown is if there is no database. In
the (rare/one-time) event that this is the first time a user has started the
application and the database does not exist, then go and create it from the
bogusdb.sql file -- zero admin. I'm using POJOs, not working with Hibernate
either (yet).

My problem is that I'm trying to figure out how to load it from an SQL file.
Sure, I can do it on the command line like so:

java -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver
org.apache.derby.tools.ij <bogusdb.sql>

but I was wondering which tool/class to use when you've alread got the
driver loaded and you're executing withing the VM already. I see that dblook
has an output (but no input) mechanism:

java org.apache.derby.tools.dblook -d 'jdbc:derby:c:\private\stuff\sample'
-o 'C:\temp\newDB.sql'

But this too is command-line driven. Thanks in advance!



On 9/24/06, Barry Books <tr...@gmail.com> wrote:
>
> You could always use create=true then load the database if it's not
> loaded. To figure out if it's been loaded you could select your your
> table names to see if they have been created. None of that will
> generate an exception.
>

Re: How to recover from the DB not existing

Posted by Barry Books <tr...@gmail.com>.
You could always use create=true then load the database if it's not
loaded. To figure out if it's been loaded you could select your your
table names to see if they have been created. None of that will
generate an exception.

How to recover from the DB not existing

Posted by nick negulescu <ni...@gmail.com>.
I'm new to Derby and I'm trying to figure out how to load a database 
from a file if it doesn't already exist when loading the driver for the 
first time. I know I'm getting an SQLState of XJ004 and an ErrorCode of 
40000. This is code for when the application first starts up -- if the 
db doesn't exist -- let's create it unbeknownst to the user. What I 
would like to do is catch the exception. If the DB is not there, I want 
to create it, load it from the "bogus.SQL" text file and then try again:

        try {
            _conn = DriverManager.getConnection("jdbc:derby:bogusdb");
        }
        catch (SQLException e){
             <if SQLState = XJ004; create db with 
"jdbc:derby:bogusdb;create=true">
             <load db schema from file "bogus.SQL">
             <try "DriverManager.getConnection("jdbc:derby:bogusdb")" again>
             ...
            }
        }

Can anybody point me to the correct location in the documentation? I'm 
thinking that I'll need to load the file using IJ, but I'm not sure how 
to load the schema from a text file....

P.S. Great presentation Dan & Dave. I've been a list follower for a few 
months. I hadn't thought about to the memory stick idea: 
http://developers.sun.com/learning/javaoneonline/sessions/2006/TS-3154/index.html

Re: derby security

Posted by Hong Ji <ho...@gmail.com>.
Thanks. I did more reading on derby doc and find the encryption may serve
the purpose since the derby db is used as embed db.

Hong

On 9/23/06, Rajesh Kartha <ka...@gmail.com> wrote:
>
> Hello,
>
> The 'derby.connection.requireAuthentication' need to set as system
> property (using -D)  while running your application
> or as a database property (within the database).
>
> More info at:
> http://db.apache.org/derby/docs/dev/tuning/rtunproper27467.html
>
> Also, there is some discussion on this in one of the JIRA issues at:
> http://issues.apache.org/jira/browse/DERBY-1711
>
> From you example you seem to pass the property as Connection properties
> which has a limited scope.
>
> Hope the above helps. Do post to the list should you have further
> questions.
>
> -Rajesh
>
>
> Hong Ji wrote:
>
> > The ij is still able to access the database without user name and
> > password.
> >
> > I set properties and create new database in java as following:
> >
> >         m_dbProperties = new Properties();
> >         m_dbProperties.put("user", "admin");
> >         m_dbProperties.put("password", "adminadmin");
> >         m_dbProperties.put(" derby.driver",
> > "org.apache.derby.jdbc.EmbeddedDriver");
> >         m_dbProperties.put("derby.url", "jdbc:derby:");
> >         m_dbProperties.put("derby.connection.requireAuthentication ",
> > "true");
> >
> >         m_dbProperties.put("create", "true");
> >
> >         dbConnection = DriverManager.getConnection(dbUrl,
> m_dbProperties);
> >
> > Is something still not set up properly?
> >
> > Thanks.
> >
> > Hong
> >
> >
> >
> > On 8/29/06, *Francois Orsini* <francois.orsini@gmail.com
> > <ma...@gmail.com>> wrote:
> >
> >     and make sure to re-boot the database or derby instance for the
> >     'derby.connection.requireAuthentication' property to be taken into
> >     account...It is a static property.
> >
> >
> >     On 8/29/06, *Fernanda Pizzorno* <Fernanda.Pizzorno@sun.com
> >     <ma...@sun.com>> wrote:
> >
> >         To enable user authentication in Derby you must set the
> >         /derby.connection.requireAuthentication/ property to true.
> >
> >         You can find more information about derby security on "Derby and
> >         Security" in "/Derby Developer's Guide"
> >         ( http://db.apache.org/derby/docs/dev/devguide/
> >         <http://db.apache.org/derby/docs/dev/devguide/>).
> >
> >         Fernanda
> >         /
> >         Hong Ji wrote:
> >> Hello,
> >>
> >> I created a derby database in Java with user name and password.
> >> However, the
> >> ij tool can open and view the database without input of the
> >         user name or
> >> password.
> >>
> >> So how could a derby database be protected? Anyone can use ij
> >         to view the
> >> database?
> >>
> >> Thanks.
> >>
> >> Hong Ji
> >>
> >
> >
> >
>
>

Re: derby security

Posted by Rajesh Kartha <ka...@gmail.com>.
Hello,

The 'derby.connection.requireAuthentication' need to set as system 
property (using -D)  while running your application
or as a database property (within the database).

More info at:
http://db.apache.org/derby/docs/dev/tuning/rtunproper27467.html

Also, there is some discussion on this in one of the JIRA issues at:
http://issues.apache.org/jira/browse/DERBY-1711

 From you example you seem to pass the property as Connection properties 
which has a limited scope.

Hope the above helps. Do post to the list should you have further questions.

-Rajesh


Hong Ji wrote:

> The ij is still able to access the database without user name and 
> password.
>  
> I set properties and create new database in java as following:
>  
>         m_dbProperties = new Properties();
>         m_dbProperties.put("user", "admin");
>         m_dbProperties.put("password", "adminadmin");
>         m_dbProperties.put(" derby.driver", 
> "org.apache.derby.jdbc.EmbeddedDriver");
>         m_dbProperties.put("derby.url", "jdbc:derby:");
>         m_dbProperties.put("derby.connection.requireAuthentication ", 
> "true");
>  
>         m_dbProperties.put("create", "true");
>         
>         dbConnection = DriverManager.getConnection(dbUrl, m_dbProperties);
>       
> Is something still not set up properly?
>  
> Thanks.
>  
> Hong
>  
>  
>  
> On 8/29/06, *Francois Orsini* <francois.orsini@gmail.com 
> <ma...@gmail.com>> wrote:
>
>     and make sure to re-boot the database or derby instance for the
>     'derby.connection.requireAuthentication' property to be taken into
>     account...It is a static property.
>
>
>     On 8/29/06, *Fernanda Pizzorno* <Fernanda.Pizzorno@sun.com
>     <ma...@sun.com>> wrote:
>
>         To enable user authentication in Derby you must set the
>         /derby.connection.requireAuthentication/ property to true.
>
>         You can find more information about derby security on "Derby and
>         Security" in "/Derby Developer's Guide"
>         ( http://db.apache.org/derby/docs/dev/devguide/
>         <http://db.apache.org/derby/docs/dev/devguide/>).
>
>         Fernanda
>         /
>         Hong Ji wrote:
>> Hello,
>>
>> I created a derby database in Java with user name and password.
>> However, the
>> ij tool can open and view the database without input of the
>         user name or
>> password.
>>
>> So how could a derby database be protected? Anyone can use ij
>         to view the
>> database?
>>
>> Thanks.
>>
>> Hong Ji
>>
>
>
>