JPA Session Storage
The JPA-based Session Storage provides long term storage for sessions (i.e. if you allowed people to choose "Remember This Login for 2 months") as well as the ability to share data across nodes. The JPA-backed session storage mechanism is slightly different than the other storage mechanisms. Because of the way JPA mappings work, once you enable JPA, you've enabled ALL protocols that CAS supports, whereas the other mechanisms allow you to choose which ones to support. Its not a significant issue, but one you should be aware of.
To enable the JPA session storage, you need to add the dependency to your web applications's pom.xml before building it with Maven.
The dependency is as follows:
<dependency> <groupId>org.jasig.cas.server</groupId> <artifactId>cas-server-sessionstorage-jpa</artifactId> <version>${cas.version}</version> <scope>runtime</scope> <type>jar</type> </dependency>
Note: By default the JPA session storage includes a JPA provider (Hibernate) and a DataSource (c3p0). If you would like to use an alternative, you can exclude those using the standard Maven2 mechanism:
<dependency> <groupId>org.jasig.cas.server</groupId> <artifactId>cas-server-sessionstorage-jpa</artifactId> <version>${cas.version}</version> <scope>runtime</scope> <type>jar</type> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </exclusion> <exclusion> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> </exclusion> </exclusions> </dependency>
Finally, the JPA mechanism requires some configuration. A configuration file, such as the one below should be placed in the WEB-INF/spring directory:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource"> <bean class="com.mchange.v2.c3p0.ComboPooledDataSource" p:jdbcUrl="jdbc:mysql://localhost/cas" p:user="root" p:driverClass="com.mysql.jdbc.Driver"> </bean> </property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:generateDdl="true" p:showSql="true"/> </property> <property name="jpaPropertyMap"> <map> <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> <entry key="hibernate.hbm2ddl.auto" value="update"/> </map> </property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" no-rollback-for="org.jasig.cas.server.session.InvalidSessionException" isolation="DEFAULT" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="centralAuthenticationServiceOperation" expression="execution(* org.jasig.cas.server.CentralAuthenticationService.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="centralAuthenticationServiceOperation"/> </aop:config> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="myEmf" /> </bean> </beans>
NOTE: This is an example configuration file. Its perfectly reasonable to externalize the DataSource into JNDI and reference it (see Spring reference documentation). You'll also need to replace any of the MySQL references (i.e. hibernate.dialect) with the references specific to your database.