Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 4222C9FB5BE; Tue, 23 Jan 2007 11:31:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 82896-10; Tue, 23 Jan 2007 11:31:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 3FEC09FB5BD; Tue, 23 Jan 2007 11:31:20 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 23 Jan 2007 07:31:14 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable In-Reply-To: <45B59C68.8080203@comcast.net> X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 References: <45B59C68.8080203@comcast.net> Organization: MIR3, Inc. X-Mailer: Evolution 2.0.2 (2.0.2-27.rhel4.6) content-class: urn:content-classes:message Subject: Re: Applet Connectivity - PLEASE help Date: Tue, 23 Jan 2007 07:33:31 -0800 Message-ID: <1169566274.4519.4.camel@archimedes> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [JDBC] Applet Connectivity - PLEASE help Thread-Index: Acc/A9YHteIOhwCIRi2QA9TD9q/yOQ== From: "Mark Lewis" To: "Marc" Cc: , X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/150 X-Sequence-Number: 16515 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=20 > 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=20 > same machine. > I'm using Postgres 8.2 and Java 1.5 w/ the postgresql-8.2-504.jdbc3 = jdbc=20 > driver. > The software works when run through my IDE (Eclipse) but not as an=20 > applet in a browser. > I've set listen_addresses =3D '*' in postgresql.conf and my pg_hba=20 > settings are: > local all all md5 > host all all 127.0.0.1/32 trust. >=20 > Here's the code I'm using to try to make the connection where > strServer =3D :jdbc:postgresql://localhost/Arco > strDriver =3D org.postgresql.Driver > strUser =3D postgres > strPswd =3D fred >=20 > public DBConnection(Trace trace, JApplet p_applet) > throws Exception > { > URL dbIniURL; > URLConnection urlConn; > BufferedReader in; > int vals =3D 0; > String nextVal; > String strProp; > String strVal; > String strUser =3D ""; > String strPswd =3D ""; > int pos; > Properties props =3D new Properties(); >=20 > try > { > System.out.println("Instantiate DBConnection."); > =20 > dbIniURL =3D new URL(p_applet.getDocumentBase(), = "db.ini"); > urlConn =3D dbIniURL.openConnection(); > in =3D new BufferedReader(new=20 > InputStreamReader(urlConn.getInputStream())); > =20 > while (vals < 4) > { > nextVal =3D in.readLine(); > vals =3D vals + 1; > =20 > System.out.println("db.ini: " + nextVal.trim()); >=20 > pos =3D nextVal.indexOf(":"); >=20 > if (pos>0) > { > strProp =3D nextVal.substring(0,pos); > strVal =3D nextVal.substring(pos+1); >=20 > if (strProp.compareToIgnoreCase("Server") =3D=3D = 0) > { > strServer =3D strVal; > } > else if (strProp.compareToIgnoreCase("Driver") = =3D=3D 0) > { > strDriver =3D strVal; > } > else if (strProp.compareToIgnoreCase("User") = =3D=3D 0) > { > strUser =3D strVal; > } > else if (strProp.compareToIgnoreCase("Password") = =3D=3D 0) > { > strPswd =3D strVal; > } > } > } > =20 > drv =3D (Driver)Class.forName(strDriver).newInstance(); > DriverManager.registerDriver(drv); > =20 > =20 > props.setProperty("user",strUser.trim()); > props.setProperty("password",strPswd.trim()); >=20 > System.out.println("Attempting to connecting to postgres=20 > db..."); > dbConn=3D 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()); > } > } >=20 > 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 =3D C:\Documents and Settings\Marc >=20 >=20 > ---------------------------------------------------- > 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 > ---------------------------------------------------- >=20 > 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=20 > 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.(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=20 > (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.(Unknown Source) > at java.net.Socket.(Unknown Source) > at org.postgresql.core.PGStream.(PGStream.java:59) > at=20 > = org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connectio= nFactoryImpl.java:77) > at=20 > = org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.ja= va:66) > at=20 > = org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connecti= on.java:125) > at=20 > = org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connecti= on.java:30) > at = org.postgresql.jdbc3.Jdbc3Connection.(Jdbc3Connection.java:24) > at org.postgresql.Driver.makeConnection(Driver.java:382) > at org.postgresql.Driver.connect(Driver.java:260) > ... 6 more >=20 > I think that covers it. I'm pretty wiped out being as I've been = working=20 > on this for about 4 hrs now. > Your help is really appreciated! >=20 > Thanks, > Marc >=20 > ---------------------------(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