parent
b16412731d
commit
79e706e59f
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>cas-client</artifactId>
|
||||
<groupId>org.jasig.cas</groupId>
|
||||
<version>3.1.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.jasig.cas</groupId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>cas-client-support-distributed-memcached</artifactId>
|
||||
<name>Jasig CAS Client for Java - Distributed Proxy Storage Support: Memcached</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jasig.cas</groupId>
|
||||
<artifactId>cas-client-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<!-- available from http://code.google.com/p/spymemcached/ -->
|
||||
<dependency>
|
||||
<groupId>spy</groupId>
|
||||
<artifactId>memcached</artifactId>
|
||||
<version>2.4</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Tests*</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clover-plugin</artifactId>
|
||||
<configuration>
|
||||
<licenseLocation>${basedir}/src/test/clover/clover.license</licenseLocation>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>pre-site</phase>
|
||||
<goals>
|
||||
<goal>instrument</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright 2009 The JA-SIG Collaborative. All rights reserved. See license
|
||||
* distributed with this file and available online at
|
||||
* http://www.ja-sig.org/products/cas/overview/license/index.html
|
||||
*/
|
||||
package org.jasig.cas.client.proxy;
|
||||
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link org.jasig.cas.client.proxy.ProxyGrantingTicketStorage} interface that is backed by
|
||||
* Memcache for distributed web applications.
|
||||
*
|
||||
* @author Scott Battaglia
|
||||
* @version $Revision$ $Date$
|
||||
* @since 3.1.9
|
||||
*/
|
||||
public final class MemcachedBackedProxyGrantingTicketStorageImpl implements ProxyGrantingTicketStorage {
|
||||
|
||||
private final MemcachedClient client;
|
||||
|
||||
/**
|
||||
* Default constructor reads from the /casclient_memcached_hosts.txt in the classpath. Each line should be a host:port
|
||||
* combination of memcached servers.
|
||||
*/
|
||||
public MemcachedBackedProxyGrantingTicketStorageImpl() {
|
||||
this(getHostsFromClassPath());
|
||||
}
|
||||
|
||||
protected static String[] getHostsFromClassPath() {
|
||||
final InputStream inputStream = MemcachedBackedProxyGrantingTicketStorageImpl.class.getResourceAsStream("/cas/casclient_memcached_hosts.txt");
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
final List<String> hosts = new ArrayList<String>();
|
||||
|
||||
String line;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
hosts.add(line);
|
||||
}
|
||||
|
||||
return hosts.toArray(new String[hosts.size()]);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (final IOException e) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (final IOException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MemcachedBackedProxyGrantingTicketStorageImpl(final String[] hostnamesAndPorts) {
|
||||
final List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
|
||||
|
||||
for (final String hostname : hostnamesAndPorts) {
|
||||
final String[] hostPort = hostname.split(":");
|
||||
addresses.add(new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1])));
|
||||
}
|
||||
|
||||
try {
|
||||
this.client = new MemcachedClient(addresses);
|
||||
} catch (final IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void save(final String proxyGrantingTicketIou, final String proxyGrantingTicket) {
|
||||
handleSynchronousRequest(this.client.add(proxyGrantingTicketIou, 120, proxyGrantingTicket));
|
||||
}
|
||||
|
||||
public String retrieve(final String proxyGrantingTicketIou) {
|
||||
return (String) this.client.get(proxyGrantingTicketIou);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
// we actually don't have anything to do here, yay!
|
||||
}
|
||||
|
||||
private void handleSynchronousRequest(final Future f) {
|
||||
try {
|
||||
f.get();
|
||||
} catch (final Exception e) {
|
||||
// ignore these.
|
||||
}
|
||||
}
|
||||
}
|
||||
3
pom.xml
3
pom.xml
|
|
@ -129,7 +129,8 @@
|
|||
<modules>
|
||||
<module>cas-client-core</module>
|
||||
<module>cas-client-integration-atlassian</module>
|
||||
<module>cas-client-support-distributed</module>
|
||||
<module>cas-client-support-distributed-ehcache</module>
|
||||
<module>cas-client-support-distributed-memcached</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
Loading…
Reference in New Issue