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