Skip to content

Instantly share code, notes, and snippets.

@dima767
Created March 11, 2012 17:23
Show Gist options
  • Save dima767/2017182 to your computer and use it in GitHub Desktop.
Save dima767/2017182 to your computer and use it in GitHub Desktop.
import org.jasig.cas.services.RegisteredService;
import java.util.Map;
/**
* An extention to <code>RegisteredService</code> with extra arbitrary attributes
*
* @author Dmitriy Kopylenko
*/
public interface RegisteredServiceWithAttributes extends RegisteredService {
Map<String, Object> getExtraAttributes();
}
/*****************************************************************************************/
import org.jasig.cas.services.RegisteredServiceImpl;
import java.util.HashMap;
import java.util.Map;
/**
* An extention to <code>RegisteredServiceImpl</code> with extra arbitrary attributes
*
* @author Dmitriy Kopylenko
*/
public class RegisteredServiceWithAttributesImpl extends RegisteredServiceImpl implements RegisteredServiceWithAttributes {
private Map<String, Object> extraAttributes = new HashMap<String, Object>();
@Override
public Map<String, Object> getExtraAttributes() {
return this.extraAttributes;
}
public void setExtraAttributes(Map<String, Object> extraAttributes) {
this.extraAttributes = extraAttributes;
}
}
/*************************************************************************************************/
import org.jasig.cas.services.ServiceRegistryDao
import org.jasig.cas.services.RegisteredService
import org.jasig.cas.services.InMemoryServiceRegistryDaoImpl
import org.springframework.core.io.Resource
import org.codehaus.jackson.map.ObjectMapper
import org.jasig.cas.services.RegisteredServiceImpl
/**
* In-memory implementation of <code>ServiceRegistryDao</code> that reads services definition from JSON configuration file at the Spring Application Context
* initialization time. After un-marshaling services from JSON blob, delegates the storage and retrieval to <code>InMemoryServiceRegistryDaoImpl</code>
*
* @author Dmitriy Kopylenko
*/
class JsonServiceRegistryDao implements ServiceRegistryDao {
InMemoryServiceRegistryDaoImpl delegateServiceRegistryDao = new InMemoryServiceRegistryDaoImpl()
/**
* A configuration file containing JSON representation of the Services attributes. REQUIRED.
*/
Resource servicesConfigFile;
@Override
RegisteredService save(RegisteredService registeredService) {
return this.delegateServiceRegistryDao.save(registeredService)
}
@Override
boolean delete(RegisteredService registeredService) {
return this.delegateServiceRegistryDao.delete(registeredService)
}
@Override
List<RegisteredService> load() {
synchronized (this.delegateServiceRegistryDao.registeredServices) {
init()
return this.delegateServiceRegistryDao.registeredServices
}
}
@Override
RegisteredService findServiceById(long id) {
return this.delegateServiceRegistryDao.findServiceById(id)
}
void init() {
def mapper = new ObjectMapper()
def servicesCollection = mapper.readValue(servicesConfigFile.file, RegisteredServicesCollection.class)
this.delegateServiceRegistryDao.registeredServices = servicesCollection.services
}
//Here to provide a top level 'container' for Jackson mapper
static class RegisteredServicesCollection {
List<RegisteredServiceWithAttributesImpl> services
}
}
/************************************************************************************************************/
<!--
In-memory data store for the ServiceRegistry that reads the services definition from /etc/cas/servicesRegistry.conf JSON file
-->
<lang:groovy id="serviceRegistryDao"
script-source="/WEB-INF/groovy/JsonServiceRegistryDao.groovy"
init-method="init">
<lang:property name="servicesConfigFile" value="file:/etc/cas/servicesRegistry.conf"/>
</lang:groovy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment