Commit 01aad3bb authored by Misagh Moayyed's avatar Misagh Moayyed
Browse files

updated docs

parent 57724b99
...@@ -4,9 +4,21 @@ title: CAS - JPA Service Registry ...@@ -4,9 +4,21 @@ title: CAS - JPA Service Registry
--- ---
# JPA Service Registry # JPA Service Registry
Stores registered service data in a database.The following schema shall be generated by CAS automatically Stores registered service data in a database.
for brand new deployments, and must be massaged
when doing CAS upgrades: Support is enabled by adding the following module into the Maven overlay:
{% highlight xml %}
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${cas.version}</version>
</dependency>
{% endhighlight %}
## Schema
The following schema shall be generated by CAS automatically
for brand new deployments, and must be massaged when doing CAS upgrades.
{% highlight sql %} {% highlight sql %}
...@@ -32,26 +44,33 @@ create table RegisteredServiceImpl ( ...@@ -32,26 +44,33 @@ create table RegisteredServiceImpl (
{% endhighlight %} {% endhighlight %}
## Configuration
The following configuration template may be applied to `deployerConfigContext.xml` to provide for persistent The following configuration template may be applied to `deployerConfigContext.xml` to provide for persistent
registered service storage. The configuration assumes a `dataSource` bean is defined in the context. registered service storage. The configuration assumes a `dataSource` bean is defined in the context.
{% highlight xml %} {% highlight xml %}
<tx:annotation-driven />
<bean id="factoryBean" <bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="dataSource"
p:dataSource-ref="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:jpaVendorAdapter-ref="jpaVendorAdapter" p:driverClass="${database.driverClass:org.hsqldb.jdbcDriver}"
p:packagesToScan-ref="packagesToScan"> p:jdbcUrl="${database.url:jdbc:hsqldb:mem:cas-ticket-registry}"
<property name="jpaProperties"> p:user="${database.user:sa}"
<props> p:password="${database.password:}"
<prop key="hibernate.dialect">${database.hibernate.dialect}</prop> p:initialPoolSize="${database.pool.minSize:6}"
<prop key="hibernate.hbm2ddl.auto">update</prop> p:minPoolSize="${database.pool.minSize:6}"
<prop key="hibernate.jdbc.batch_size">${database.hibernate.batchSize:10}</prop> p:maxPoolSize="${database.pool.maxSize:18}"
</props> p:maxIdleTimeExcessConnections="${database.pool.maxIdleTime:1000}"
</property> p:checkoutTimeout="${database.pool.maxWait:2000}"
</bean> p:acquireIncrement="${database.pool.acquireIncrement:16}"
p:acquireRetryAttempts="${database.pool.acquireRetryAttempts:5}"
p:acquireRetryDelay="${database.pool.acquireRetryDelay:2000}"
p:idleConnectionTestPeriod="${database.pool.idleConnectionTestPeriod:30}"
p:preferredTestQuery="${database.pool.connectionHealthQuery:select 1}"
/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<util:list id="packagesToScan"> <util:list id="packagesToScan">
<value>org.jasig.cas.services</value> <value>org.jasig.cas.services</value>
...@@ -59,121 +78,46 @@ registered service storage. The configuration assumes a `dataSource` bean is def ...@@ -59,121 +78,46 @@ registered service storage. The configuration assumes a `dataSource` bean is def
<value>org.jasig.cas.adaptors.jdbc</value> <value>org.jasig.cas.adaptors.jdbc</value>
</util:list> </util:list>
<bean id="jpaVendorAdapter" <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" id="jpaVendorAdapter"
p:generateDdl="true" p:generateDdl="true"
p:showSql="true" /> p:showSql="true" />
<bean id="serviceRegistryDao" <bean id="entityManagerFactory"
class="org.jasig.cas.services.JpaServiceRegistryDaoImpl" /> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
<bean id="transactionManager" p:jpaVendorAdapter-ref="jpaVendorAdapter"
class="org.springframework.orm.jpa.JpaTransactionManager" p:packagesToScan-ref="packagesToScan">
p:entityManagerFactory-ref="factoryBean" /> <property name="jpaProperties">
<props>
<!-- <prop key="hibernate.dialect">${database.dialect:org.hibernate.dialect.HSQLDialect}</prop>
| Injects EntityManager/Factory instances into beans with <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
| @PersistenceUnit and @PersistenceContext <prop key="hibernate.jdbc.batch_size">${database.batchSize:1}</prop>
--> </props>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> </property>
</bean>
<!--
Configuration via JNDI
-->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="java:comp/env/jdbc/cas-source" />
{% endhighlight %}
If you prefer a direct connection to the database, here's a sample configuration of the `dataSource`:
{% highlight xml %}
<bean
id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource"
p:driverClassName="org.hsqldb.jdbcDriver"
p:jdbcUrl-ref="database"
p:password=""
p:username="sa" />
{% endhighlight %}
The data source will need to be modified for your particular database
(i.e. Oracle, MySQL, etc.), but the name `dataSource` should be preserved. Here is a MYSQL sample:
{% highlight xml %}
<bean
id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
p:password=""
p:username="sa" />
{% endhighlight %}
You will also need to change the property `hibernate.dialect` in adequacy with your
database in `cas.properties` and `deployerConfigContext.xml`.
For example, for MYSQL the setting would be:
In `cas.properties`:
{% highlight bash %}
database.hibernate.dialect=org.hibernate.dialect.MySQLDialect
{% endhighlight %}
In `deployerConfigContext.xml`: <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
{% highlight xml %} <tx:advice id="txAdvice" transaction-manager="transactionManager">
<prop key="hibernate.dialect">${database.hibernate.dialect}</prop> <tx:attributes>
{% endhighlight %}
You will also need to ensure that the xml configuration file contains the `tx` namespace: <tx:method name="delete*" read-only="false"/>
<tx:method name="save*" read-only="false"/>
<tx:method name="update*" read-only="false"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
{% highlight xml %} <aop:config>
<beans xmlns="http://www.springframework.org/schema/beans" <aop:pointcut id="servicesManagerOperations" expression="execution(* org.jasig.cas.services.JpaServiceRegistryDaoImpl.*(..))"/>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <aop:advisor advice-ref="txAdvice" pointcut-ref="servicesManagerOperations"/>
xmlns:tx="http://www.springframework.org/schema/tx" </aop:config>
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation=" <bean id="serviceRegistryDao"
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> class="org.jasig.cas.services.JpaServiceRegistryDaoImpl" />
{% endhighlight %} {% endhighlight %}
Finally, when adding a new source new dependencies may be required on Hibernate, `commons-dbcp2`. add props and config for xml
Be sure to add those to your `pom.xml`. Below is a sample configuration for MYSQL. Be sure to \ No newline at end of file
adjust the version elements for the appropriate version number.
{% highlight xml %}
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${cas.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons.dbcp.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.entitymgmr.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
{% endhighlight %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment