JPA-Service-Management.md 4.13 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
# JPA Service Registry 
Misagh Moayyed's avatar
Misagh Moayyed committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Stores registered service data in a database. 

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.
Misagh Moayyed's avatar
Misagh Moayyed committed
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

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

Misagh Moayyed's avatar
Misagh Moayyed committed
47
## Configuration
Misagh Moayyed's avatar
Misagh Moayyed committed
48
49
50
51
52
53

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

Misagh Moayyed's avatar
Misagh Moayyed committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<bean
    id="dataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    p:driverClass="${database.driverClass:org.hsqldb.jdbcDriver}"
    p:jdbcUrl="${database.url:jdbc:hsqldb:mem:cas-ticket-registry}"
    p:user="${database.user:sa}"
    p:password="${database.password:}"
    p:initialPoolSize="${database.pool.minSize:6}"
    p:minPoolSize="${database.pool.minSize:6}"
    p:maxPoolSize="${database.pool.maxSize:18}"
    p:maxIdleTimeExcessConnections="${database.pool.maxIdleTime:1000}"
    p:checkoutTimeout="${database.pool.maxWait:2000}"
    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"/>
Misagh Moayyed's avatar
Misagh Moayyed committed
74
75
76
77
78
79
80

<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>

Misagh Moayyed's avatar
Misagh Moayyed committed
81
82
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
      id="jpaVendorAdapter"
Misagh Moayyed's avatar
Misagh Moayyed committed
83
84
85
      p:generateDdl="true"
      p:showSql="true" />

Misagh Moayyed's avatar
Misagh Moayyed committed
86
87
88
89
90
91
92
93
94
95
96
97
98
<bean id="entityManagerFactory"
      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.dialect:org.hibernate.dialect.HSQLDialect}</prop>
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
            <prop key="hibernate.jdbc.batch_size">${database.batchSize:1}</prop>
        </props>
    </property>
</bean>
Misagh Moayyed's avatar
Misagh Moayyed committed
99

Misagh Moayyed's avatar
Misagh Moayyed committed
100
101
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
      p:entityManagerFactory-ref="entityManagerFactory" />
Misagh Moayyed's avatar
Misagh Moayyed committed
102

Misagh Moayyed's avatar
Misagh Moayyed committed
103
104
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
Misagh Moayyed's avatar
Misagh Moayyed committed
105

Misagh Moayyed's avatar
Misagh Moayyed committed
106
107
108
109
110
111
        <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>
Misagh Moayyed's avatar
Misagh Moayyed committed
112

Misagh Moayyed's avatar
Misagh Moayyed committed
113
114
115
116
117
118
119
120
<aop:config>
    <aop:pointcut id="servicesManagerOperations" expression="execution(* org.jasig.cas.services.JpaServiceRegistryDaoImpl.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="servicesManagerOperations"/>
</aop:config>
      
<bean id="serviceRegistryDao"
      class="org.jasig.cas.services.JpaServiceRegistryDaoImpl" />
      
Misagh Moayyed's avatar
Misagh Moayyed committed
121
122
{% endhighlight %}

Misagh Moayyed's avatar
Misagh Moayyed committed
123
add props and config for xml