Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Get Logged in user(Is there a way to get the currently logged in user from Tomcat?)
Get Logged in user [message #883313] Fri, 08 June 2012 09:16 Go to next message
Rick Missing name is currently offline Rick Missing nameFriend
Messages: 5
Registered: July 2009
Junior Member
We're running Tomcat 3.7.1. on Tomcat 5.5.
Tomcat 5.5 is running on Linux, the clients are Windows clients in an AD Domain.
What would be the best way to get the username of the user requesting the report? I should be able to get it from Tomcat using this method?
Unfortunately, i'm unable to post links, but googling for this gives the post i'm talking about:
20140-accessing-servlet-context-in-the-report
I've been trying to get this working, but i can't figure it out entirely.
Re: Get Logged in user [message #883501 is a reply to message #883313] Fri, 08 June 2012 17:12 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You can get session variables in a report expression or script like:

var sess = reportContext.getHttpServletRequest().getSession();
var myvar = sess.getAttribute("youvariable");
I am not sure how you would get the user into session.

Jason

On 6/8/2012 5:16 AM, Rick Mising name wrote:
> We're running Tomcat 3.7.1. on Tomcat 5.5.
> Tomcat 5.5 is running on Linux, the clients are Windows clients in an AD
> Domain. What would be the best way to get the username of the user
> requesting the report? I should be able to get it from Tomcat using this
> method?
> Unfortunately, i'm unable to post links, but googling for this gives the
> post i'm talking about:
> 20140-accessing-servlet-context-in-the-report
> I've been trying to get this working, but i can't figure it out entirely.
Re: Get Logged in user [message #884635 is a reply to message #883501] Mon, 11 June 2012 14:25 Go to previous messageGo to next message
Rick Missing name is currently offline Rick Missing nameFriend
Messages: 5
Registered: July 2009
Junior Member
Thanks for your reply Jason. Further investigation based on your response made me find the solution Wink

This describes is (cp, because i can't post urls)


A. Application server configuration (e.g. Tomcat)

Add the jcifs-x.jar to the '<BIRT_VIEWER_HOME>\WEB-INF\lib' directory
Configure the BIRT-viewer application to authenticate via NTLM by adding the NTLM-filter to the web.xml:
<filter>
<filter-name>NtlmHttpFilter</filter-name>
<filter-class>jcifs.http.NtlmHttpFilter</filter-class>

<init-param>
<param-name>jcifs.smb.client.domain</param-name>
<param-value>your.domain</param-value>
</init-param>
<init-param>
<param-name>jcifs.netbios.wins</param-name>
<param-value>domain-controller.your.domain</param-value>
</init-param>

<init-param>
<param-name>jcifs.util.loglevel</param-name>
<param-value>2</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>NtlmHttpFilter</filter-name>
<servlet-name>ViewerServlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>NtlmHttpFilter</filter-name>
<servlet-name>EngineServlet</servlet-name>
</filter-mapping>
</filter>
Restart your Tomcat application server
Test if your BIRT-application is secured:
--> You should now be prompted for your username & password
NTLM Authentication

B. BIRT Report design
Once authenticated, you can check authorization via your Report using the BIRT Rhino Javascript.
On your dataset you can add a parameter using a default scripted value like:
var myLoginName = null;
var request = reportContext.getHttpServletRequest();
if (request!=null) {
if (request.getRemoteUser()!=null) {
myLoginName = request.getRemoteUser();
}
}
myLoginName;
BIRT authentication: scripted parameter
This parameter you can use in your query / stored procedure to filter data matching the logged-in username.
Download report-authentication example

When you run this example report on your NTLM-enabled application server (see A.), you get prompted for username & password and will see a list of products (our example query simply checks if the username is not null)


optional: you can also embed this into a global getLoggedInUsername()-function, so you can simply call getLoggedInUsername() to get the logged-in user (*).
function getLoggedInUsername() {
var myLoginName = null;
var request = reportContext.getHttpServletRequest();
if (request!=null) {
if (request.getRemoteUser()!=null) {
myLoginName = request.getRemoteUser();
}
}
return myLoginName;
}


Re: Get Logged in user [message #884711 is a reply to message #884635] Mon, 11 June 2012 16:44 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Thanks for posting your solution.

Jason

On 6/11/2012 10:25 AM, Rick Mising name wrote:
> Thanks for your reply Jason. Further investigation based on your
> response made me find the solution ;)
>
> This describes is (cp, because i can't post urls)
>
>
> A. Application server configuration (e.g. Tomcat)
>
> Add the jcifs-x.jar to the '<BIRT_VIEWER_HOME>\WEB-INF\lib' directory
> Configure the BIRT-viewer application to authenticate via NTLM by adding
> the NTLM-filter to the web.xml:
> <filter>
> <filter-name>NtlmHttpFilter</filter-name>
> <filter-class>jcifs.http.NtlmHttpFilter</filter-class>
>
> <init-param>
> <param-name>jcifs.smb.client.domain</param-name>
> <param-value>your.domain</param-value>
> </init-param>
> <init-param>
> <param-name>jcifs.netbios.wins</param-name>
> <param-value>domain-controller.your.domain</param-value>
> </init-param>
>
> <init-param>
> <param-name>jcifs.util.loglevel</param-name>
> <param-value>2</param-value>
> </init-param>
> </filter>
>
> <filter-mapping>
> <filter-name>NtlmHttpFilter</filter-name>
> <servlet-name>ViewerServlet</servlet-name>
> </filter-mapping>
> <filter-mapping>
> <filter-name>NtlmHttpFilter</filter-name>
> <servlet-name>EngineServlet</servlet-name>
> </filter-mapping>
> </filter>
> Restart your Tomcat application server Test if your BIRT-application is
> secured:
> --> You should now be prompted for your username & password
> NTLM Authentication
>
> B. BIRT Report design
> Once authenticated, you can check authorization via your Report using
> the BIRT Rhino Javascript.
> On your dataset you can add a parameter using a default scripted value
> like:
> var myLoginName = null;
> var request = reportContext.getHttpServletRequest();
> if (request!=null) {
> if (request.getRemoteUser()!=null) {
> myLoginName = request.getRemoteUser();
> }
> }
> myLoginName;
> BIRT authentication: scripted parameter
> This parameter you can use in your query / stored procedure to filter
> data matching the logged-in username.
> Download report-authentication example
>
> When you run this example report on your NTLM-enabled application server
> (see A.), you get prompted for username & password and will see a list
> of products (our example query simply checks if the username is not null)
>
>
> optional: you can also embed this into a global
> getLoggedInUsername()-function, so you can simply call
> getLoggedInUsername() to get the logged-in user (*).
> function getLoggedInUsername() {
> var myLoginName = null;
> var request = reportContext.getHttpServletRequest();
> if (request!=null) {
> if (request.getRemoteUser()!=null) {
> myLoginName = request.getRemoteUser();
> }
> }
> return myLoginName;
> }
>
>
>
Re: Get Logged in user [message #1387328 is a reply to message #884711] Wed, 25 June 2014 00:33 Go to previous message
Syed Shah is currently offline Syed ShahFriend
Messages: 13
Registered: April 2014
Junior Member
Hi,

If we are using form based authentication and not NTLM, what would be the script for retrieving the username etc?

Arif
Previous Topic:Programmatically get list of report parameters
Next Topic:Birt Migration 2.2.2 to 3.7.2
Goto Forum:
  


Current Time: Thu Apr 25 19:24:38 GMT 2024

Powered by FUDForum. Page generated in 0.02925 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top