pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Lewis <mark.lewis@mir3.com>
To: Marc <mhorv@comcast.net>
Cc: pgsql-jdbc@postgresql.org
Cc: pgsql-novice@postgresql.org
Subject: Re: Applet Connectivity - PLEASE help
Date: Tue, 23 Jan 2007 07:33:31 -0800
Message-ID: <1169566274.4519.4.camel@archimedes> (raw)
In-Reply-To: <45B59C68.8080203@comcast.net>
References: <45B59C68.8080203@comcast.net>

It's not a PostgreSQL-specific error.  Applets run in a sandbox which
limits the damage they can do.  Specifically what's biting you in this
case is that applets are only allowed to establish network connections
back to the IP address they came from.  You can see this because you're
getting a java.security.AccessControlException thrown in the stack trace
when the JDBC driver tries to connect to the server at "localhost".

-- Mark Lewis

On Tue, 2007-01-23 at 00:26 -0500, Marc wrote:
> OK, I'll say right up front I'm a postgres novice at best.
> I've spent quite some time researching this tonight and trying out a few 
> things to no avail.
> The basic question is can an applet connect to a postgres database and 
> if so how (I need specific details)?
> Postgres, the database, the web server and signed applet are all on the 
> same machine.
> I'm using Postgres 8.2 and Java 1.5 w/ the postgresql-8.2-504.jdbc3 jdbc 
> driver.
> The software works when run through my IDE (Eclipse) but not as an 
> applet in a browser.
> I've set listen_addresses = '*' in postgresql.conf and my pg_hba 
> settings are:
> local      all      all                               md5
> host       all      all         127.0.0.1/32          trust.
> 
> Here's the code I'm using to try to make the connection where
> strServer = :jdbc:postgresql://localhost/Arco
> strDriver = org.postgresql.Driver
> strUser = postgres
> strPswd = fred
> 
>     public DBConnection(Trace trace, JApplet p_applet)
>         throws Exception
>     {
>         URL    dbIniURL;
>         URLConnection  urlConn;
>         BufferedReader in;
>         int            vals = 0;
>         String         nextVal;
>         String         strProp;
>         String         strVal;
>         String         strUser = "";
>         String         strPswd = "";
>         int            pos;
>         Properties     props = new Properties();
> 
>         try
>         {
>             System.out.println("Instantiate DBConnection.");
>            
>             dbIniURL = new URL(p_applet.getDocumentBase(), "db.ini");
>             urlConn = dbIniURL.openConnection();
>             in = new BufferedReader(new 
> InputStreamReader(urlConn.getInputStream()));
>            
>             while (vals < 4)
>             {
>                 nextVal = in.readLine();
>                 vals = vals + 1;
>                
>                 System.out.println("db.ini: " + nextVal.trim());
> 
>                 pos = nextVal.indexOf(":");
> 
>                 if (pos>0)
>                 {
>                     strProp = nextVal.substring(0,pos);
>                     strVal = nextVal.substring(pos+1);
> 
>                     if (strProp.compareToIgnoreCase("Server") == 0)
>                     {
>                         strServer = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("Driver") == 0)
>                     {
>                         strDriver = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("User") == 0)
>                     {
>                         strUser = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("Password") == 0)
>                     {
>                         strPswd = strVal;
>                     }
>                 }
>             }
>            
>             drv = (Driver)Class.forName(strDriver).newInstance();
>             DriverManager.registerDriver(drv);
>            
>            
>             props.setProperty("user",strUser.trim());
>             props.setProperty("password",strPswd.trim());
> 
>             System.out.println("Attempting to connecting to postgres 
> db...");
>             dbConn= DriverManager.getConnection(strServer, props);
>             System.out.println("Connected to postgres db.");
>         }
>         catch (IOException ioe)
>         {
>             System.out.println("Error trying to connect to postgres db:");
>             ioe.printStackTrace();
>             throw new Exception(ioe.getMessage());
>         }
>     }
> 
> The error I get in the console is:
> Java Plug-in 1.6.0
> Using JRE version 1.6.0 Java HotSpot(TM) Client VM
> User home directory = C:\Documents and Settings\Marc
> 
> 
> ----------------------------------------------------
> c:   clear console window
> f:   finalize objects on finalization queue
> g:   garbage collect
> h:   display this help message
> l:   dump classloader list
> m:   print memory usage
> o:   trigger logging
> p:   reload proxy configuration
> q:   hide console
> r:   reload policy configuration
> s:   dump system and deployment properties
> t:   dump thread list
> v:   dump thread stack
> x:   clear classloader cache
> 0-5: set trace level to <n>
> ----------------------------------------------------
> 
> Init applet.
> Call new DBConnection.
> Instantiate DBConnection.
> db.ini: Server:jdbc:postgresql://localhost/Arco
> db.ini: Driver:org.postgresql.Driver
> Attempting to connecting to postgres db...
> org.postgresql.util.PSQLException: Something unusual has occured to 
> cause the driver to fail. Please report this exception.
>     at org.postgresql.Driver.connect(Driver.java:276)
>     at java.sql.DriverManager.getConnection(Unknown Source)
>     at java.sql.DriverManager.getConnection(Unknown Source)
>     at db.DBConnection.<init>(DBConnection.java:169)
>     at ui.BaseApplet.init(BaseApplet.java:138)
>     at sun.applet.AppletPanel.run(Unknown Source)
>     at java.lang.Thread.run(Unknown Source)
> Caused by: java.security.AccessControlException: access denied 
> (java.net.SocketPermission 127.0.0.1:5432 connect,resolve)
>     at java.security.AccessControlContext.checkPermission(Unknown Source)
>     at java.security.AccessController.checkPermission(Unknown Source)
>     at java.lang.SecurityManager.checkPermission(Unknown Source)
>     at java.lang.SecurityManager.checkConnect(Unknown Source)
>     at java.net.Socket.connect(Unknown Source)
>     at java.net.Socket.connect(Unknown Source)
>     at java.net.Socket.<init>(Unknown Source)
>     at java.net.Socket.<init>(Unknown Source)
>     at org.postgresql.core.PGStream.<init>(PGStream.java:59)
>     at 
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:77)
>     at 
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>     at 
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
>     at 
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>     at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>     at org.postgresql.Driver.makeConnection(Driver.java:382)
>     at org.postgresql.Driver.connect(Driver.java:260)
>     ... 6 more
> 
> I think that covers it. I'm pretty wiped out being as I've been working 
> on this for about 4 hrs now.
> Your help is really appreciated!
> 
> Thanks,
> Marc
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly





view thread (4+ messages)  latest in thread

Message-ID: <1169566274.4519.4.camel@archimedes>
Permalink:  ../1169566274.4519.4.camel@archimedes/
Also on:    postgresql.org/message-id/1169566274.4519.4.camel@archimedes

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: mark.lewis@mir3.com, mhorv@comcast.net, pgsql-novice@postgresql.org
  Subject: Re: Applet Connectivity - PLEASE help
  In-Reply-To: <1169566274.4519.4.camel@archimedes>
  References: <45B59C68.8080203@comcast.net> <1169566274.4519.4.camel@archimedes>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox