Search in sources :

Example 1 with MockOnlyOneTicketRegistry

use of org.apereo.cas.util.MockOnlyOneTicketRegistry in project cas by apereo.

the class DefaultCentralAuthenticationServiceTests method verifyDestroyRemoteRegistry.

/**
 * This test checks that the TGT destruction happens properly for a remote registry.
 * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
 */
@Test
public void verifyDestroyRemoteRegistry() throws Exception {
    val registry = new MockOnlyOneTicketRegistry();
    val expirationPolicy = mock(ExpirationPolicy.class);
    when(expirationPolicy.getClock()).thenReturn(Clock.systemUTC());
    val tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), expirationPolicy);
    registry.addTicket(tgt);
    val servicesManager = mock(ServicesManager.class);
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val context = CentralAuthenticationServiceContext.builder().applicationContext(applicationContext).ticketRegistry(registry).servicesManager(servicesManager).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).cipherExecutor(CipherExecutor.noOpOfStringToString()).registeredServiceAccessStrategyEnforcer(mock(AuditableExecution.class)).serviceMatchingStrategy(new DefaultServiceMatchingStrategy(servicesManager)).lockRepository(LockRepository.asDefault()).build();
    val cas = new DefaultCentralAuthenticationService(context);
    cas.deleteTicket(tgt.getId());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DefaultServiceMatchingStrategy(org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockOnlyOneTicketRegistry(org.apereo.cas.util.MockOnlyOneTicketRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with MockOnlyOneTicketRegistry

use of org.apereo.cas.util.MockOnlyOneTicketRegistry in project cas by apereo.

the class CentralAuthenticationServiceImplTests method verifyDestroyRemoteRegistry.

/**
 * This test checks that the TGT destruction happens properly for a remote registry.
 * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
 */
@Test
public void verifyDestroyRemoteRegistry() throws AbstractTicketException, AuthenticationException {
    final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry();
    final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), mock(ExpirationPolicy.class));
    final LogoutManager logoutManager = mock(LogoutManager.class);
    when(logoutManager.performLogout(any(TicketGrantingTicket.class))).thenAnswer(invocation -> {
        tgt.markTicketExpired();
        registry.updateTicket(tgt);
        return null;
    });
    registry.addTicket(tgt);
    final DefaultCentralAuthenticationService cas = new DefaultCentralAuthenticationService(mock(ApplicationEventPublisher.class), registry, null, logoutManager, null, null, null, null, null, mock(AuditableExecution.class));
    cas.destroyTicketGrantingTicket(tgt.getId());
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) LogoutManager(org.apereo.cas.logout.LogoutManager) MockOnlyOneTicketRegistry(org.apereo.cas.util.MockOnlyOneTicketRegistry) ExpirationPolicy(org.apereo.cas.ticket.ExpirationPolicy) AuditableExecution(org.apereo.cas.audit.AuditableExecution) Test(org.junit.Test)

Aggregations

Authentication (org.apereo.cas.authentication.Authentication)2 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)2 MockOnlyOneTicketRegistry (org.apereo.cas.util.MockOnlyOneTicketRegistry)2 lombok.val (lombok.val)1 AuditableExecution (org.apereo.cas.audit.AuditableExecution)1 DefaultServiceMatchingStrategy (org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy)1 LogoutManager (org.apereo.cas.logout.LogoutManager)1 ExpirationPolicy (org.apereo.cas.ticket.ExpirationPolicy)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1