use of org.apereo.cas.services.ServicesManager in project cas by apereo.
the class GenericSuccessViewActionTests method verifyValidPrincipal.
@Test
public void verifyValidPrincipal() throws InvalidTicketException {
final CentralAuthenticationService cas = mock(CentralAuthenticationService.class);
final ServicesManager mgr = mock(ServicesManager.class);
final ServiceFactory factory = mock(ServiceFactory.class);
final Authentication authn = mock(Authentication.class);
when(authn.getPrincipal()).thenReturn(CoreAuthenticationTestUtils.getPrincipal("cas"));
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getAuthentication()).thenReturn(authn);
when(cas.getTicket(any(String.class), any(Ticket.class.getClass()))).thenReturn(tgt);
final GenericSuccessViewAction action = new GenericSuccessViewAction(cas, mgr, factory, "");
final Principal p = action.getAuthenticationPrincipal("TGT-1");
assertNotNull(p);
assertEquals(p.getId(), "cas");
}
use of org.apereo.cas.services.ServicesManager in project cas by apereo.
the class SamlIdPUtils method getMetadataResolverForAllSamlServices.
/**
* Gets chaining metadata resolver for all saml services.
*
* @param servicesManager the services manager
* @param entityID the entity id
* @param resolver the resolver
* @return the chaining metadata resolver for all saml services
*/
public static MetadataResolver getMetadataResolverForAllSamlServices(final ServicesManager servicesManager, final String entityID, final SamlRegisteredServiceCachingMetadataResolver resolver) {
try {
final Collection<RegisteredService> registeredServices = servicesManager.findServiceBy(SamlRegisteredService.class::isInstance);
final List<MetadataResolver> resolvers;
final ChainingMetadataResolver chainingMetadataResolver = new ChainingMetadataResolver();
resolvers = registeredServices.stream().filter(SamlRegisteredService.class::isInstance).map(SamlRegisteredService.class::cast).map(s -> SamlRegisteredServiceServiceProviderMetadataFacade.get(resolver, s, entityID)).filter(Optional::isPresent).map(Optional::get).map(SamlRegisteredServiceServiceProviderMetadataFacade::getMetadataResolver).collect(Collectors.toList());
LOGGER.debug("Located [{}] metadata resolvers to match against [{}]", resolvers, entityID);
chainingMetadataResolver.setResolvers(resolvers);
chainingMetadataResolver.setId(entityID);
chainingMetadataResolver.initialize();
return chainingMetadataResolver;
} catch (final Exception e) {
throw new RuntimeException(new SamlException(e.getMessage(), e));
}
}
use of org.apereo.cas.services.ServicesManager in project cas by apereo.
the class GoogleAccountsServiceTests method getGoogleAccountsService.
public GoogleAccountsService getGoogleAccountsService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final String samlRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" " + "ID=\"5545454455\" Version=\"2.0\" IssueInstant=\"Value\" " + "ProtocolBinding=\"urn:oasis:names.tc:SAML:2.0:bindings:HTTP-Redirect\" " + "ProviderName=\"https://localhost:8443/myRutgers\" AssertionConsumerServiceURL=\"https://localhost:8443/myRutgers\"/>";
request.setParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, encodeMessage(samlRequest));
request.setParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "RelayStateAddedHere");
final RegisteredService regSvc = mock(RegisteredService.class);
when(regSvc.getUsernameAttributeProvider()).thenReturn(new DefaultRegisteredServiceUsernameProvider());
final ServicesManager servicesManager = mock(ServicesManager.class);
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(regSvc);
return (GoogleAccountsService) factory.createService(request);
}
Aggregations