Category: JasperReports Server
Access JasperReports Server using LDAP
We had a few issues getting to the bottom of how to add the LDAP functionality to JasperReports.
So here is how we did it:
Open ‘applicationContext-security.xml‘ which is located in:
/usr/local/glassfish3.1.2/glassfish/domains/domain1/autodeploy/jasperserver.war/WEB-INF
This is where it is if you’ve followed our earlier blog post, how to deploy JasperReports Server 4.0 on Glassfish 3.1/3.2.
If you didn’t then it’ll be located within your JasperReports directory somewhere.
Changes:
To help you find what needs to be changed, download my version of the applicationContext-security.xml file and use some file comparing software to note the changes from the original version.
There are changes on lines:
- 14: Unremarked the “ldapAuthenticationProvider” line.
- 78: Enter your LDAP host “ldap://blah.blah.co.uk:3286”.
- 83: Enter username/email address/account name here.
- 84: Enter the password to the above account on this line.
- 93: Enter the domain content ‘DC’ structure for your LDAP directory.
i.e.
DC=staff,DC=google,DC=co,DC=uk
Apache Directory Studio will help test the above configuration & help you find your LDAP host, ‘DC’ structure, using its search features.
Once you’ve made the changes to this file, start up Glassfish again and you will be able to login using your corporate account.
*Things to note, if you have a local account in JasperReports with the same name as the account that you’re trying to access from LDAP, access will only be granted using the local password that was set to this account – Not a password coming from your LDAP host.
Nested subreport within iReport & JasperReports Server
iReport, JasperReports Server & subreports what a nightmare
It has taken far too long to work out how to get them to play nicely, so I thought I’d sum it up since I couldn’t find any complete information on how to do it.
There is partial information which I based the following on here
- Connect iReports to JasperReports Server, so you can add content.
- In the ‘Repository Navigator’ Right click on your server name and select ‘Add’ / ‘Folder’.
- Right click on the new folder and select ‘Add’ / ‘JasperServer Report’.
- Enter an ID, Name & Description for your report, the ID needs underscores instead of spaces.
- Locate the main JRXML file, I’ve select one from my HDD.
- Locate the Data Source, I’ve select one that I’ve already created on the server, its easy to create.
- On clicking finish, a dialog box ‘JRXML validation’ might pop up, this is iReports checking your main report for any subreports, it then changes any subreports links in order to reference the file in the repository. Click continue to whatever it suggests.
- Note this above part has changed your master file to point to “repo:subreport.jrxml” rather than what it referenced before, which was “subreport.jasper”.
- Now if you open out your tree you’ll notice that you’ve got a ‘Main jrxml’ and your subreport in your ‘Resources’ folder.
- If you’ve multiple nested subreports, now is the time to upload them as well, because iReports has choosen to ignore any but the first one that it found.
- Its easier to do this on the JasperReports Server side of things, find the new report in your Repository right click and ‘Edit’ it, then click ‘Controls & Resources’ / ‘Add Resource’ now upload another ‘subreport.jrxml’ file, Click ‘Next’ and give it a Name & ID, Click ‘Next’ & ‘Submit’.
- Repeat above for any other subreports.
- Switch back to iReports and Refresh your ‘Repository Navigator’ tree, in order to show the files uploaded in JasperReports Server.
- In the ‘resources’ folder right click the subreport which is referenced first in the main jrxml file & click ‘properties’.
- Hightlight and Copy with Ctrl + C the ‘Parent Folder’ line which displays, then click ‘Cancel’. In my case I’m copying the line /XX/Report1/Report1_files/Report1-Tenure.jrxml
- Once copied, Right click & ‘Open in editor’ on the ‘Main jrxml’ report in your tree.
- Highlight the subreport on the main report and click on the three dots next to the ‘Subreport Expression’ property in the properties panel.
- Replace everything after “repo: with what is copied to your clipboard. in my case I end up with “repo:/XX/Report1/Report1_files/Report1-Tenure.jrxml”.
- Click Save icon, and Right click on the Main report and write the changes back to it by selecting ‘Replace with current document’.
- Link up your other Nested subreports in the same fashion, loading each one in turn to the editor, changing their ‘Subreport Expression’ property and write the information back to the correct resources jrxml file.
- Making sure that you add “repo: before the path, as that wont be there as the nested subreport wasnt found by iReports first time around.
- Now finally you can Right click the main report and ‘Run JasperServer Report’. Your report will also work on your server.
- Other things to note, remove any refernces to ‘$P{SUBREPORT_DIR} +’ and just reference the actual subreport, otherwise it wont be able to find the file.
JasperReports Server 4.0 on Glassfish 3.1 / 3.2.1
1. Download JasperReports Server installation package
2. Unzip this package and then following the steps in chapter 5 ‘Installing the War File Distribution’ within JasperReports-Server-CP-Install-Guide.pdf.
3. If you are running Mysql 5.5, then there is an issue posted here
Scroll down the page to ‘5. Known Issues‘
* 21953: The JasperReports Server repository database has issues under MySQL 5.5. There is a conflict with a new reserved word: MAXVALUE. Also, the storage engine needs to be specified as engine=Innodb (instead of type=Innodb).
In order to use the command ‘maxValue‘, you need to replace with all ‘maxValue‘ lines which exist without quotes to have quotes, so ‘`maxValue`‘ and change any ‘Type=Innodb‘ to ‘ENGINE=Innodb‘, within all the *.ddl files in /jasperreports-server-cp-4.0.0-bin/buildomatic/install_resources/sql/mysql/
4. Now edit the file default_master.properties, add the following settings for glassfish
appServerType = glassfish2
appServerDir =/Glassfish3.1/glassfish
5. edit /jasperreports-server-cp-4.0.0-bin/buildomatic/bin/validation.xml
add following to line 342
<equals arg1="${appServerType}" arg2="glassfish2" />
Before code looks like this:
<if>
<not>
<or>
<equals arg1="${appServerType}" arg2="skipAppServerCheck" />
<equals arg1="${appServerType}" arg2="tomcat5" />
<equals arg1="${appServerType}" arg2="tomcat6" />
<equals arg1="${appServerType}" arg2="jboss" />
</or>
</not>
After you code should look like this, part in bold is the change:
<if>
<not>
<or>
<equals arg1="${appServerType}" arg2="skipAppServerCheck" />
<equals arg1="${appServerType}" arg2="tomcat5" />
<equals arg1="${appServerType}" arg2="tomcat6" />
<equals arg1="${appServerType}" arg2="jboss" />
<equals arg1="${appServerType}" arg2="glassfish2" />
</or>
</not>
Without this the installation script will not continue. This is probably a bug within the system.
6. Manually install data-pooling and data resources required for glassfish,mysql database username and password should be set correctly in js-glassfish-ds.xml :
when glassfish is running, use asadmin add databaseresources.
/usr/local/glassfish3.1/glassfish/bin/asadmin add-resources /jasperreports-server-cp-4.0.0-bin/buildomatic/build_conf/default/js-glassfish-ds.xml
7. Comment out the glassfish datasource autoinstallation script.
Edit /jasperreports-server-cp-4.0.0-bin/buildomatic/bin/app-server.xml, comment out the glassfish2 datasources option
Code before the change:
…
<if> <equals arg1="${appServerType}" arg2="glassfish2" /> <then> <runasadmin> <arg value="start-domain"/> <arg value="domain1"/> </runasadmin> <runasadmin> <arg value="add-resources"/> <arg value="${currentConf}/js-glassfish-ds.xml"/> </runasadmin> <runasadmin failOnError="false"> <arg value="create-jvm-options"/> <arg value="${glassfishJvmOpt}"/> </runasadmin> <runasadmin> <arg value="stop-domain"/> <arg value="domain1"/> </runasadmin> </then> </if>
…
Code after the rem’d out statement around line 415, Marked in Bold:
…
<if> <equals arg1="${appServerType}" arg2="glassfish2" /> <then> <!-- <runasadmin> <arg value="start-domain"/> <arg value="domain1"/> </runasadmin> <runasadmin> <arg value="add-resources"/> <arg value="${currentConf}/js-glassfish-ds.xml"/> </runasadmin> <runasadmin failOnError="false"> <arg value="create-jvm-options"/> <arg value="${glassfishJvmOpt}"/> </runasadmin> <runasadmin> <arg value="stop-domain"/> <arg value="domain1"/> </runasadmin> --> </then> </if> ...
8. Stop glassfish and Run the autoinstall command js-install-ce.bat in Windows or js-install-ce.sh in Unix. If you are using MYSQL 5.5 should use minimal argument to avoid default full installation(Default installation comes with sample data and sample table, but will bring sql insert error in MYSQL 5.5 because the java source code still use MaxValue). Use help can get all the functions.
./js-install-ce.sh minimal
(unix)
js-install-ce.bat
(windows)
9. All the files should then be copy to /glassfish3.1/glassfish/domains/domain1/autodeploy/jasperserver.war/
10. Create a glassfish-web.xml file in /glassfish3.1/glassfish/domains/domain1/autodeploy/jasperserver.war/WEB-INF/
Paste the following information to this file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<resource-ref>
<res-ref-name>jdbc/dataSource</res-ref-name>
<jndi-name>jdbc/jasperserver</jndi-name>
</resource-ref>
<class-loader delegate="true"/>
</glassfish-web-app>
“<jndi-name>jdbc/jasperserver</jndi-name>” is required for glassfish3.1, otherwise the server will throw “javax.naming.NameNotFoundException: JasperServerDataBase not found” error message during deploying the web application. This is not necessary for glassfish3.0. The default setting in web.xml can be picked up by glassfish3.0.
11. Restart glassfish3.1. All should now work!