Embedded HSQLDB persist data to a file - hsqldb

I am creating a spring based web application that uses embedded hsqldb.
My spring config is pretty simple:
<jdbc:embedded-database id="dataSource" type="HSQL" >
<jdbc:script location="classpath:scripts/create-table-if-not-exists" />
</jdbc:embedded-database>
But with this config all data is stored in memory. Here is the data source url that is created
jdbc:hsqldb:mem:dataSource
I need to persist data to a file. So that I can use it again after server restart.

This solution worked for me
<bean class="org.apache.commons.dbcp2.BasicDataSource" id="dataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:#{systemProperties['user.home']}/db/data" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:scripts/create-table-if-not-exists" />
</jdbc:initialize-database>

Related

ActiveMQ Jetty with 2 authentications methods (LDAP + local)

I currently having ActiveMQ jetty web server configured by using LDAP authentication for the users of the web console (admins), but I'm struggling to have at the same time HashLoginService for Rest API purpose...
I there a way to have the two authentication methods working on ActiveMQ Jetty?
Here my working config with LDAP:
<bean id="ldapLoginService" class="org.eclipse.jetty.jaas.JAASLoginService">
<property name="name" value="LDAP realm" />
<property name="loginModuleName" value="LDAPLogin" />
<property name="roleClassNames" value="org.apache.activemq.jaas.GroupPrincipal" />
<property name="identityService" ref="identityService" />
</bean>
<bean id="identityService" class="org.eclipse.jetty.security.DefaultIdentityService"/>
<bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
<property name="name" value="BASIC" />
<property name="roles" value="admin_grp" />
<property name="authenticate" value="true" />
</bean>
<bean id="adminSecurityConstraint" class="org.eclipse.jetty.util.security.Constraint">
<property name="name" value="BASIC" />
<property name="roles" value="admin_grp" />
<property name="authenticate" value="true" />
</bean>
<bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="securityConstraint" />
<property name="pathSpec" value="/api/*,/admin/*,*.jsp" />
</bean>
<bean id="adminSecurityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="adminSecurityConstraint" />
<property name="pathSpec" value="*.action" />
</bean>
<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<property name="loginService" ref="ldapLoginService" />
<property name="realmName" value="LdapRealm" />
<property name="identityService" ref="identityService" />
<property name="authenticator">
<bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator" />
</property>
<property name="constraintMappings">
<list>
<ref bean="adminSecurityConstraintMapping" />
<ref bean="securityConstraintMapping" />
</list>
</property>
<property name="handler" ref="secHandlerCollection" />
</bean>
and the ldap config:
LDAPLogin {
org.apache.activemq.jaas.LDAPLoginModule required
debug="false"
initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory
connectionURL="{{ ldap_connect_url }}"
connectionUsername="{{ bind_dn }}"
connectionPassword="{{ bind_pw }}"
connectionProtocol=""
authentication=simple
userBase="{{ base_dn }}"
userSearchMatching="{{ ldap_user_search_matching }}"
userSearchSubtree="true"
roleBase="{{ ldap_role_base }}"
roleName="cn"
roleSearchMatching="{{ ldap_role_search_matching }}"
roleSearchSubtree=false
;
};
Why don't you add the PropertyFileLoginModule to your JAAS config file? It is similar to the HashLoginService, but works with JAAS. You would have to change your JAAS config to make the LDAPLoginModule sufficient rather than required, and make the PropertyFileLoginModule also sufficient. That way, if either of the login modules can succeed in authenticating the user. Reading more about the definitions of required/requisite/sufficient/optional may be helpful.
Jetty 9.x JAAS docs do not mention the ability to run multiple authentication sources, but you could implement your own custom JAAS LoginModule to support it.
If you are looking for something out-of-the-box, I know many people run ActiveMQ inside another runtime container (such as Apache Karaf) that supports single JAAS realm with multiple backends.

How to config activiti.org to work with IBM Domino LDAP groups

I work on integration IBM Domino with activiti.org workflow engine. I need to connect Activiti with Domino LDAP in order to retrive users and groups.
I already can log in with my Domino credentials but I'm not able to resolve user groups. My user is a member of ACTIVITI_ADMINS domino group but he doesn't see activiti-explorer administration menu (the one that default kermit user see). I've made the following modifications in Activiti xml config files. What should I add/rewrite in my config files in order to resolve user groups?
activiti-custom-context.xml
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!--...-->
<property name="configurators">
<list>
<bean class="org.activiti.ldap.LDAPConfigurator">
<!-- Server connection params -->
<property name="server" value="ldap://myDominoLdapServer" />
<property name="port" value="389" />
<property name="user" value="cn=User Ldap, ou=myUnit1, ou=myUnit2, o=myCompany" />
<property name="password" value="myPassword" />
<!-- Query params -->
<property name="baseDn" value="o=myCompany" />
<property name="queryUserByUserId" value="(&(objectClass=inetOrgPerson)(displayname={0}))" />
<property name="queryUserByFullNameLike" value="(&(objectClass=inetOrgPerson)(|({0}=*{1}*)({2}=*{3}*)))" />
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
<!-- Attribute config -->
<property name="userIdAttribute" value="displayname" />
<property name="userFirstNameAttribute" value="GivenName" />
<property name="userLastNameAttribute" value="sn" />
<property name="userEmailAttribute" value="mail" />
<property name="groupIdAttribute" value="cn" />
<property name="groupNameAttribute" value="cn" />
</bean>
</list>
</property>
</bean>
activiti-ui-context.xml
<bean name="explorerApp" class="org.activiti.explorer.ExplorerApp" scope="session">
<property name="environment" value="${activiti.ui.environment}" />
<property name="useJavascriptDiagram" value="${activiti.ui.jsdiagram}" />
<property name="i18nManager" ref="i18nManager" />
<property name="viewManager" ref="viewManager" />
<property name="notificationManager" ref="notificationManager" />
<property name="attachmentRendererManager" ref="attachmentRendererManager" />
<property name="formPropertyRendererManager" ref="formPropertyRendererManager" />
<property name="variableRendererManager" ref="variableRendererManager" />
<property name="applicationMainWindow" ref="mainWindow" />
<property name="componentFactories" ref="componentFactories" />
<property name="workflowDefinitionConversionFactory" ref="workflowDefinitionConversionFactory" />
<property name="loginHandler" ref="activitiLoginHandler" />
<property name="simpleWorkflowJsonConverter" ref="simpleWorkflowJsonConverter" />
<property name="adminGroups">
<list>
<value>ACTIVITI_ADMINS</value>
</list>
</property>
<property name="userGroups">
<list>
<value>user</value>
</list>
</property>
</bean>
Your configuration looks right so the problem must have something to do with the LDAP query used to retrieved the groups for the user:
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
Is this query returning the ACTIVITI_ADMIN group?
Well, I've found that the baseDN entry was the reason of my problem. I set empty value and Activiti is resolving my group now. The activiti-custom-context.xml file contains the following code:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!--...-->
<property name="configurators">
<list>
<bean class="org.activiti.ldap.LDAPConfigurator">
<!-- Server connection params -->
<property name="server" value="ldap://myDominoLdapServer" />
<property name="port" value="389" />
<property name="user" value="cn=User Ldap, ou=myUnit1, ou=myUnit2, o=myCompany" />
<property name="password" value="myPassword" />
<!-- Query params -->
<!--MY CHANGE START-->
<property name="baseDn" value="" />
<!--MY CHANGE END-->
<property name="queryUserByUserId" value="(&(objectClass=inetOrgPerson)(displayname={0}))" />
<property name="queryUserByFullNameLike" value="(&(objectClass=inetOrgPerson)(|({0}=*{1}*)({2}=*{3}*)))" />
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
<!-- Attribute config -->
<property name="userIdAttribute" value="displayname" />
<property name="userFirstNameAttribute" value="GivenName" />
<property name="userLastNameAttribute" value="sn" />
<property name="userEmailAttribute" value="mail" />
<property name="groupIdAttribute" value="cn" />
<property name="groupNameAttribute" value="cn" />
</bean>
</list>
</property>
</bean>

Excess of Redis connections created and idle connections not used

Following is my jedis pool configuration:
Excess of connections are created as the existing ones are not used. What is the purpose of pool if every function creates new connection.
Please let me know if anybody can provide solution to this.
`<bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="whenExhaustedAction" value="2" />
<property name="maxIdle" value="40" />
<property name="minIdle" value="30" />
<property name="softMinEvictableIdleTimeMillis" value="60000" />
<property name="timeBetweenEvictionRunsMillis" value="600000" />
</bean>
<bean id="jedisFactoryPrimary"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig"><ref bean="jedisConfig"/></property>
<property name="hostName" value="${redis-db.hostname}"></property>
<property name="password" value="${redis-db.password}"></property>
<property name="port" value="${redis-db.port}"></property>
</bean>`

get error :cannot commit a resource enlisted in a global transaction in activemq

Could you please help to solve the problem with XA transactions on Activemq and Oracle and Bitronix.
I have a activemq and using camel.xml embeded in for routing message from one queue to oracle db.
this is the content of camel.xml file in conf folder of standalone Activemq.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="partnerToDB">
<from uri="activemqXa:example.A" />
<transacted ref="PROPAGATION_REQUIRED"/>
<transform>
<simple>insert into tbl_1(body,type) values('${in.body}','P') </simple>
</transform>
<to uri="jdbc:dataSource" />
</route>
</camelContext>
<!-- TX configuration -->
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="transactionManager"/>
<property name="userTransaction" ref="transactionManager" />
</bean>
<bean id="btmConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
<property name="serverId" value="spring-btm" />
</bean>
<bean id="transactionManager" factory-method="getTransactionManager" class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig" destroy-method="shutdown" />
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="jtaTransactionManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
<!-- JMS configuration -->
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="transactionManager" />
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory" />
<property name="resourceName" value="activemq.default,java/testDS1" />
</bean>
<bean id="pooledJmsXaConnectionFactory" class="bitronix.tm.resource.jms.PoolingConnectionFactory" init-method="init" destroy-method="close" >
<property name="className" value="org.apache.activemq.ActiveMQXAConnectionFactory" />
<property name="uniqueName" value="activemq" />
<property name="maxPoolSize" value="8" />
<property name="driverProperties">
<props>
<prop key="brokerURL">tcp://172.16.9.17:61617</prop>
</props>
</property>
</bean>
<bean id="activemqXa" class="org.apache.activemq.camel.component.ActiveMQComponent">
<!-- because of https://issues.apache.org/jira/browse/AMQ-3251, we cannot use the XaPooledConnectionFactory in AMQ 5.5.1 -->
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory"/>
<property name="transacted" value="false"/>
<property name="transactionManager" ref="jtaTransactionManager"/>
</bean>
<!-- JDBC configuration -->
<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
init-method="init" destroy-method="close">
<property name="className" value="bitronix.tm.resource.jdbc.lrc.LrcXADataSource" />
<property name="uniqueName" value="java/testDS1" />
<property name="maxPoolSize" value="5" />
<property name="minPoolSize" value="0" />
<property name="allowLocalTransactions" value="false" />
<property name="testQuery" value="SELECT 1 FROM DUAL" />
<property name="driverProperties">
<props>
<prop key="user">test</prop>
<prop key="password">test</prop>
<prop key="url">jdbc:oracle:thin:#db1sh:1521/org.amin.org</prop>
<prop key="driverClassName">oracle.jdbc.OracleDriver</prop>
</props>
</property>
</bean>
when I run Activemq and send a message to example.A queue, nothing is inserted on db and message is dequeued from queue, I get this error in activemq log:
[org.apache.camel.RuntimeCamelException - java.sql.SQLException: cannot commit a resource
enlisted in a global transaction]
Also I have run these SQL scripts for Oracle DataBase:
$ORACLE_HOME/javavm/install/initxa.sql
$ORACLE_HOME/javavm/install/initjvm.sql
and the following grant statments:
grant select on pending_trans$ to public;
grant select on dba_2pc_pending to public;
grant select on dba_pending_transactions to public;
grant execute on dbms_system to <user>;
Any ideas/solutions are welcome!
Thanks
Looking at the first lines in the camel jdbc component docs I find this information box
This component can not be used as a Transactional Client. If you need transaction support in your route, you should use the SQL component instead.

Oracle Weblogic JNDI Datasource set Default Auto Commit

In my J2ee web application I am using a datasource accessed stored in the weblogic server and accessed through jndi. In normal datasource bean declaration there is a property defaultAutoCommit which can be set to false. Is there a similar property or is there a way to set something like this when using datasource in JNDI. Because currently my rollback won't work using JNDI. But when I normally define my datasource in the application context with defaultAutoCommit set to false my rollback works.
JNDI Data source:
<bean id="TerasolunaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="dataSource" />
</bean>
Normal Data Source defined in application context
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:#192.168.178.82:1521:anicom" />
<property name="username" value="jay" />
<property name="password" value="jay" />
<property name="initialSize" value="5" />
<property name="maxActive" value="10" />
<property name="defaultAutoCommit" value="false" />
</bean
You need a JTA transaction manager and transaction logic. It's not just auto commit.