pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
getMetaData().getUserName() implementation
2+ messages / 2 participants
[nested] [flat]

* getMetaData().getUserName() implementation
@ 2012-10-07 21:40 Thomas Hill <Thomas.K.Hill@t-online.de>
  2012-10-07 22:33 ` Re: getMetaData().getUserName() implementation Péter Kovács <peter.dunay.kovacs@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Thomas Hill @ 2012-10-07 21:40 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

I have been using Apache Derby as data base backend for an application 
over the past years and am looking into adding PostgreSQL as an 
additional backend the application could be run against.
Obviously all stored procedure code I have written is in Java. All 
procedures/functions are defined with "Security definer" so they are 
executed with the privileges of the user that defined them.
So in a first step I installed the latest version of plJava on 
PostgreSQL 8.4 running on a Debian 6 Squeeze server and uploaded the jar 
files into the server.

In one of my procedures I am however noticing that the Apache Derby 
implementation and the PostgreSQL implementation are leading to 
different results.
When logging in as "Thomas" and then using jdbc function 
getMetaData().getUserName() *within* a stored procedure and returning 
the result to the calling program
- Apache Derby returns the session user, i.e. Thomas (and not the name 
of the data base or procedure owner [which is what CURRENT_USER when 
being called within the proc would return / but which is not what I need)
- PostgreSQL returns "postgres" whereas I would have expected it to also 
return "Thomas".

I am wondering if someone can explain why this is the case? and
how I can get around this "compatibility" issue?
If the driver implementations are different, any suggestion how to 
modify the java code so it would actually for both data base systems 
return the session_user?

Thanks a lot in advance.

Kind regards
Thomas






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: getMetaData().getUserName() implementation
  2012-10-07 21:40 getMetaData().getUserName() implementation Thomas Hill <Thomas.K.Hill@t-online.de>
@ 2012-10-07 22:33 ` Péter Kovács <peter.dunay.kovacs@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Péter Kovács @ 2012-10-07 22:33 UTC (permalink / raw)
  To: pgsql-jdbc

As JDBC doesn't appear to distinguish between real and impersonated user,
the safest is probably to bypass the JDBC API and use the native SQL API:
http://www.postgresql.org/docs/8.3/static/functions-info.html

Peter
On Oct 8, 2012 12:27 AM, "Péter Kovács" <peter.dunay.kovacs@gmail.com>
wrote:

> The safest is probably to bypass the JDBC API and use the native SQL API:
> http://www.postgresql.org/docs/8.3/static/functions-info.html
>
> Peter
> On Oct 7, 2012 11:41 PM, "Thomas Hill" <Thomas.K.Hill@t-online.de> wrote:
>
>> Hello,
>>
>> I have been using Apache Derby as data base backend for an application
>> over the past years and am looking into adding PostgreSQL as an additional
>> backend the application could be run against.
>> Obviously all stored procedure code I have written is in Java. All
>> procedures/functions are defined with "Security definer" so they are
>> executed with the privileges of the user that defined them.
>> So in a first step I installed the latest version of plJava on PostgreSQL
>> 8.4 running on a Debian 6 Squeeze server and uploaded the jar files into
>> the server.
>>
>> In one of my procedures I am however noticing that the Apache Derby
>> implementation and the PostgreSQL implementation are leading to different
>> results.
>> When logging in as "Thomas" and then using jdbc function
>> getMetaData().getUserName() *within* a stored procedure and returning the
>> result to the calling program
>> - Apache Derby returns the session user, i.e. Thomas (and not the name of
>> the data base or procedure owner [which is what CURRENT_USER when being
>> called within the proc would return / but which is not what I need)
>> - PostgreSQL returns "postgres" whereas I would have expected it to also
>> return "Thomas".
>>
>> I am wondering if someone can explain why this is the case? and
>> how I can get around this "compatibility" issue?
>> If the driver implementations are different, any suggestion how to modify
>> the java code so it would actually for both data base systems return the
>> session_user?
>>
>> Thanks a lot in advance.
>>
>> Kind regards
>> Thomas
>>
>>
>>
>>
>> --
>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/**mailpref/pgsql-jdbc<http://www.postgresql.org/mailpref/pgsql-jdbc;
>>
>

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2012-10-07 22:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-10-07 21:40 getMetaData().getUserName() implementation Thomas Hill <Thomas.K.Hill@t-online.de>
2012-10-07 22:33 ` Péter Kovács <peter.dunay.kovacs@gmail.com>

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