User Is as Parameter

0

Hello,



In JasperServer (4.1), how can I transmit the user id as parameter in a report.


I need it to apply grants to the returned data.



Thanks.

vbouq's picture
2
Joined: Jan 24 2012 - 11:46pm
Last seen: 9 years 2 months ago

8 Answers:

0

Hello

I have the same problem. Is there any way to print the name or user ID that has been validated in jasperserver? Is there a parameter or variable something like $P{userid}?

Thank you!

txemacarcar's picture
Joined: Apr 11 2011 - 5:06am
Last seen: 4 years 9 months ago
0

I attached a small jrxml file that I use to display the properties assigned to the logged in user. I usually add $P{LoggedInUser} in my reports to show who ran the report.

http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Code:
  <?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports <a href="http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"" target="_blank">http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"</a> name="UserData" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
	<property name="ireport.zoom" value="1.0"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
	<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"/>
	<parameter name="LoggedInUserFullName" class="java.lang.String" isForPrompting="false"/>
	<parameter name="LoggedInUserEmailAddress" class="java.lang.String" isForPrompting="false"/>
	<parameter name="LoggedInUserEnabled" class="java.lang.Boolean" isForPrompting="false"/>
	<parameter name="LoggedInUserExternallyDefined" class="java.lang.Boolean" isForPrompting="false"/>
	<parameter name="LoggedInUserTenantId" class="java.lang.String" isForPrompting="false"/>
	<parameter name="LoggedInUserRoles" class="java.util.Collection" isForPrompting="false"/>
	<parameter name="LoggedInUserAttributes" class="java.util.Map" isForPrompting="false"/>
	<parameter name="LoggedInUserAttributeNames" class="java.util.Collection" isForPrompting="false"/>
	<parameter name="LoggedInUserAttributeValues" class="java.util.Collection" isForPrompting="false"/>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="468" splitType="Stretch">
			<frame>
				<reportElement mode="Opaque" x="28" y="0" width="476" height="172" backcolor="#CCCCCC"/>
				<textField>
					<reportElement mode="Transparent" x="111" y="0" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[""+$P{LoggedInUser}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement mode="Transparent" x="111" y="20" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[$P{LoggedInUsername}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement mode="Transparent" x="111" y="40" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[$P{LoggedInUserFullName}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement mode="Transparent" x="111" y="60" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[$P{LoggedInUserEmailAddress}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement mode="Transparent" x="111" y="80" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[$P{LoggedInUserTenantId}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement stretchType="RelativeToTallestObject" mode="Transparent" x="-107" y="60" width="318" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[""+$P{LoggedInUserRoles}]]></textFieldExpression>
				</textField>
				<textField>
					<reportElement mode="Transparent" x="111" y="120" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#FFFFFF"/>
					<textElement/>
					<textFieldExpression><![CDATA[""+$P{LoggedInUserAttributes}]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement mode="Transparent" x="0" y="0" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[User]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="80" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[TenantId]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="60" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[Email]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="40" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[Full Name]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="20" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[UserName]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="140" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[Roles]]></text>
				</staticText>
				<staticText>
					<reportElement mode="Transparent" x="0" y="120" width="100" height="20" backcolor="#FFFFFF"/>
					<textElement/>
					<text><![CDATA[Attributes]]></text>
				</staticText>
			</frame>
		</band>
	</title>
</jasperReport>
</td></tr></tbody></table>
brooneyx1's picture
119
Joined: May 4 2009 - 6:10pm
Last seen: 2 years 11 months ago
0

Thanks brooneyx1!!


But I get the error that it show in the attachment.

Any idea?


Thank you.
 

 

Code:
Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@1b818b0  net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type                 value = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 2. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type                 value = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 3. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type                 value = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 3 errors  Â Â Â Â at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:191)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:499)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)</td></tr></tbody></table>
txemacarcar's picture
Joined: Apr 11 2011 - 5:06am
Last seen: 4 years 9 months ago
0

I think brooneyx1 might have left the defaultValueExpression for LoggedInUserName.  I have done something similar with iReports.  I have attached what I use.

I tried to find the webpage that documents com.jaspersoft.jasperserver.api.metadata.user.domain.User but can't find it.  There are a number of other methods you can call for the class.

Code:
	<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
	<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA[(Object)$P{LoggedInUser}.getUsername()]]></defaultValueExpression>
	</parameter></td></tr></tbody></table>
twmoore's picture
10
Joined: Aug 25 2011 - 12:46pm
Last seen: 7 years 1 month ago
0

Sorry, I got the error because I was running on iReport. Once uploaded to the server works fine and displays the user data correctly.

Thank you very much for your help!

txemacarcar's picture
Joined: Apr 11 2011 - 5:06am
Last seen: 4 years 9 months ago
0

Yes, sorry about leaving out that important peice of information. The report will only work in jasperserver, not in iReport !

 

brooneyx1's picture
119
Joined: May 4 2009 - 6:10pm
Last seen: 2 years 11 months ago
0

Works fine. Ty

 

vbouq's picture
2
Joined: Jan 24 2012 - 11:46pm
Last seen: 9 years 2 months ago
0

Hi,

I am using Jasper 7 version,  is LoggedInUser parameter deprecated for this version. I am not able to import user interface.

hgothankar's picture
Joined: May 30 2018 - 11:32am
Last seen: 1 hour 52 min ago
Feedback