Search in sources :

Example 1 with DefaultAuthenticationServiceSelectionPlan

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan in project cas by apereo.

the class CasCoreConfiguration method authenticationServiceSelectionPlan.

@ConditionalOnMissingBean(name = "authenticationServiceSelectionPlan")
@Autowired
@Bean
public AuthenticationServiceSelectionPlan authenticationServiceSelectionPlan(final List<AuthenticationServiceSelectionStrategyConfigurer> configurers) {
    final DefaultAuthenticationServiceSelectionPlan plan = new DefaultAuthenticationServiceSelectionPlan();
    configurers.forEach(c -> {
        final String name = StringUtils.removePattern(c.getClass().getSimpleName(), "\\$.+");
        LOGGER.debug("Configuring authentication request service selection strategy plan [{}]", name);
        c.configureAuthenticationServiceSelectionStrategy(plan);
    });
    return plan;
}
Also used : DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) Autowired(org.springframework.beans.factory.annotation.Autowired) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with DefaultAuthenticationServiceSelectionPlan

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan in project cas by apereo.

the class FrontChannelLogoutActionTests method onSetUp.

@Before
public void onSetUp() throws Exception {
    final DefaultSingleLogoutServiceMessageHandler handler = new DefaultSingleLogoutServiceMessageHandler(new SimpleHttpClientFactoryBean().getObject(), new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(), false, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final LogoutManagerImpl logoutManager = new LogoutManagerImpl(new SamlCompliantLogoutMessageCreator(), handler, false);
    this.frontChannelLogoutAction = new FrontChannelLogoutAction(logoutManager);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.requestContext = mock(RequestContext.class);
    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(this.requestContext.getExternalContext()).thenReturn(servletExternalContext);
    when(servletExternalContext.getNativeRequest()).thenReturn(request);
    when(servletExternalContext.getNativeResponse()).thenReturn(response);
    final LocalAttributeMap flowScope = new LocalAttributeMap();
    when(this.requestContext.getFlowScope()).thenReturn(flowScope);
    final MockFlowExecutionKey mockFlowExecutionKey = new MockFlowExecutionKey(FLOW_EXECUTION_KEY);
    final MockFlowExecutionContext mockFlowExecutionContext = new MockFlowExecutionContext();
    mockFlowExecutionContext.setKey(mockFlowExecutionKey);
    when(this.requestContext.getFlowExecutionContext()).thenReturn(mockFlowExecutionContext);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockFlowExecutionKey(org.springframework.webflow.test.MockFlowExecutionKey) DefaultSingleLogoutServiceMessageHandler(org.apereo.cas.logout.DefaultSingleLogoutServiceMessageHandler) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSingleLogoutServiceLogoutUrlBuilder(org.apereo.cas.logout.DefaultSingleLogoutServiceLogoutUrlBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) SamlCompliantLogoutMessageCreator(org.apereo.cas.logout.SamlCompliantLogoutMessageCreator) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) LogoutManagerImpl(org.apereo.cas.logout.LogoutManagerImpl) Before(org.junit.Before)

Example 3 with DefaultAuthenticationServiceSelectionPlan

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan in project cas by apereo.

the class LogoutManagerImplTests method setUp.

@Before
public void setUp() {
    when(client.isValidEndPoint(any(String.class))).thenReturn(true);
    when(client.isValidEndPoint(any(URL.class))).thenReturn(true);
    when(client.sendMessageToEndPoint(any(HttpMessage.class))).thenReturn(true);
    singleLogoutServiceMessageHandler = new DefaultSingleLogoutServiceMessageHandler(client, new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(), true, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final Map<String, Service> services = new HashMap<>();
    this.simpleWebApplicationServiceImpl = RegisteredServiceTestUtils.getService(URL);
    services.put(ID, this.simpleWebApplicationServiceImpl);
    when(this.tgt.getServices()).thenReturn(services);
    this.logoutManager = new LogoutManagerImpl(new SamlCompliantLogoutMessageCreator(), singleLogoutServiceMessageHandler, false);
    this.registeredService = RegisteredServiceTestUtils.getRegisteredService(URL);
    when(servicesManager.findServiceBy(this.simpleWebApplicationServiceImpl)).thenReturn(this.registeredService);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) HttpMessage(org.apereo.cas.util.http.HttpMessage) URL(java.net.URL) Before(org.junit.Before)

Example 4 with DefaultAuthenticationServiceSelectionPlan

use of org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan 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

DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)4 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 Service (org.apereo.cas.authentication.principal.Service)2 URL (java.net.URL)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 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)1 HandlerResult (org.apereo.cas.authentication.HandlerResult)1 AcceptAnyAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory)1 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 DefaultSingleLogoutServiceLogoutUrlBuilder (org.apereo.cas.logout.DefaultSingleLogoutServiceLogoutUrlBuilder)1 DefaultSingleLogoutServiceMessageHandler (org.apereo.cas.logout.DefaultSingleLogoutServiceMessageHandler)1 LogoutManagerImpl (org.apereo.cas.logout.LogoutManagerImpl)1 SamlCompliantLogoutMessageCreator (org.apereo.cas.logout.SamlCompliantLogoutMessageCreator)1 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)1