Search in sources :

Example 86 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class WSFederationAuthenticationServiceSelectionStrategy method getReplyAsParameter.

private static Optional<NameValuePair> getReplyAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WREPLY)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 87 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class WSFederationMetadataUIAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    Service service = WebUtils.getService(requestContext);
    if (service != null) {
        service = serviceSelectionStrategy.resolveServiceFrom(service);
        final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
        if (registeredService instanceof WSFederationRegisteredService) {
            final WSFederationRegisteredService wsfed = WSFederationRegisteredService.class.cast(registeredService);
            WebUtils.putServiceUserInterfaceMetadata(requestContext, new DefaultRegisteredServiceUserInterfaceInfo(wsfed));
        }
    }
    return success();
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultRegisteredServiceUserInterfaceInfo(org.apereo.cas.web.flow.services.DefaultRegisteredServiceUserInterfaceInfo)

Example 88 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class SecurityTokenServiceAuthenticationMetaDataPopulator method populateAttributes.

@Override
public void populateAttributes(final AuthenticationBuilder builder, final AuthenticationTransaction transaction) {
    if (!this.selectionStrategy.supports(transaction.getService())) {
        return;
    }
    final Service service = this.selectionStrategy.resolveServiceFrom(transaction.getService());
    if (service != null) {
        final WSFederationRegisteredService rp = this.servicesManager.findServiceBy(service, WSFederationRegisteredService.class);
        if (rp == null || !rp.getAccessStrategy().isServiceAccessAllowed()) {
            LOGGER.warn("Service [{}] is not allowed to use SSO.", rp);
            throw new UnauthorizedSsoServiceException();
        }
        final SecurityTokenServiceClient sts = clientBuilder.buildClientForSecurityTokenRequests(rp);
        invokeSecurityTokenServiceForToken(transaction, builder, rp, sts);
    }
}
Also used : UnauthorizedSsoServiceException(org.apereo.cas.services.UnauthorizedSsoServiceException) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 89 with Service

use of org.apereo.cas.authentication.principal.Service in project cas by apereo.

the class WsFederationAction method prepareLoginViewWithWsFederationClients.

private void prepareLoginViewWithWsFederationClients(final RequestContext context) {
    final List<WsFedClient> clients = new ArrayList<>();
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
    final Service service = (Service) context.getFlowScope().get(CasProtocolConstants.PARAMETER_SERVICE);
    this.configurations.forEach(cfg -> {
        final WsFedClient c = new WsFedClient();
        c.setName(cfg.getName());
        final String id = UUID.randomUUID().toString();
        final String rpId = wsFederationHelper.getRelyingPartyIdentifier(service, cfg);
        c.setAuthorizationUrl(cfg.getAuthorizationUrl(rpId, id));
        c.setReplyingPartyId(rpId);
        c.setId(id);
        c.setRedirectUrl(WsFederationNavigationController.getRelativeRedirectUrlFor(cfg, service, request));
        c.setAutoRedirect(cfg.isAutoRedirect());
        clients.add(c);
    });
    context.getFlowScope().put("wsfedUrls", clients);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service)

Example 90 with Service

use of org.apereo.cas.authentication.principal.Service 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)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)173 RegisteredService (org.apereo.cas.services.RegisteredService)67 Test (org.junit.Test)61 Authentication (org.apereo.cas.authentication.Authentication)47 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)44 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)42 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)35 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)32 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)29 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)21 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)15 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)15 Credential (org.apereo.cas.authentication.Credential)13 Principal (org.apereo.cas.authentication.principal.Principal)13 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)12 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)12 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)12