use of org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy 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());
}
use of org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy in project cas by apereo.
the class DefaultCentralAuthenticationServiceMockitoTests method prepareNewCAS.
@BeforeEach
public void prepareNewCAS() {
this.authentication = mock(Authentication.class);
when(this.authentication.getAuthenticationDate()).thenReturn(ZonedDateTime.now(ZoneOffset.UTC));
val metadata = new BasicCredentialMetaData(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
val successes = new HashMap<String, AuthenticationHandlerExecutionResult>();
successes.put("handler1", new DefaultAuthenticationHandlerExecutionResult(mock(AuthenticationHandler.class), metadata));
when(this.authentication.getCredentials()).thenReturn(List.of(metadata));
when(this.authentication.getSuccesses()).thenReturn(successes);
when(this.authentication.getPrincipal()).thenReturn(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal(PRINCIPAL));
val tgtRootMock = createRootTicketGrantingTicket();
val service1 = getService(SVC1_ID);
val stMock = createMockServiceTicket(ST_ID, service1);
val tgtMock = createMockTicketGrantingTicket(TGT_ID, stMock, false, tgtRootMock, new ArrayList<>());
when(tgtMock.getProxiedBy()).thenReturn(getService("proxiedBy"));
stMock.setTicketGrantingTicket(tgtMock);
val authnListMock = mock(List.class);
/*
* Size is required to be 2, so that
* we can simulate proxying capabilities
*/
when(authnListMock.size()).thenReturn(2);
when(authnListMock.toArray()).thenReturn(new Object[] { this.authentication, this.authentication });
when(authnListMock.get(anyInt())).thenReturn(this.authentication);
when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
val service2 = getService(SVC2_ID);
val stMock2 = createMockServiceTicket(ST2_ID, service2);
val tgtMock2 = createMockTicketGrantingTicket(TGT2_ID, stMock2, false, tgtRootMock, authnListMock);
stMock2.setTicketGrantingTicket(tgtMock2);
mockTicketRegistry(stMock, tgtMock, stMock2, tgtMock2);
val smMock = getServicesManager(service1, service2);
val factory = getTicketFactory();
val authenticationRequestServiceSelectionStrategies = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
val enforcer = mock(AuditableExecution.class);
when(enforcer.execute(any())).thenReturn(new AuditableExecutionResult());
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val context = CentralAuthenticationServiceContext.builder().applicationContext(applicationContext).ticketRegistry(ticketRegMock).servicesManager(smMock).ticketFactory(factory).lockRepository(LockRepository.asDefault()).authenticationServiceSelectionPlan(authenticationRequestServiceSelectionStrategies).authenticationPolicyFactory(new AcceptAnyAuthenticationPolicyFactory()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).cipherExecutor(CipherExecutor.noOpOfStringToString()).registeredServiceAccessStrategyEnforcer(enforcer).serviceMatchingStrategy(new DefaultServiceMatchingStrategy(smMock)).build();
this.cas = new DefaultCentralAuthenticationService(context);
}
use of org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy in project cas by apereo.
the class SamlServiceTests method verifyTargetMatchingSamlService.
@Test
public void verifyTargetMatchingSamlService() {
val request = new MockHttpServletRequest();
request.setParameter(SamlProtocolConstants.CONST_PARAM_TARGET, "https://some.service.edu/path/to/app");
val service = new DefaultArgumentExtractor(samlServiceFactory).extractService(request);
val impl = new DefaultArgumentExtractor(samlServiceFactory).extractService(request);
val manager = mock(ServicesManager.class);
assertTrue(new DefaultServiceMatchingStrategy(manager).matches(impl, service));
}
use of org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy in project cas by apereo.
the class SamlServiceTests method verifyTargetMatchesNoSamlService.
@Test
public void verifyTargetMatchesNoSamlService() {
val request = new MockHttpServletRequest();
request.setParameter(SamlProtocolConstants.CONST_PARAM_TARGET, "https://some.service.edu/path/to/app");
val impl = new DefaultArgumentExtractor(samlServiceFactory).extractService(request);
val request2 = new MockHttpServletRequest();
request2.setParameter(SamlProtocolConstants.CONST_PARAM_TARGET, "https://some.SERVICE.edu");
val service = new DefaultArgumentExtractor(samlServiceFactory).extractService(request2);
val manager = mock(ServicesManager.class);
assertFalse(new DefaultServiceMatchingStrategy(manager).matches(impl, service));
}
Aggregations