Skip to content

Commit

Permalink
Remove the ticket delegator components. (apereo#1706)
Browse files Browse the repository at this point in the history
* Remove the ticket delegetor components. Closes #1672

* fixed test cases

* fixed test cases

* fixed test cases

* removed refs to delegators in the JPA config

* Fix oauth unit tests

* fixing test cases

* fixing test cases

* fixing test cases
  • Loading branch information
dima767 authored and SavvasMisaghMoayyed committed Apr 24, 2016
1 parent d522901 commit 6ba1378
Show file tree
Hide file tree
Showing 35 changed files with 783 additions and 674 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ before_install:
- ls ./etc
- sudo unzip -j -o ./etc/jce8.zip *.jar -d `jdk_switcher home oraclejdk8`/jre/lib/security
- sudo ls `jdk_switcher home oraclejdk8`/jre/lib/security
- sudo cp ./etc/java.security `jdk_switcher home oraclejdk8`/jre/lib/security
- chmod -R 777 ./travis/init-travis-build.sh
- ./travis/init-travis-build.sh
- chmod -R 777 ./gradlew
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ public interface TicketRegistry {
* might or might not be valid i.e. expired.
*/
Collection<Ticket> getTickets();

/**
* Update the received ticket.
*
* @param ticket the ticket
*/
void updateTicket(Ticket ticket);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import javax.security.auth.login.LoginException;


import org.apache.commons.io.IOUtils;
import org.jasig.cas.authentication.TestUtils;
import org.junit.Before;
import org.junit.Test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.FileWriter;

import static org.junit.Assert.*;

Expand All @@ -24,15 +29,16 @@ public class JaasAuthenticationHandlerTests {

@Before
public void setUp() throws Exception {
String pathPrefix = System.getProperty("user.dir");
pathPrefix = !pathPrefix.contains("cas-server-core") ? pathPrefix
+ "/cas-server-core" : pathPrefix;
logger.info("PATH PREFIX: {}", pathPrefix);

final String pathToConfig = pathPrefix
+ "/src/test/resources/org/jasig/cas/authentication/handler/support/jaas.conf";
System.setProperty("java.security.auth.login.config", '=' +pathToConfig);
this.handler = new JaasAuthenticationHandler();
final ClassPathResource resource = new ClassPathResource("jaas.conf");
final File fileName = new File(System.getProperty("java.io.tmpdir"), "jaas.conf");
try (final FileWriter writer = new FileWriter(fileName)) {
IOUtils.copy(resource.getInputStream(), writer);
writer.flush();
}
if (fileName.exists()) {
System.setProperty("java.security.auth.login.config", '=' + fileName.getCanonicalPath());
this.handler = new JaasAuthenticationHandler();
}
}

@Test(expected = LoginException.class)
Expand Down
Binary file modified cas-server-core-authentication/src/test/resources/truststore.jks
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import org.jasig.cas.ticket.Ticket;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.proxy.ProxyGrantingTicket;
import org.jasig.cas.ticket.proxy.ProxyTicket;
import org.jasig.cas.util.DateTimeUtils;
import org.jasig.cas.util.DigestUtils;
import org.jasig.cas.util.Pair;
import org.jasig.cas.util.SerializationUtils;
import org.quartz.Job;
import org.quartz.JobBuilder;
Expand All @@ -33,12 +31,9 @@

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import java.lang.reflect.Constructor;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand All @@ -48,7 +43,7 @@
* @author Scott Battaglia
* @since 3.0.0
* <p>
* This is a published and supported CAS Server 3 API.
* This is a published and supported CAS Server API.
* </p>
*/
public abstract class AbstractTicketRegistry implements TicketRegistry, TicketRegistryState, Job {
Expand Down Expand Up @@ -78,21 +73,11 @@ public abstract class AbstractTicketRegistry implements TicketRegistry, TicketRe
@Qualifier("logoutManager")
private LogoutManager logoutManager;

private List<Pair<Class<? extends Ticket>, Constructor<? extends AbstractTicketDelegator>>> ticketDelegators = new ArrayList<>();

/**
* Default constructor which registers the appropriate ticket delegators.
* Default constructor.
*/
@SuppressWarnings("unchecked")
public AbstractTicketRegistry() {
ticketDelegators.add(new Pair(ProxyGrantingTicket.class,
AbstractTicketDelegator.getDefaultConstructor(ProxyGrantingTicketDelegator.class)));
ticketDelegators.add(new Pair(TicketGrantingTicket.class,
AbstractTicketDelegator.getDefaultConstructor(TicketGrantingTicketDelegator.class)));
ticketDelegators.add(new Pair(ProxyTicket.class,
AbstractTicketDelegator.getDefaultConstructor(ProxyTicketDelegator.class)));
ticketDelegators.add(new Pair(ServiceTicket.class,
AbstractTicketDelegator.getDefaultConstructor(ServiceTicketDelegator.class)));
}

/**
Expand Down Expand Up @@ -199,47 +184,14 @@ public boolean deleteSingleTicket(final Ticket ticketId) {
* @return the boolean
*/
public abstract boolean deleteSingleTicket(final String ticketId);

/**
* Update the received ticket.
*
* @param ticket the ticket
*/
protected abstract void updateTicket(Ticket ticket);


/**
* Whether or not a callback to the TGT is required when checking for expiration.
*
* @return true, if successful
*/
protected abstract boolean needsCallback();

/**
* Gets the proxied ticket instance.
*
* @param ticket the ticket
* @return the proxied ticket instance
*/
protected final Ticket getProxiedTicketInstance(final Ticket ticket) {
if (ticket == null) {
return null;
}

for (final Pair<Class<? extends Ticket>, Constructor<? extends AbstractTicketDelegator>> ticketDelegator: ticketDelegators) {
final Class<? extends Ticket> clazz = ticketDelegator.getFirst();
if (clazz.isAssignableFrom(ticket.getClass())) {
final Constructor<? extends AbstractTicketDelegator> constructor = ticketDelegator.getSecond();
try {
return constructor.newInstance(this, ticket, needsCallback());
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}

throw new IllegalStateException("Cannot wrap ticket of type: " + ticket.getClass() + " with a ticket delegator");
}

public void setCipherExecutor(final CipherExecutor<byte[], byte[]> cipherExecutor) {
this.cipherExecutor = cipherExecutor;
}
Expand Down Expand Up @@ -331,16 +283,6 @@ protected Collection<Ticket> decodeTickets(final Collection<Ticket> items) {
return items.stream().map(this::decodeTicket).collect(Collectors.toSet());
}

@Nullable
public List<Pair<Class<? extends Ticket>, Constructor<? extends AbstractTicketDelegator>>> getTicketDelegators() {
return ticketDelegators;
}

public void setTicketDelegators(@Nullable final List<Pair<Class<? extends Ticket>, Constructor<? extends AbstractTicketDelegator>>>
ticketDelegators) {
this.ticketDelegators = ticketDelegators;
}

/**
* Common code to go over expired tickets and clean them up.
**/
Expand Down Expand Up @@ -393,8 +335,14 @@ protected boolean preCleanupTickets() {
protected void scheduleCleanerJob() {
try {

if (!cleanerEnabled && isCleanerSupported()) {
logger.info("Ticket registry cleaner is disabled or is not supported by {}. No cleaner processes will be scheduled.",
if (!this.cleanerEnabled) {
logger.info("Ticket registry cleaner is disabled by {}. No cleaner processes will be scheduled.",
this.getClass().getName());
return;
}

if (!isCleanerSupported()) {
logger.info("Ticket registry cleaner is not supported by {}. No cleaner processes will be scheduled.",
this.getClass().getName());
return;
}
Expand All @@ -412,7 +360,7 @@ protected void scheduleCleanerJob() {
.repeatForever()).build();

logger.debug("Scheduling {} job", this.getClass().getSimpleName());
scheduler.scheduleJob(job, trigger);
this.scheduler.scheduleJob(job, trigger);
logger.info("{} will clean tickets every {} minutes",
this.getClass().getSimpleName(),
TimeUnit.SECONDS.toMinutes(this.refreshInterval));
Expand Down Expand Up @@ -440,6 +388,6 @@ public final void execute(final JobExecutionContext jobExecutionContext) throws
* @return true/false.
*/
protected boolean isCleanerSupported() {
return true;
return this.scheduler != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public Ticket getTicket(final String ticketId) {
if (ticketId == null) {
return null;
}

final Ticket ticket = decodeTicket(this.cache.get(encTicketId));
return getProxiedTicketInstance(ticket);
return decodeTicket(this.cache.get(encTicketId));
}

@Override
Expand All @@ -98,7 +96,7 @@ public long serviceTicketCount() {
}

@Override
protected void updateTicket(final Ticket ticket) {
public void updateTicket(final Ticket ticket) {
addTicket(ticket);
}

Expand Down
Loading

0 comments on commit 6ba1378

Please sign in to comment.