Adding Multiple Login Pages in Jasperserver - jasperserver

I want to add multiple login pages to single jasperserver.
i have customize the code and added login1.jsp and login2.jsp in moudles/login/ folder.
also i have added following code in \jasperserver-war\src\main\webapp\WEB-INF\jasperserver-servlet.xml
bean id="urlHandlerMapping" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="/fileview/**">jsFileViewContr</prop>
<!-- anonymous pages -->
<prop key="/login1.html">jsCommContr</prop>
<prop key="/login.html">jsCommContr</prop>
<prop key="/logout.html">jsCommContr</prop>
and
<!-- js mac method name resolver -->
<bean id="paramResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/login1.html">entry</prop>
<prop key="/home.html">homePage</prop>
<prop key="/login.html">login</prop>
I have also added following code to JSCommonController.java in com.jaspersoft.jasperserver.war.control package.
public ModelAndView login1(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/login");
}
public ModelAndView login2(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/login");
}
i deployed server after rebuilting it.
but when i enter
localhost:8080/jasperserver/login1.html
it takes me to
localhost:8080/jasperserver/login.html
and after login on this page it takes me to
localhost:8080/jasperserver/login1.html
but when i try to login on this page login event occures succesfully but it keeps me on same page.
Anybody know how to add multiple login pages in jasper server??
Please help me out.
Thanks.

I found the way for it :) and answer is as follows:
Procedure to add new login page:
Create a new login jsp page. Example entry.jsp
Keep it in jasperserver-war/src/main/webapp/WEB-INF/jsp/modules/login/
Add entry of property of page in urlHandlerMapping bean section in jasper-servlet.xml in anonymous pages section as follows:
<bean id="urlHandlerMapping" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="/fileview/**">jsFileViewContr</prop>
<!-- anonymous pages -->
<prop key="/entry.html">jsCommContr</prop>
<prop key="/login.html">jsCommContr</prop>
<prop key="/logout.html">jsCommContr</prop>
Also add following code in same file in paramResolver bean section.
<bean id="paramResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/entry.html">entry</prop>
<prop key="/home.html">homePage</prop>
<prop key="/login.html">login</prop>
<prop key="/entry.html">jsCommContr</prop>
This will call controller servlet which is mapped as
<bean id="jsCommContr" class="com.jaspersoft.jasperserver.war.control.JSCommonController">
Add following code in com.jaspersoft.jasperserver.war.control.JSCommonController.java
public ModelAndView entry(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/entry");
}
This will load entry.jsp from folder modules/login/ folder for url
localhost:8080/jasperserver/entry.html
We also have to add this page entry to the filterInvocationInterceptor bean in applicationContext-security-web.xml
Modify applicationContext-security.xml as follows:
<bean id="filterInvocationInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager"/>
</property>
<property name="accessDecisionManager">
<ref bean="httpRequestAccessDecisionManager"/>
</property>
<!-- <property name="runAsManager"><ref bean="runAsManager"/></property> -->
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/entry.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR
/login.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR
/logout.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR,IS_AUTHENTICATED_FULLY
Build the war file again and redeploy it on server.
Now you can use
localhost:8080/jasperserver/entry.html
as login page.
To change UI of login page customize entry.jsp and pageSpecific.css.
Locations of files:
entry.jsp :- /jasperserver/jasperserver-war/src/main/webapp/WEB-INF/jsp/modules/login/entry.jsp
jasperserver-servlet.xml :- /jasperserver/jasperserver-war/src/main/webapp/WEB-INF/jasperserver-servlet.xml
JSCommonController.java :-
Physical path: /jasperserver/jasperserver-war-jar/src/main/java/com/jaspersoft/jasperserver/war/control/JSCommonController.java
Package Path: com.jaspersoft.jasperserver.war.control/ JSCommonController
applicationContext-security-web.xml :- /jasperserver/jasperserver-war/shared-config/applicationContext-security-web.xml

Related

How to use JBossTS (Narayana) with Spring Data JPA

I am investigating the use of a JTA transaction manager with Spring Data JPA. I have successfully configured Atomikos and Bitronix and am trying to configure JBossTS (Arjuna/Narayana).
I followed the instructions for configuring JBossTS for Spring and came up with the following configuration:
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="jpaProperties">
<props>
<prop key="hibernate.format_sql">true"</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.H2Dialect"/>
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jtaDataSource">
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="connectionProperties">
<props>
<prop key="dynamicClass">com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass</prop>
<prop key="password"></prop>
<prop key="user">sa</prop>
</props>
</property>
<property name="driverClassName" value="com.arjuna.ats.jdbc.TransactionalDriver"/>
<property name="url" value="jdbc:arjuna:database.properties"/>
</bean>
</property>
<property name="packagesToScan" value="org.example.domain"/>
</bean>
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager">
<bean class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/>
</property>
<property name="userTransaction">
<bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction"/>
</property>
</bean>
<transaction:annotation-driven/>
However, attempting to run the application throws the following error:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: java.sql.SQLException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:361)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.<init>(IndirectRecoverableConnection.java:109)
at com.arjuna.ats.internal.jdbc.ConnectionImple.<init>(ConnectionImple.java:107)
at com.arjuna.ats.internal.jdbc.ConnectionManager.create(ConnectionManager.java:110)
at com.arjuna.ats.jdbc.TransactionalDriver.connect(TransactionalDriver.java:87)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.resource.transaction.backend.jta.internal.DdlTransactionIsolatorJtaImpl.prepare(DdlTransactionIsolatorJtaImpl.java:49)
... 60 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:346)
There does not seem to be any documentation on whether JNDI is mandatory to run JBossTS and if yes, how it can be configured in a standalone application that does not use a JavaEE container.
A sample application is available on Github in case the full configuration and source code is required. The problem can be seen by running Maven tests as mvn test -D"spring.profiles.active=jbossts".
Replace the <prop key="dynamicClass"> with <prop key="DYNAMIC_CLASS">
Specify the properties file with target/classes
Use the H2 file database instead of the memory
For more information you can see narayana.io

Pageable support for Spring Data JPA having jndi look up for entityManagerFactory

I was following http://terasolunaorg.github.io/guideline/1.0.x/en/ArchitectureInDetail/Pagination.html to implement Pagination support for my MVC application
When I try to start the JBoss Server,
nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.repo.MyRepository.searchEntitySC(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.util.Date,java.lang.String,java.util.Date,java.lang.String,java.lang.String,java.lang.String,org.springframework.data.domain.Pageable)!
Reason: Your persistence provider does not support extracting the JPQL query from a named query thus you can't use Pageable inside your query method. Make sure you have a JpaDialect configured at your EntityManagerFactoryBean as this affects discovering the concrete persistence provider.
I tried to follow, http://forum.spring.io/forum/spring-projects/data/99613-you-cannot-use-pageable-as-method-parameter-if-your-persistence-provider-cannot-extra
But I don't know how to apply the suggested configuration for entityManagerFactory
as my jpa-config.xml contains
<jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/pu/pc" />
Any other better suggestion is more than welcome!
Environment:
JBoss Enterprise Application Platform - Version 6.2.0.GA
spring-data-jpa-1.4.3.RELEASE.jar
hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar
standalone.xml contains:
<datasource jndi-name="java:jboss/datasources/pc" pool-name="pcdatapool" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#localhost:1521:mysid</connection-url>
<driver>oracle</driver>
<security>
<user-name>XXX</user-name>
<password>xxx</password>
</security>
</datasource>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="pcem">
<jta-data-source>java:jboss/datasources/pc</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<class>xxx.YYYYY</class>
...
<class>yyyy.AAAAAAAAAA</class>
<properties>
<property name="hibernate.jdbc.batch_size" value="50" />
<property name="hibernate.default_batch_fetch_size" value="50" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<!-- Use log category 'org.hibernate.SQL' to level 'debug' to output SQL from hibernate -->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false"/>
<!-- Use generate statistics this will help query performance tunning -->
<property name="hibernate.generate_statistics" value="false"/>
</properties>
</persistence-unit>
In the standalone.xml file remove the prefix java:. Then in persistence config file reference the jndi name you have in your standalone.xml but with the prefix. So:
persistence.xml
<jee:jndi-lookup id="myDatasource" jndi-name="java:jboss/datasources/pc" />
<mapping-file>META-INF/announcement-queries.hbm.xml</mapping-file>
jboss.datasource.xml
<datasource jndi-name="jboss/datasources/pc" pool-name="pcdatapool" enabled="true" use-ccm="false">
...
</datasource>
applicationContext.xml (Spring)
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myDatasource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="${hibernate.show_sql}" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.use_sql_comments">${hibernate.format_sql}</prop>
<prop key="hibernate.connection.isolation">1</prop>
<prop key="hibernate.configurationClass">org.hibernate.cfg.AnnotationConfiguration</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.default_batch_fetch_size">100</prop>
<prop key="hibernate.id.new_generator_mappings">true</prop>
</props>
</property>
<property name="packagesToScan" value="com.mypacjage" />
</bean>

Password Encryption in Hikaricp

I am using HikariCP in a spring project.
Right now, I defined a connection like this
<bean id="hikariConfigLegacyReasonCode" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="HikariCPReasonCodePool" />
<property name="connectionTestQuery" value="SELECT 1" />
<property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<property name="registerMbeans" value="true"/>
<property name="maximumPoolSize" value="15"/>
<property name="idleTimeout" value="60000"/>
<property name="connectionTimeout" value="5000" ></property>
<property name="dataSourceProperties">
<props>
<prop key="url">jdbc:mysql://${LegacyReasonCodeIp}</prop>
<prop key="user">${LegacyReasonCodeUsername}</prop>
<prop key="password">${LegacyReasonCodePassword}</prop>
<prop key="cachePrepStmts" >true</prop>
<prop key="prepStmtCacheSize" >250</prop>
<prop key="prepStmtCacheSqlLimit" >2048</prop>
<prop key="useServerPrepStmts" >true</prop>
</props>
</property>
Here, Server name , username and password will be loaded from a property file. Is there any way to store the DB password in the property file in encrypted manner ?
Try the jasypt project. It includes a number of integrations for Spring, including implementations of:
PropertyPlaceholderConfigurer
PropertyOverrideConfigurer
PreferencesPlaceholderConfigurer
http://www.jasypt.org/spring31.html

Heroku's Spring MVC Hibernate template application not connecting to DB

I'm trying to get the sample application running, but getting the following error when it tries to connect to the db:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
I haven't changed the applicationContext.xml, and the particular portion is:
<beans profile="default">
<jdbc:embedded-database id="dataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
</beans>
<beans profile="prod">
<bean class="java.net.URI" id="dbUrl">
<constructor-arg value="#{systemEnvironment['DATABASE_URL']}"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="#{ 'jdbc:postgresql://' + #dbUrl.getHost() + #dbUrl.getPath() }"/>
<property name="username" value="#{ #dbUrl.getUserInfo().split(':')[0] }"/>
<property name="password" value="#{ #dbUrl.getUserInfo().split(':')[1] }"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- change this to 'verify' before running as a production app -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
</beans>
I am able to connect to the db using pgAdmin III from my laptop.
Also, I am learning Spring, and I see some beans are wrapped in the profile "prod", but I cannot tell anywhere in code or web.xml that uses a particular profile.
Does the application server (Heroku?) need to start in a particular mode/profile, could that be why the db connection is not opening?
I'm learning Heroku as well.
Are you trying to run application on local machine? To be able to run this sample project on your local machine, you need to have database created. It's not described in the tutorial but if you try to use sample DATABASE_URL (postgres://scott:tiger#localhost/myapp) you need to create user scott with password tiger and create database myapp and grant scott required privileges. What I did, I've created sampledb database with existing postgres user, since it's database admin, I don't need to bother with grants and just changed url to
export DATABASE_URL=postgres://postrges:<password>#localhost/sampledb

Email not sent in Jasper Report Scheduling

I want to schedule my jasper report so that at a particular time, it will send the report to the mentioned id. I'm using Jasper Server 4.5.0 and I have scheduled a sample report to be sent to my gmail id. However, it's not been sent to the mail id and it doesn't show any Last Ran time too.
I found it hard to setup GMail as my email server. So once I got it working I posted the details in this article.
In the spirit of keeping StackOverflow answers self-contained, here are the key settings. js.quartz.properties:
report.scheduler.web.deployment.uri=http://localhost/jasperserver
report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=me#gmail.com
report.scheduler.mail.sender.password=mypassword
report.scheduler.mail.sender.from=me#gmail.com
report.scheduler.mail.sender.protocol=smtp
report.scheduler.mail.sender.port=587
applicationContext-report-scheduling.xml:
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop> <!--as indicated in JasperReports-Server-Install-Guide.pdf)-->
<prop key="mail.smtp.starttls.enable">true</prop> <!--NOT indicated in JasperReports-Server-Install-Guide.pdf-->
</props>
</property>
One observation,
If you´re going to use an email from Microsoft Exchange, you need on more line in the applicationContext-report-scheduling.xml
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.starttls.required">true</prop>
</props>
in my case works with this
first edit this arquive
/opt/jasperreports-server-cp-5.1.0/apache-tomcat/webapps/jasperserver/WEB-INF/js.quartz.properties
report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=username#gmail.com
report.scheduler.mail.sender.password=your_password
report.scheduler.mail.sender.from=username#gmail.com
report.scheduler.mail.sender.protocol=smtps
report.scheduler.mail.sender.port=465
second edit this
opt/jasperreports-server-cp-5.1.0/apache-tomcat/webapps/jasperserver/WEB-INF/applicationContext-report-scheduling.xml
<bean id=”reportSchedulerMailSender”>
<property name=”host” value=”${report.scheduler.mail.sender.host}”/>
<property name=”username” value=”${report.scheduler.mail.sender.username}”/>
<property name=”password” value=”${report.scheduler.mail.sender.password}”/>
<property name=”protocol” value=”${report.scheduler.mail.sender.protocol}”/>
<property name=”port” value=”${report.scheduler.mail.sender.port}”/>
<property name=”javaMailProperties”>
<props>
**<prop key=”mail.smtps.auth”>true</prop>
<prop key=”mail.smtps.starttls.enable”>true</prop>**
</props>
</property>
</bean>