I do not mind joining from the fact table to a row level security table that associates user ids with an organization_id - is it simple to pickup up the JS user id as a parameter?
Thanks!
17 Answers:
Code: |
<br /> <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/><br /> <parameter name="LoggedInUsername" isForPrompting="false"><br /> <defaultValueExpression>$P{LoggedInUser}.getUsername()</defaultValueExpression><br /> </parameter><br /> <queryString>SELECT .. WHERE .. $P{LoggedInUsername} ..</queryString><br /> </td></tr></tbody></table><br /> <br /> HTH,<br /> Lucian |
Code: |
<br /> public interface User extends AttributedObject {<br /> <br /> public String getUsername();<br /> <br /> public String getFullName();<br /> <br /> public String getEmailAddress();<br /> <br /> public boolean isExternallyDefined();<br /> <br /> public boolean isEnabled();<br /> <br /> public Set getRoles();<br /> <br /> }<br /> </td></tr></tbody></table><br /> <br /> <br /> Sherman<br /> JasperSoft<br>Post edited by: swood, at: 2008/02/14 07:25 |
What would be best; extend/modify the User Interface to include a function to do this, use a scriptlet, or create a stand alone java class? Extending or modifying the User interface is not ideal because I don't want to fix it each time I upgrade.
My goal is to reuse this parameter across many reports as a data source filter.
I created a 'client user' table in Postgres that contains the user name as it appears in Jasper, the client key and boolean for active users. This table is added to all 'client' reports with a where clause to filter 'user_name' = $P{LoggedInUsername}.
I would much rather parse out the client key from a user role.
I tried using an input control, but it wouldn't work due to a SQL syntax error at "= $". Probably didn't have a value for the parameter at that time. Just guess.
Re: the error, did you run the report from iReport or JasperServer?
Mary
My plan is to assign a key specific role to client users. The text for these roles would contain the clients unique key (6 digit interger). All client specific reports would be created with this filter; many users, one report, specific client data.
Here are the details of the input control:
* Single Select Query
* Mandatory = yes
* Query =
Code: |
SELECT * FROM tbl_jasper_users WHERE user_name = $P{LoggedInUsername}</td></tr></tbody></table><br /> * Parameter works; it currently displays in a text field in the report<br /> <br /> Errors being returned:<br /> <font color=#0000FF><br /> </ol>com.jaspersoft.jasperserver.api.JSExceptionWrapper: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : qrySelectKey<br /> <br /> net.sf.jasperreports.engine.JRException: Error executing SQL statement for : qrySelectKey<br /> <br /> org.postgresql.util.PSQLException: ERROR: syntax error at or near "= $"[/ol</font>]<br /> <br /> <br /> Full error is attached.<br /> <br /> Post edited by: jeffv, at: 2008/04/29 18:55 [file name=inputcontrolError.txt size=30341]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/inputcontrolError.txt[/file]<br>Post edited by: jeffv, at: 2008/04/29 18:58 |
Code: |
<br /> <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/><br /> </td></tr></tbody></table><br /> <br /> It has to be called "LoggedInUser".<br /> <br /> To get the user name as a parameter, create another parameter:<br /> <br /> <table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><br /> <parameter name="LoggedInUsername" class="java.lang.String"/><br /> <defaultValueExpression ><![CDATA[$P{LoggedInUser}].getUsername()]></defaultValueExpression><br /> </td></tr></tbody></table><br /> <br /> Then you can use $P(LoggedInUsername} in your query.<br /> <br /> <br /> <br /> Sherman<br /> JasperSoft<br>Post edited by: swood, at: 2008/04/29 19:42 |
I now want to use that parameter in the WHERE clause of an input control that will filter the list of keys available for that user.
JRXML file contains:
Code: |
<parameter name="LoggedInUser" isForPrompting="true" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/><br /> <parameter name="LoggedInUsername" isForPrompting="false" class="java.lang.String"><br /> <defaultValueExpression ><![CDATA[$P{LoggedInUser}.getUsername()]]></defaultValueExpression><br /> </parameter></td></tr></tbody></table><br /> <br /> I am connecting to a Postgres database.<br>Post edited by: jeffv, at: 2008/04/29 20:02 |
And I did not read all your details properly, so I gave the wrong advice - sorry!
Looking at it again, you cannot filter the query input control in the way you are wanting. Could you log an enhancement?
Sherman
JasperSoft
Does anyone know if it is possible to reference custom attributes from ldap entry through the LoggedInUsername in a sql? If not, could it be done any other way?
I'm trying to reference attributes like Region, Location, Timezone any custom attribute....
Something like
select * from table where
region = '$P{LoggedInUsername}.region'
Thanks
Post edited by: zhu001, at: 2008/07/01 18:37
Post edited by: zhu001, at: 2008/07/01 18:38
hi,
i have implemented the row level security in the same way, but when i use those reports in my dashboard
(using jasperserver pro 3.7.2)
i get the following error even after supplying all the default values:
The report is missing default values for atleast one mandatory parameter.
Please suggest the resolution
I have similar problem in getting the logged in organization/tenant id & using them in the SQL query.
I used a parameter & captured the organization/tenant id as below,
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInTenantId" class="java.lang.Integer" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{LoggedInUser}.getTenantId()]]></defaultValueExpression>
</parameter>
And printed this parameter in the main report - the proper value gets printed.
I have a input control whose SQL Query is as below,
select id, name from team_mst where TEAM_ID in (select team_id from access_mst where USER_ID = (Select USER_ID from user_mst where USER_NAME = '$P!{LoggedInUsername}' and ENTERPRISE_ID = $P!{ LoggedInTenantId} ) and ENTERPRISE_ID = $P!{ LoggedInTenantId} ) and VIR_TEAM_TYPE in (0,2) and DEACTIVATED = 0;
Before loading the main report the input control query itself fails with error as,
2012-07-24 17:00:37,881 ERROR errorPage_jsp,http-8080-1:487 - stack trace of exception that redirected to errorPage.jsp
net.sf.jasperreports.engine.JRRuntimeException: Parameter "LoggedInTenantId" does not exist.
at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.checkParameter(JRAbstractQueryExecuter.java:627)
atnet.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendParameterClauseChunk(JRAbstractQueryExecuter.java:347)
at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendQueryChunk(JRAbstractQueryExecuter.java:262)
at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.parseQuery(JRAbstractQueryExecuter.java:247)
The parameter have been defined. I'm not sure what is required here... & how can we resolve this...PLease anyone can show some pointer or help ...
I have attached the JRXML that I'm using..