Search in sources :

Example 6 with ServicesManager

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");
}
Also used : ServicesManager(org.apereo.cas.services.ServicesManager) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Example 7 with ServicesManager

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));
    }
}
Also used : MessageContext(org.opensaml.messaging.context.MessageContext) Arrays(java.util.Arrays) BindingCriterion(org.opensaml.saml.criterion.BindingCriterion) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) LoggerFactory(org.slf4j.LoggerFactory) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) StringUtils(org.apache.commons.lang3.StringUtils) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) ServicesManager(org.apereo.cas.services.ServicesManager) AssertionConsumerServiceBuilder(org.opensaml.saml.saml2.metadata.impl.AssertionConsumerServiceBuilder) Logger(org.slf4j.Logger) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Collection(java.util.Collection) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) RequestAbstractType(org.opensaml.saml.saml2.core.RequestAbstractType) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) Endpoint(org.opensaml.saml.saml2.metadata.Endpoint) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) List(java.util.List) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SAMLEndpointContext(org.opensaml.saml.common.messaging.context.SAMLEndpointContext) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SAMLPeerEntityContext(org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext) Optional(java.util.Optional) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Optional(java.util.Optional) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)

Example 8 with ServicesManager

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);
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) ServicesManager(org.apereo.cas.services.ServicesManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultRegisteredServiceUsernameProvider(org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Aggregations

ServicesManager (org.apereo.cas.services.ServicesManager)8 RegisteredService (org.apereo.cas.services.RegisteredService)5 Service (org.apereo.cas.authentication.principal.Service)4 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Authentication (org.apereo.cas.authentication.Authentication)2 NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)2 Principal (org.apereo.cas.authentication.principal.Principal)2 ServiceFactory (org.apereo.cas.authentication.principal.ServiceFactory)2 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 Before (org.junit.Before)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1