Translate

Monday 24 March 2014

How to display the Username of the user who logged into JasperServer

Many a times we require the name of the person who logged into the Jasper Server and according to this information we are able to show/hide the elements on report, or simpley to log the user name we can use it.

So how to achieve this ? 


We can create parameters in our report, with a specific name and datatype. Then these parameters will be automatically filled when the report is executed by JasperReports Server.
LoggedInUsername (java.lang.String), with no default value. Then, we can use $P{LoggedInUsername} in a text field, in a query, in a printWhenExpression, etc ...
This is a built in parameter which gets filled with the User Details when report is run on Jasper Server.
Note that the report if run in iReport, would get a null value. So for the correct results it is necessary that we deploy the report onto JasperServer.



Parameter Name
Type
Notes
LoggedInUser
User
Not usable in query input control,
 but is used as parameter to report
LoggedInUsername
String
Of logged in user
LoggedInUserFullName
String
Of logged in user
LoggedInUserEmailAddress
String
Of logged in user
LoggedInUserEnabled
Boolean
Is logged in user enabled?
LoggedInUserExternallyDefined
Boolean
Is logged in user externally defined?
 ie. authenticated externally
LoggedInUserTenantId
String
Of logged in user. Only relevant in 
Pro/Enterprise.
LoggedInUserRoles
Collection<string>
Current set of roles of logged in user. 
Useful for $X parameter
LoggedInUserAttributes
Map<string, string>
Not usable in query input control, but is 
used as parameter to report.
 Empty map if no attributes
LoggedInUserAttributeNames
Collection<string>
User profile attribute names. Useful for
 $X parameters. Empty collection if no
 
attributes
LoggedInUserAttributeValues
Collection
-
LoggedInUserAttribute_<attribute name>
String
Attribute value for matched attribute name (like "att1") on the user. Empty string if no match. Only provided if defined in a query or as a report parameter.

Using the above parameters we could easily get various important information which could help in defining the roles. 

Happy Coding.!!

No comments:

Post a Comment

Please post your queries or suggestions here!!