Jump to content
We've recently updated our Privacy Statement, available here ×

Solution - LoggedInUser and Input Control


bpienig

Recommended Posts

Hello All,

 

So far JasperReports has been an excellent tool.

 

I'm interested in finding out if it is possible to use LoggedInUser within a Single Select Query input control.

 

Please see the attached image, this may give you an idea of what I'm trying to accomplish.

 

Thanks in advance,

Ben

Post edited by: bpienig, at: 2007/10/01 15:34

Link to comment
Share on other sites

  • Replies 17
  • Created
  • Last Reply

Top Posters In This Topic

Hi all,

 

I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file.

 

Let me post my approach for those interested...

 

Step 1: Create a non-visible inputControl (SingleValue - string) called USER.

Step 2: Add reference to acegi taglib at the beginning of DefaultParametersForm.jsp file.

<%@ taglib uri="http://acegisecurity.org/authz" prefix="authz"%>

Step 3: Search this file for this code...

 

<c:if test="${!control.visible}">

<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>

</c:if>

 

...and substitute it with this fragment...

 

<c:if test="${!control.visible}">

<c:choose>

<c:when test="${control.name=='USER'}">

<input type="hidden" name="${inputName}" value="<authz:authentication operation="username"/>"/>

</c:when>

<c:otherwise>

<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>

</c:otherwise>

</c:choose>

</c:if>

 

 

I hope this is useful for those in a hurry...

It would be great to have an official implementation for this feature in the future.

 

Best regards,

 

P.S.- I'll be out of office for two weeks. Read you in September.

Link to comment
Share on other sites

I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file.

 

Hey sergio,

 

That's not quite what I was looking for, I'm looking at being able to use the LoggedInUser in the SQL of the multiple-input control.

 

If you want to use the LoggedInUser in the report, just take a look at the SalesByMonth sample report. It uses the LoggedInUser as a parameter.

 

Thanks,

Ben

Link to comment
Share on other sites

  • 1 month later...

I've got a fix for this problem.

 

It involved editing the EngineServiceImpl.java file.

 

 

Previous Code

 

Code:
	public OrderedMap executeQuery(ExecutionContext context, 
ResourceReference queryReference, String keyColumn, String[] resultColumns,
ResourceReference defaultDataSourceReference) {
Query query = (Query) getFinalResource(context, queryReference);

ResourceReference dataSourceReference = query.getDataSource();
if (dataSourceReference == null) {
dataSourceReference = defaultDataSourceReference;
}

 

 

Edited Code

 

Code:
[code] public OrderedMap executeQuery(ExecutionContext context,
ResourceReference queryReference, String keyColumn, String[] resultColumns,
ResourceReference defaultDataSourceReference) {
Query query = (Query) getFinalResource(context, queryReference);

String userName = getSecurityContextProvider().getContextUser().getUsername();
String queryStr = query.getSql().replace("$P{LoggedInUsername}",userName);
query.setSql( queryStr );

ResourceReference dataSourceReference = query.getDataSource();
if (dataSourceReference == null) {
dataSourceReference = defaultDataSourceReference;
}

 

If you add $P{LoggedInUsername} to an input control query, it will replace it with the current logged in user name.

 

It's a hack, but at least it works for now.

Post edited by: bpienig, at: 2007/09/27 22:42

Link to comment
Share on other sites

  • 1 month later...
  • 10 months later...
  • 4 months later...
  • 6 months later...

 I wonder if I someone could give me the resulting compiled .jar file and then I could just drop it into my server lib files - I'm having no luck whatsoever in building jasperserver after making the changes to the java file. Maven2 , POMs, repos, getting that all to work will take (me) weeks.

Thanks in advance. 

And, why not just add it to the next release - the workaround seems quite useful and its only a few lines. Why has this request been sitting there so long (since 3.1?)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...