Java Code Examples for org.jasig.cas.ticket.TicketGrantingTicket#markTicketExpired()

The following examples show how to use org.jasig.cas.ticket.TicketGrantingTicket#markTicketExpired() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistributedTicketRegistryTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyUpdateOfRegistry() {
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    this.ticketRegistry.addTicket(t);
    final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test");

    final ServiceTicket s = returned.grantServiceTicket("test2", TestUtils.getService(),
            new NeverExpiresExpirationPolicy(), true);

    this.ticketRegistry.addTicket(s);
    final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2");
    assertNotNull(s2.grantTicketGrantingTicket("ff", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy()));

    assertTrue(s2.isValidFor(TestUtils.getService()));
    assertTrue(this.wasTicketUpdated);

    returned.markTicketExpired();
    assertTrue(t.isExpired());
}
 
Example 2
Source File: DistributedTicketRegistryTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateOfRegistry() {
    final TicketGrantingTicket t = new TicketGrantingTicketImpl("test", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    this.ticketRegistry.addTicket(t);
    final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket("test");

    final ServiceTicket s = returned.grantServiceTicket("test2", TestUtils.getService(),
            new NeverExpiresExpirationPolicy(), true);

    this.ticketRegistry.addTicket(s);
    final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2");
    assertNotNull(s2.grantTicketGrantingTicket("ff", TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy()));

    assertTrue(s2.isValidFor(TestUtils.getService()));
    assertTrue(this.wasTicketUpdated);

    returned.markTicketExpired();
    assertTrue(t.isExpired());
}
 
Example 3
Source File: LogoutManagerImpl.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Perform a back channel logout for a given ticket granting ticket and returns all the logout requests.
 *
 * @param ticket a given ticket granting ticket.
 * @return all logout requests.
 */
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    final Map<String, Service> services;
    // synchronize the retrieval of the services and their cleaning for the TGT
    // to avoid concurrent logout mess ups
    synchronized (ticket) {
        services = ticket.getServices();
        ticket.removeAllServices();
    }
    ticket.markTicketExpired();

    final List<LogoutRequest> logoutRequests = new ArrayList<>();
    // if SLO is not disabled
    if (!this.singleLogoutCallbacksDisabled) {
        // through all services
        for (final Map.Entry<String, Service> entry : services.entrySet()) {
            // it's a SingleLogoutService, else ignore
            final Service service = entry.getValue();
            if (service instanceof SingleLogoutService) {
                final LogoutRequest logoutRequest = handleLogoutForSloService((SingleLogoutService) service, entry.getKey());
                if (logoutRequest != null) {
                    LOGGER.debug("Captured logout request [{}]", logoutRequest);
                    logoutRequests.add(logoutRequest);
                }
            }
        }
    }

    return logoutRequests;
}
 
Example 4
Source File: AbstractRegistryCleanerTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
protected void populateRegistryWithExpiredTickets() {
    for (int i = 0; i < 10; i++) {
        final TicketGrantingTicket ticket = new TicketGrantingTicketImpl("test" + i, TestUtils.getAuthentication(),
                new NeverExpiresExpirationPolicy());
        ticket.markTicketExpired();
        this.ticketRegistry.addTicket(ticket);
    }
}
 
Example 5
Source File: OpenIdCredentialsAuthenticationHandlerTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test(expected = FailedLoginException.class)
public void verifyTGTThatIsExpired() throws Exception {
    final OpenIdCredential c = new OpenIdCredential("test", "test");
    final TicketGrantingTicket t = getTicketGrantingTicket();
    this.ticketRegistry.addTicket(t);

    t.markTicketExpired();
    this.openIdCredentialsAuthenticationHandler.authenticate(c);
}
 
Example 6
Source File: AbstractRegistryCleanerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
private void populateRegistryWithExpiredTickets() {
    for (int i = 0; i < 10; i++) {
        TicketGrantingTicket ticket = new TicketGrantingTicketImpl("test" + i, TestUtils.getAuthentication(),
                new NeverExpiresExpirationPolicy());
        ticket.markTicketExpired();
        this.ticketRegistry.addTicket(ticket);
    }
}
 
Example 7
Source File: OpenIdCredentialsAuthenticationHandlerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test(expected = FailedLoginException.class)
public void testTGTThatIsExpired() throws Exception {
    final OpenIdCredential c = new OpenIdCredential("test", "test");
    final TicketGrantingTicket t = getTicketGrantingTicket();
    this.ticketRegistry.addTicket(t);

    t.markTicketExpired();
    this.openIdCredentialsAuthenticationHandler.authenticate(c);
}
 
Example 8
Source File: MockExpireUpdateTicketLogoutManager.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    ticket.markTicketExpired();
    registry.updateTicket(ticket);
    return null;
}
 
Example 9
Source File: LogoutManagerImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a back channel logout for a given ticket granting ticket and returns all the logout requests.
 *
 * @param ticket a given ticket granting ticket.
 * @return all logout requests.
 */
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    final Map<String, Service> services;
    // synchronize the retrieval of the services and their cleaning for the TGT
    // to avoid concurrent logout mess ups
    synchronized (ticket) {
        services = ticket.getServices();
        ticket.removeAllServices();
    }
    ticket.markTicketExpired();

    final List<LogoutRequest> logoutRequests = new ArrayList<LogoutRequest>();
    // if SLO is not disabled
    if (!disableSingleSignOut) {
        // through all services
        for (final String ticketId : services.keySet()) {
            final Service service = services.get(ticketId);
            // it's a SingleLogoutService, else ignore
            if (service instanceof SingleLogoutService) {
                final SingleLogoutService singleLogoutService = (SingleLogoutService) service;
                // the logout has not performed already
                if (!singleLogoutService.isLoggedOutAlready()) {
                    final LogoutRequest logoutRequest = new LogoutRequest(ticketId, singleLogoutService);
                    // always add the logout request
                    logoutRequests.add(logoutRequest);
                    final RegisteredService registeredService = servicesManager.findServiceBy(service);
                    // the service is no more defined, or the logout type is not defined or is back channel
                    if (registeredService == null || registeredService.getLogoutType() == null
                            || registeredService.getLogoutType() == LogoutType.BACK_CHANNEL) {
                        // perform back channel logout
                        if (performBackChannelLogout(logoutRequest)) {
                            logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);
                        } else {
                            logoutRequest.setStatus(LogoutRequestStatus.FAILURE);
                            LOGGER.warn("Logout message not sent to [{}]; Continuing processing...",
                                    singleLogoutService.getId());
                        }
                    }
                }
            }
        }
    }

    return logoutRequests;
}
 
Example 10
Source File: MockExpireUpdateTicketLogoutManager.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    ticket.markTicketExpired();
    registry.updateTicket(ticket);
    return null;
}