Skip to main content



      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 05:16 Go to next message
Eclipse UserFriend
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 13:12 Go to previous messageGo to next message
Eclipse UserFriend
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 10:25 Go to previous messageGo to next message
Eclipse UserFriend
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 12:44 Go to previous messageGo to next message
Eclipse UserFriend
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] Tue, 24 June 2014 20:33 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 15:15:34 EDT 2025

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

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

Back to the top