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;
}
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);
}
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);
}
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));
}
Aggregations