forked from apereo/cas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket registry based on infinispan cache
- Loading branch information
1 parent
8fa64b6
commit b7b7e49
Showing
55 changed files
with
325 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cas-server-integration-ehcache-monitor/src/test/resources/log4j2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
description = 'Apereo CAS Infinispan Integration' | ||
dependencies { | ||
compile group: 'org.springframework', name: 'spring-context-support', version:springVersion | ||
compile group: 'org.springframework', name: 'spring-context', version:springVersion | ||
compile(group: 'org.infinispan', name: 'infinispan-core', version:infinispanVersion) { | ||
exclude(module: 'guava') | ||
} | ||
compile(group: 'org.infinispan', name: 'infinispan-commons', version:infinispanVersion) { | ||
exclude(module: 'guava') | ||
} | ||
|
||
compile project(':cas-server-core-api') | ||
compile project(':cas-server-core-tickets') | ||
|
||
testCompile(group: 'org.infinispan', name: 'infinispan-embedded', version:infinispanVersion) { | ||
exclude(module: 'guava') | ||
exclude(module: 'leveldb-api') | ||
exclude(module: 'leveldbjni') | ||
} | ||
testCompile project(path: ":cas-server-core-authentication", configuration: "tests") | ||
testCompile project(':cas-server-core-services') | ||
testCompile project(path: ":cas-server-core-services", configuration: "tests") | ||
testCompile project(':cas-server-core-util') | ||
} | ||
|
||
|
98 changes: 98 additions & 0 deletions
98
...tion-infinispan/src/main/java/org/jasig/cas/ticket/registry/InfinispanTicketRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.jasig.cas.ticket.registry; | ||
|
||
import org.infinispan.Cache; | ||
import org.jasig.cas.ticket.Ticket; | ||
import org.jasig.cas.ticket.registry.encrypt.AbstractCrypticTicketRegistry; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Collection; | ||
|
||
/** | ||
* This is {@link InfinispanTicketRegistry}. Infinispan is a distributed in-memory key/value data store with optional schema. | ||
* It offers advanced functionality such as transactions, events, querying and distributed processing. | ||
* See <a href="http://infinispan.org/features/">http://infinispan.org/features/</a> for more info. | ||
* | ||
* @author Misagh Moayyed | ||
* @since 4.2.0 | ||
*/ | ||
@Component("infinispanTicketRegistry") | ||
public final class InfinispanTicketRegistry extends AbstractCrypticTicketRegistry { | ||
|
||
@Resource(name="infinispanTicketsCache") | ||
private Cache<String, Ticket> cache; | ||
|
||
/** | ||
* Instantiates a new Infinispan ticket registry. | ||
*/ | ||
public InfinispanTicketRegistry() { | ||
} | ||
|
||
@Override | ||
protected void updateTicket(final Ticket ticket) { | ||
this.cache.put(ticket.getId(), ticket); | ||
} | ||
|
||
@Override | ||
protected boolean needsCallback() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Add a ticket to the registry. Ticket storage is based on the ticket id. | ||
* | ||
* @param ticket The ticket we wish to add to the cache. | ||
*/ | ||
@Override | ||
public void addTicket(final Ticket ticket) { | ||
this.cache.put(ticket.getId(), ticket); | ||
} | ||
|
||
/** | ||
* Retrieve a ticket from the registry. | ||
* | ||
* @param ticketId the id of the ticket we wish to retrieve | ||
* @return the requested ticket. | ||
*/ | ||
@Override | ||
public Ticket getTicket(final String ticketId) { | ||
final Ticket ticket = this.cache.get(ticketId); | ||
return getProxiedTicketInstance(ticket); | ||
} | ||
|
||
/** | ||
* Remove a specific ticket from the registry. | ||
* | ||
* @param ticketId The id of the ticket to delete. | ||
* @return true if the ticket was removed and false if the ticket did not | ||
* exist. | ||
*/ | ||
@Override | ||
public boolean deleteTicket(final String ticketId) { | ||
if (getTicket(ticketId) == null) { | ||
return false; | ||
} | ||
this.cache.evict(ticketId); | ||
return true; | ||
|
||
} | ||
|
||
/** | ||
* | ||
* Retrieve all tickets from the registry. | ||
* | ||
* Note! Usage of this method can be computational and I/O intensive and should not be used for other than | ||
* debugging. | ||
* | ||
* @return collection of tickets currently stored in the registry. Tickets | ||
* might or might not be valid i.e. expired. | ||
*/ | ||
@Override | ||
public Collection<Ticket> getTickets() { | ||
return this.cache.values(); | ||
} | ||
|
||
public void setCache(final Cache<String, Ticket> cache) { | ||
this.cache = cache; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...-integration-infinispan/src/main/resources/META-INF/spring/infinispan-ticket-registry.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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:tx="http://www.springframework.org/schema/tx" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xmlns:sec="http://www.springframework.org/schema/security" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context.xsd | ||
http://www.springframework.org/schema/tx | ||
http://www.springframework.org/schema/tx/spring-tx.xsd | ||
http://www.springframework.org/schema/security | ||
http://www.springframework.org/schema/security/spring-security.xsd | ||
http://www.springframework.org/schema/util | ||
http://www.springframework.org/schema/util/spring-util.xsd"> | ||
|
||
</beans> |
75 changes: 75 additions & 0 deletions
75
...infinispan/src/test/java/org/jasig/cas/ticket/registry/InfinispanTicketRegistryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.jasig.cas.ticket.registry; | ||
|
||
import org.jasig.cas.authentication.Authentication; | ||
import org.jasig.cas.authentication.TestUtils; | ||
import org.jasig.cas.ticket.Ticket; | ||
import org.jasig.cas.ticket.TicketGrantingTicket; | ||
import org.jasig.cas.ticket.TicketGrantingTicketImpl; | ||
import org.jasig.cas.ticket.support.NeverExpiresExpirationPolicy; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* This is {@link InfinispanTicketRegistryTests}. | ||
* | ||
* @since 4.2.0 | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration("classpath:/infinispan-springcache-tests.xml") | ||
public class InfinispanTicketRegistryTests { | ||
|
||
@Autowired | ||
@Qualifier("infinispanTicketRegistry") | ||
private TicketRegistry infinispanTicketRegistry; | ||
|
||
@Test | ||
public void updateTicketShouldOverwriteTicketInStorage() { | ||
final Ticket ticket = getTicket(); | ||
infinispanTicketRegistry.addTicket(ticket); | ||
assertFalse(infinispanTicketRegistry.getTicket(ticket.getId()).isExpired()); | ||
final TicketGrantingTicket ticket2 = (TicketGrantingTicket) ticket; | ||
ticket2.markTicketExpired(); | ||
infinispanTicketRegistry.addTicket(ticket); | ||
assertTrue(infinispanTicketRegistry.getTicket(ticket.getId()).isExpired()); | ||
} | ||
|
||
@Test | ||
public void addTicketExistsInCache() { | ||
final Ticket ticket = getTicket(); | ||
infinispanTicketRegistry.addTicket(ticket); | ||
assertEquals(infinispanTicketRegistry.getTicket(ticket.getId()), ticket); | ||
} | ||
|
||
@Test | ||
public void deleteTicketRemovesFromCacheReturnsTrue() { | ||
final Ticket ticket = getTicket(); | ||
infinispanTicketRegistry.addTicket(ticket); | ||
assertTrue(infinispanTicketRegistry.deleteTicket(ticket.getId())); | ||
assertNull(infinispanTicketRegistry.getTicket(ticket.getId())); | ||
} | ||
|
||
@Test | ||
public void deleteTicketOnNonExistingTicketReturnsFalse() { | ||
final String ticketId = "does_not_exist"; | ||
assertFalse(infinispanTicketRegistry.deleteTicket(ticketId)); | ||
} | ||
|
||
@Test | ||
public void getTicketReturnsTicketFromCacheOrNull() { | ||
final Ticket ticket = getTicket(); | ||
infinispanTicketRegistry.addTicket(ticket); | ||
assertEquals(infinispanTicketRegistry.getTicket(ticket.getId()), ticket); | ||
assertNull(infinispanTicketRegistry.getTicket("")); | ||
} | ||
|
||
private Ticket getTicket() { | ||
final Authentication authentication = TestUtils.getAuthentication(); | ||
return new TicketGrantingTicketImpl("123", authentication, new NeverExpiresExpirationPolicy()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
cas-server-integration-infinispan/src/test/resources/infinispan-springcache-tests.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:c="http://www.springframework.org/schema/c" | ||
xmlns:p="http://www.springframework.org/schema/p" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> | ||
|
||
|
||
<bean id="infinispanTicketRegistry" class="org.jasig.cas.ticket.registry.InfinispanTicketRegistry" /> | ||
<bean id="infinispanTicketsCache" factory-bean="cacheManager" factory-method="getCache" /> | ||
<bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager" | ||
c:configurationFile-ref="configFilePath"/> | ||
|
||
<bean id="configFilePath" factory-bean="configFile" factory-method="getFilename" /> | ||
<bean id="configFile" class="org.springframework.core.io.ClassPathResource" | ||
c:path="infinispan.xml" /> | ||
</beans> |
10 changes: 10 additions & 0 deletions
10
cas-server-integration-infinispan/src/test/resources/infinispan.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<infinispan xsi:schemaLocation="urn:infinispan:config:8.1 http://www.infinispan.org/schemas/infinispan-config-8.1.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:8.1"> | ||
|
||
<cache-container default-cache="cas"> | ||
<jmx duplicate-domains="true" /> | ||
<local-cache name="cas" /> | ||
</cache-container> | ||
</infinispan> |
Oops, something went wrong.