Skip to content
This repository has been archived by the owner on Nov 3, 2017. It is now read-only.

Configuring JSON Service Registry

Dmitriy Kopylenko edited this page May 14, 2013 · 25 revisions
  • Create JSON configuration file servicesRegistry.conf and put it in /etc/cas. Example services definitions:
{
    "services":[
        {
            "id":1,
            "serviceId":"https://www.google.com/**",
            "name":"GOOGLE",
            "description":"Test service with ant-style pattern matching",
            "theme":"my_example_theme",
            "allowedToProxy":true,
            "enabled":true,
            "ssoEnabled":true,
            "anonymousAccess":false,
            "evaluationOrder":1
        },

        {
            "id":2,
            "serviceId":"https://yahoo.com",
            "name":"YAHOO",
            "description":"Test service with exact match on its serviceId and optional extra attributes",
            "extraAttributes":{
                "someCustomAttribute":"Custom attribute value"
            },
            "evaluationOrder":2
        },

        {
            "id":3,
            "serviceId":"^(https?|imaps?)://.*",
            "name":"HTTPS or IMAPS",
            "description":"Test service with regex-style pattern matching of any service either via HTTPS or IMAPS",
            "evaluationOrder":3
        }
    ]
}
  • Define serviceRegistryDao bean in deployerConfigContext:
<bean id="serviceRegistryDao" class="net.unicon.cas.addons.serviceregistry.JsonServiceRegistryDao" 
          init-method="loadServices">
          <constructor-arg index="0" value="file:/etc/cas/servicesRegistry.conf"/>
</bean>

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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://unicon.net/schema/cas
                           http://unicon.net/schema/cas/cas-addons.xsd">

    <cas:json-services-registry/>

</beans>
  • To add change notification support:
<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:c="http://www.springframework.org/schema/c"
       xmlns:context="http://www.springframework.org/schema/context"
       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://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- To enable JsonServiceRegistryDao#ServicesManagerInjectableBeanPostProcessor. Excludes the MongoDb services registry, which is defined as @Repository stereotype -->
    <context:component-scan base-package="net.unicon.cas.addons.serviceregistry">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    </context:component-scan>

    <!-- This aspect is optional and it just aims to suppress 
         the duplicate reloading of services from both cas-core and cas-addons. 
         WARNING: this relies on a fairly advanced feature of AspectJ compile-time weaving of aspects 
         and including the woven DefaultServicesManagerImpl class in cas-addons.jar, 
         therefore including 2 versions of this class 
         (one from cas-core jar and one from cas-addons jar) and is therefore highly dependent 
         on the classloading strategy of the target container. 
         That means that cas-core version could be loaded by the target ClassLoader 
         first and thus canceling the effect of the aspect altogether. 
         Please also note that if this happens, there is no harm in the core behavior 
         of CAS server and cas-addons - it is just that CAS default reloading cron job 
         will periodically reload the services, in addition to cas-addons on-demand 
         change-detecting reloading behavior -->
    <bean id="reloadadableServicesManagerSupressionAspect" class="net.unicon.cas.addons.serviceregistry.ReloadableServicesManagerSuppressionAspect"
          factory-method="aspectOf"/>

    <cas:resource-change-detector id="registeredServicesChangeDetectingEventNotifier"
                                  watched-resource="file:/etc/cas/servicesRegistry.conf"/>

    <task:scheduler id="springScheduler" pool-size="3"/>

    <task:scheduled-tasks scheduler="springScheduler">        
        <task:scheduled ref="registeredServicesChangeDetectingEventNotifier" method="notifyOfTheResourceChangeEventIfNecessary" fixed-delay="2000"/>
    </task:scheduled-tasks>
</beans>
Clone this wiki locally