JPA-Service-Management.md 5.51 KB
Newer Older
Misagh Moayyed's avatar
Misagh Moayyed committed
1
2
---
layout: default
Misagh Moayyed's avatar
Misagh Moayyed committed
3
title: CAS - JPA Service Registry 
Misagh Moayyed's avatar
Misagh Moayyed committed
4
5
---

Misagh Moayyed's avatar
Misagh Moayyed committed
6
7
8
# JPA Service Registry 
Stores registered service data in a database.The following schema shall be generated by CAS automatically 
for brand new deployments, and must be massaged
Misagh Moayyed's avatar
Misagh Moayyed committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
when doing CAS upgrades:

{% highlight sql %}

create table RegisteredServiceImpl (
    expression_type VARCHAR(15) DEFAULT 'ant' not null,
    id bigint generated by default as identity (start with 1),
    access_strategy blob(255),
    attribute_release blob(255),
    description varchar(255) not null,
    evaluation_order integer not null,
    logo varchar(255),
    logout_type integer,
    logout_url varchar(255),
    name varchar(255) not null,
    proxy_policy blob(255),
    required_handlers blob(255),
    public_key blob(255),
    serviceId varchar(255) not null,
    theme varchar(255),
    username_attr blob(255),
    primary key (id)
)

{% endhighlight %}


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.

{% highlight xml %}
<tx:annotation-driven />

<bean id="factoryBean"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      p:dataSource-ref="dataSource"
      p:jpaVendorAdapter-ref="jpaVendorAdapter"
      p:packagesToScan-ref="packagesToScan">
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.dialect">${database.hibernate.dialect}</prop>
        <prop key="hibernate.hbm2ddl.auto">update</prop>
        <prop key="hibernate.jdbc.batch_size">${database.hibernate.batchSize:10}</prop>
      </props>
    </property>
</bean>

<util:list id="packagesToScan">
    <value>org.jasig.cas.services</value>
    <value>org.jasig.cas.ticket</value>
    <value>org.jasig.cas.adaptors.jdbc</value>
</util:list>

<bean id="jpaVendorAdapter"
      class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
      p:generateDdl="true"
      p:showSql="true" />

<bean id="serviceRegistryDao"
      class="org.jasig.cas.services.JpaServiceRegistryDaoImpl" />

<bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager"
      p:entityManagerFactory-ref="factoryBean" />

<!--
   | Injects EntityManager/Factory instances into beans with
   | @PersistenceUnit and @PersistenceContext
-->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<!--
   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 %}

Misagh Moayyed's avatar
Misagh Moayyed committed
99
100
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:
Misagh Moayyed's avatar
Misagh Moayyed committed
101
102
103
104
105
106
107
108
109
110
111

{% 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 %}

Misagh Moayyed's avatar
Misagh Moayyed committed
112
113
You will also need to change the property `hibernate.dialect` in adequacy with your 
database in `cas.properties` and `deployerConfigContext.xml`.
Misagh Moayyed's avatar
Misagh Moayyed committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

For example, for MYSQL the setting would be:

In `cas.properties`:

{% highlight bash %}
database.hibernate.dialect=org.hibernate.dialect.MySQLDialect
{% endhighlight %}

In `deployerConfigContext.xml`:

{% highlight xml %}
<prop key="hibernate.dialect">${database.hibernate.dialect}</prop>
{% endhighlight %}

You will also need to ensure that the xml configuration file contains the `tx` namespace:

{% highlight xml %}
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
{% endhighlight %}

Misagh Moayyed's avatar
Misagh Moayyed committed
140
141
142
Finally, when adding a new source new dependencies may be required on Hibernate, `commons-dbcp2`.
Be sure to add those to your `pom.xml`. Below is a sample configuration for MYSQL. Be sure to 
adjust the version elements for the appropriate version number.
Misagh Moayyed's avatar
Misagh Moayyed committed
143
144
145
146

{% highlight xml %}

<dependency>
Misagh Moayyed's avatar
Misagh Moayyed committed
147
148
149
150
    <groupId>org.jasig.cas</groupId>
    <artifactId>cas-server-support-jdbc</artifactId>
    <version>${cas.version}</version>
    <scope>runtime</scope>
Misagh Moayyed's avatar
Misagh Moayyed committed
151
152
153
</dependency>

<dependency>
Misagh Moayyed's avatar
Misagh Moayyed committed
154
155
156
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-dbcp2</artifactId>
    <version>${commons.dbcp.version}</version>
Misagh Moayyed's avatar
Misagh Moayyed committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    <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 %}