-
Notifications
You must be signed in to change notification settings - Fork 26
Configuring JSON ComplexStubPersonAttributeDao
There is a ComplexStubPersonAttributeDao available in the Person Directory Service project which is very useful for development time testing. However, configuring it in the Spring application context with test principals as well as their attributes is very verbose and somewhat painful. Also, using it straight from Spring application context bean configuration makes it a 'read-only' instance and in order to change/add new values to it, the servlet container needs to be restarted in order to pick up new in-memory values.
cas-addons fixes both of these 'inconveniences' by providing a convenient extension of ComplexStubPersonAttributeDao
which allows it to be configured externally from a readable JSON file as well as adds the ability to re-load the instance at runtime detecting the changes to the configuration file almost instanteniously and eliminates the need to re-start servlet container for any changes to the config. This significantly reduces the overhead of develop-compile-deploy cycle during development and testing.
- Define an external JSON configuration file
/etc/cas/person-attributes.conf
in this example:
{
"u1":{
"firstName":["Json1"],
"lastName":["One"],
"additionalAttribute":["here I AM!!!"],
"additionalAttribute2":["attr2"],
"eduPersonAffiliation":["alumni", "staff"]
},
"u2":{
"firstName":["Json2"],
"lastName":["Two"],
"eduPersonAffiliation":["employee", "student"]
},
"u3":{
"firstName":["Json3"],
"lastName":["Three"],
"eduPersonAffiliation":["alumni", "student", "employee", "some other attr"]
}
}
- Define Spring beans:
<bean id="attributeRepository" class="net.unicon.cas.addons.persondir.JsonBackedComplexStubPersonAttributeDao" init-method="init">
<constructor-arg index="0" value="file:/etc/cas/person-attributes.conf"/>
</bean>
<bean id="personAttributesChangeDetectingEventNotifier"
class="net.unicon.cas.addons.support.ResourceChangeDetectingEventNotifier"
c:watchedResource="file:/etc/cas/person-attributes.conf"/>
<task:scheduler id="springScheduler" pool-size="3"/>
<task:scheduled-tasks scheduler="springScheduler">
<task:scheduled ref="personAttributesChangeDetectingEventNotifier" method="notifyOfTheResourceChangeEventIfNecessary" fixed-delay="5000"/>
</task:scheduled-tasks>
Or use more compact declaration with custom namespace support (available since version 1.4):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cas="http://unicon.net/schema/cas"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://unicon.net/schema/cas
http://unicon.net/schema/cas/cas-addons.xsd">
<cas:json-attribute-repository/>
<cas:resource-change-detector id="personAttributesChangeDetectingEventNotifier"
watched-resource="file:/etc/cas/person-attributes.conf"/>
<task:scheduler id="springScheduler" pool-size="3"/>
<task:scheduled-tasks scheduler="springScheduler">
<task:scheduled ref="personAttributesChangeDetectingEventNotifier" method="notifyOfTheResourceChangeEventIfNecessary" fixed-delay="5000"/>
</task:scheduled-tasks>
</beans>