Search in sources :

Example 41 with Service

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

the class DelegatedClientWebflowManager method store.

/**
 * Store.
 *
 * @param webContext the web context
 * @param client     the client
 * @return the ticket
 */
public Ticket store(final WebContext webContext, final BaseClient client) {
    final Map<String, Serializable> properties = new LinkedHashMap<>();
    final Service service = determineService(webContext);
    properties.put(CasProtocolConstants.PARAMETER_SERVICE, service);
    properties.put(this.themeParamName, StringUtils.defaultString(webContext.getRequestParameter(this.themeParamName)));
    properties.put(this.localParamName, StringUtils.defaultString(webContext.getRequestParameter(this.localParamName)));
    properties.put(CasProtocolConstants.PARAMETER_METHOD, StringUtils.defaultString(webContext.getRequestParameter(CasProtocolConstants.PARAMETER_METHOD)));
    final TransientSessionTicketFactory transientFactory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    final TransientSessionTicket ticket = transientFactory.create(service, properties);
    LOGGER.debug("Storing delegated authentication request ticket [{}] for service [{}] with properties [{}]", ticket.getId(), ticket.getService(), ticket.getProperties());
    this.ticketRegistry.addTicket(ticket);
    webContext.setRequestAttribute(PARAMETER_CLIENT_ID, ticket.getId());
    if (client instanceof SAML2Client) {
        webContext.getSessionStore().set(webContext, SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, ticket.getId());
    }
    if (client instanceof OAuth20Client) {
        final OAuth20Client oauthClient = (OAuth20Client) client;
        oauthClient.getConfiguration().setWithState(true);
        oauthClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof OidcClient) {
        final OidcClient oidcClient = (OidcClient) client;
        oidcClient.getConfiguration().setCustomParams(CollectionUtils.wrap(PARAMETER_CLIENT_ID, ticket.getId()));
        oidcClient.getConfiguration().setWithState(true);
        oidcClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof CasClient) {
        final CasClient casClient = (CasClient) client;
        casClient.getConfiguration().addCustomParam(DelegatedClientWebflowManager.PARAMETER_CLIENT_ID, ticket.getId());
    }
    return ticket;
}
Also used : TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) Serializable(java.io.Serializable) OidcClient(org.pac4j.oidc.client.OidcClient) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) SAML2Client(org.pac4j.saml.client.SAML2Client) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) LinkedHashMap(java.util.LinkedHashMap) CasClient(org.pac4j.cas.client.CasClient)

Example 42 with Service

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

the class DelegatedClientWebflowManager method restoreDelegatedAuthenticationRequest.

private Service restoreDelegatedAuthenticationRequest(final RequestContext requestContext, final WebContext webContext, final TransientSessionTicket ticket) {
    final Service service = ticket.getService();
    LOGGER.debug("Restoring requested service [{}] back in the authentication flow", service);
    requestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, service);
    webContext.setRequestAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
    webContext.setRequestAttribute(this.themeParamName, ticket.getProperties().get(this.themeParamName));
    webContext.setRequestAttribute(this.localParamName, ticket.getProperties().get(this.localParamName));
    webContext.setRequestAttribute(CasProtocolConstants.PARAMETER_METHOD, ticket.getProperties().get(CasProtocolConstants.PARAMETER_METHOD));
    return service;
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service)

Example 43 with Service

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

the class DelegatedClientAuthenticationActionTests method getServicesManagerWith.

private ServicesManager getServicesManagerWith(final Service service, final BaseClient client) {
    final ServicesManager mgr = mock(ServicesManager.class);
    final AbstractRegisteredService regSvc = RegisteredServiceTestUtils.getRegisteredService(service.getId());
    final DefaultRegisteredServiceAccessStrategy strategy = new DefaultRegisteredServiceAccessStrategy();
    strategy.setDelegatedAuthenticationPolicy(new DefaultRegisteredServiceDelegatedAuthenticationPolicy(CollectionUtils.wrapList(client.getName())));
    regSvc.setAccessStrategy(strategy);
    when(mgr.findServiceBy(any(Service.class))).thenReturn(regSvc);
    return mgr;
}
Also used : ServicesManager(org.apereo.cas.services.ServicesManager) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) DefaultRegisteredServiceDelegatedAuthenticationPolicy(org.apereo.cas.services.DefaultRegisteredServiceDelegatedAuthenticationPolicy) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)

Example 44 with Service

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

the class SamlMetadataUIParserAction method getRegisteredServiceFromRequest.

/**
 * Gets registered service from request.
 *
 * @param requestContext the request context
 * @return the registered service from request
 */
protected RegisteredService getRegisteredServiceFromRequest(final RequestContext requestContext) {
    final Service currentService = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(currentService);
    return registeredService;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service)

Example 45 with Service

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

the class DefaultOAuth2UserProfileDataCreator method getAccessTokenAuthenticationPrincipal.

/**
 * Gets access token authentication principal.
 *
 * @param accessToken the access token
 * @param context     the context
 * @return the access token authentication principal
 */
protected Principal getAccessTokenAuthenticationPrincipal(final AccessToken accessToken, final J2EContext context) {
    final Service service = accessToken.getService();
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
    final Principal currentPrincipal = accessToken.getAuthentication().getPrincipal();
    LOGGER.debug("Preparing user profile response based on CAS principal [{}]", currentPrincipal);
    final Principal principal = this.scopeToAttributesFilter.filter(accessToken.getService(), currentPrincipal, registeredService, context, accessToken);
    LOGGER.debug("Created CAS principal [{}] based on requested/authorized scopes", principal);
    return principal;
}
Also used : OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) Principal(org.apereo.cas.authentication.principal.Principal)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)162 lombok.val (lombok.val)54 RegisteredService (org.apereo.cas.services.RegisteredService)53 Authentication (org.apereo.cas.authentication.Authentication)44 Test (org.junit.Test)36 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)34 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)31 Slf4j (lombok.extern.slf4j.Slf4j)30 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)26 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)25 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)25 Test (org.junit.jupiter.api.Test)25 Optional (java.util.Optional)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 StringUtils (org.apache.commons.lang3.StringUtils)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)17 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)17 HashMap (java.util.HashMap)16