Search in sources :

Example 1 with DefaultTicketGrantingTicketFactory

use of org.apereo.cas.ticket.factory.DefaultTicketGrantingTicketFactory in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method prepareNewCAS.

@Before
public void prepareNewCAS() throws Exception {
    this.authentication = mock(Authentication.class);
    when(this.authentication.getAuthenticationDate()).thenReturn(ZonedDateTime.now(ZoneOffset.UTC));
    final CredentialMetaData metadata = new BasicCredentialMetaData(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
    final Map<String, HandlerResult> successes = new HashMap<>();
    successes.put("handler1", new DefaultHandlerResult(mock(AuthenticationHandler.class), metadata));
    when(this.authentication.getCredentials()).thenReturn(Arrays.asList(metadata));
    when(this.authentication.getSuccesses()).thenReturn(successes);
    when(this.authentication.getPrincipal()).thenReturn(new DefaultPrincipalFactory().createPrincipal(PRINCIPAL));
    final Service service1 = getService(SVC1_ID);
    final ServiceTicket stMock = createMockServiceTicket(ST_ID, service1);
    final TicketGrantingTicket tgtRootMock = createRootTicketGrantingTicket();
    final TicketGrantingTicket tgtMock = createMockTicketGrantingTicket(TGT_ID, stMock, false, tgtRootMock, new ArrayList<>());
    when(tgtMock.getProxiedBy()).thenReturn(getService("proxiedBy"));
    final List<Authentication> authnListMock = mock(List.class);
    //Size is required to be 2, so that we can simulate proxying capabilities
    when(authnListMock.size()).thenReturn(2);
    when(authnListMock.get(anyInt())).thenReturn(this.authentication);
    when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock.getGrantingTicket()).thenReturn(tgtMock);
    final Service service2 = getService(SVC2_ID);
    final ServiceTicket stMock2 = createMockServiceTicket(ST2_ID, service2);
    final TicketGrantingTicket tgtMock2 = createMockTicketGrantingTicket(TGT2_ID, stMock2, false, tgtRootMock, authnListMock);
    //Mock TicketRegistry
    mockTicketRegistry(stMock, tgtMock, stMock2, tgtMock2);
    //Mock ServicesManager
    final ServicesManager smMock = getServicesManager(service1, service2);
    final DefaultTicketFactory factory = new DefaultTicketFactory(new DefaultProxyGrantingTicketFactory(null, null, null), new DefaultTicketGrantingTicketFactory(null, null, null), new DefaultServiceTicketFactory(null, Collections.emptyMap(), false, null), new DefaultProxyTicketFactory(null, Collections.emptyMap(), null, true));
    final AuthenticationServiceSelectionPlan authenticationRequestServiceSelectionStrategies = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
    this.cas = new DefaultCentralAuthenticationService(ticketRegMock, factory, smMock, mock(LogoutManager.class), authenticationRequestServiceSelectionStrategies, new AcceptAnyAuthenticationPolicyFactory(), new DefaultPrincipalFactory(), null);
    this.cas.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
}
Also used : HashMap(java.util.HashMap) DefaultProxyTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyTicketFactory) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) DefaultProxyGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyGrantingTicketFactory) AcceptAnyAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultServiceTicketFactory(org.apereo.cas.ticket.factory.DefaultServiceTicketFactory) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultTicketGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketGrantingTicketFactory) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) HandlerResult(org.apereo.cas.authentication.HandlerResult) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) DefaultTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Authentication(org.apereo.cas.authentication.Authentication) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1 CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)1 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)1 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)1 HandlerResult (org.apereo.cas.authentication.HandlerResult)1 AcceptAnyAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 DefaultProxyGrantingTicketFactory (org.apereo.cas.ticket.factory.DefaultProxyGrantingTicketFactory)1 DefaultProxyTicketFactory (org.apereo.cas.ticket.factory.DefaultProxyTicketFactory)1 DefaultServiceTicketFactory (org.apereo.cas.ticket.factory.DefaultServiceTicketFactory)1 DefaultTicketFactory (org.apereo.cas.ticket.factory.DefaultTicketFactory)1