Search in sources :

Example 1 with AcceptAnyAuthenticationPolicyFactory

use of org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory in project cas by apereo.

the class AcceptAnyAuthenticationPolicyFactoryTests method verifyOperation.

@Test
public void verifyOperation() {
    val input = new AcceptAnyAuthenticationPolicyFactory();
    val policy = input.createPolicy(new ServiceContext(CoreAuthenticationTestUtils.getService(), CoreAuthenticationTestUtils.getRegisteredService()));
    assertNotNull(policy.getContext());
}
Also used : lombok.val(lombok.val) AcceptAnyAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory) ServiceContext(org.apereo.cas.services.ServiceContext) Test(org.junit.jupiter.api.Test)

Example 2 with AcceptAnyAuthenticationPolicyFactory

use of org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory 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);
}
Also used : lombok.val(lombok.val) AcceptAnyAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) DefaultServiceMatchingStrategy(org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy) Authentication(org.apereo.cas.authentication.Authentication) AuditableExecutionResult(org.apereo.cas.audit.AuditableExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with AcceptAnyAuthenticationPolicyFactory

use of org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method prepareNewCAS.

@Before
public void prepareNewCAS() {
    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, AuthenticationHandlerExecutionResult> successes = new HashMap<>();
    successes.put("handler1", new DefaultAuthenticationHandlerExecutionResult(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.toArray()).thenReturn(new Object[] { this.authentication, this.authentication });
    when(authnListMock.get(anyInt())).thenReturn(this.authentication);
    when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock.getTicketGrantingTicket()).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);
    mockTicketRegistry(stMock, tgtMock, stMock2, tgtMock2);
    final ServicesManager smMock = getServicesManager(service1, service2);
    final TicketFactory factory = getTicketFactory();
    final AuthenticationServiceSelectionPlan authenticationRequestServiceSelectionStrategies = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
    final AuditableExecution enforcer = mock(AuditableExecution.class);
    when(enforcer.execute(any())).thenReturn(new AuditableExecutionResult());
    this.cas = new DefaultCentralAuthenticationService(mock(ApplicationEventPublisher.class), ticketRegMock, smMock, mock(LogoutManager.class), factory, authenticationRequestServiceSelectionStrategies, new AcceptAnyAuthenticationPolicyFactory(), new DefaultPrincipalFactory(), null, enforcer);
    this.cas.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
}
Also used : AcceptAnyAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) AuditableExecution(org.apereo.cas.audit.AuditableExecution) ServicesManager(org.apereo.cas.services.ServicesManager) DefaultTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketFactory) TicketFactory(org.apereo.cas.ticket.TicketFactory) DefaultProxyGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyGrantingTicketFactory) DefaultProxyTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyTicketFactory) DefaultTransientSessionTicketFactory(org.apereo.cas.ticket.factory.DefaultTransientSessionTicketFactory) DefaultServiceTicketFactory(org.apereo.cas.ticket.factory.DefaultServiceTicketFactory) DefaultTicketGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketGrantingTicketFactory) Authentication(org.apereo.cas.authentication.Authentication) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) AuthenticationHandlerExecutionResult(org.apereo.cas.authentication.AuthenticationHandlerExecutionResult) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) AuditableExecutionResult(org.apereo.cas.audit.AuditableExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Before(org.junit.Before)

Aggregations

AcceptAnyAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory)3 HashMap (java.util.HashMap)2 lombok.val (lombok.val)2 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)2 Authentication (org.apereo.cas.authentication.Authentication)2 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)2 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)2 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)2 AuditableExecution (org.apereo.cas.audit.AuditableExecution)1 AuthenticationHandlerExecutionResult (org.apereo.cas.authentication.AuthenticationHandlerExecutionResult)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1 CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)1 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 DefaultServiceMatchingStrategy (org.apereo.cas.authentication.principal.DefaultServiceMatchingStrategy)1 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 ServiceContext (org.apereo.cas.services.ServiceContext)1 ServicesManager (org.apereo.cas.services.ServicesManager)1