use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20DefaultCasAuthenticationBuilderTests method verifyOperationByService.
@Test
public void verifyOperationByService() {
val request = new MockHttpServletRequest();
request.addHeader("X-".concat(CasProtocolConstants.PARAMETER_SERVICE), service.getServiceId());
val ctx = new JEEContext(request, new MockHttpServletResponse());
val result = authenticationBuilder.buildService(service, ctx, true);
assertNotNull(result);
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class OAuth20ClientIdAwareProfileManagerTests method init.
@BeforeEach
public void init() {
val request = new MockHttpServletRequest();
request.addParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
val response = new MockHttpServletResponse();
context = new JEEContext(request, response);
profileManager = new OAuth20ClientIdAwareProfileManager(context, oauthDistributedSessionStore, servicesManager);
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DefaultDelegatedAuthenticationNavigationController method redirectToProvider.
/**
* Redirect to provider. Receive the client name from the request and then try to determine and build the endpoint url
* for the redirection. The redirection data/url must contain a delegated client ticket id so that the request be can
* restored on the trip back. SAML clients use the relay-state session attribute while others use request parameters.
*
* @param request the request
* @param response the response
* @return the view
*/
@GetMapping(DelegatedClientIdentityProviderConfigurationFactory.ENDPOINT_URL_REDIRECT)
public View redirectToProvider(final HttpServletRequest request, final HttpServletResponse response) {
var clientName = request.getParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER);
if (StringUtils.isBlank(clientName)) {
clientName = (String) request.getAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER);
}
try {
if (StringUtils.isBlank(clientName)) {
throw new UnauthorizedServiceException("No client name parameter is provided in the incoming request");
}
val clientResult = getConfigurationContext().getClients().findClient(clientName);
if (clientResult.isEmpty()) {
throw new UnauthorizedServiceException("Unable to locate client " + clientName);
}
val client = IndirectClient.class.cast(clientResult.get());
client.init();
val webContext = new JEEContext(request, response);
val ticket = delegatedClientAuthenticationWebflowManager.store(webContext, client);
return getResultingView(client, webContext, ticket);
} catch (final Exception e) {
val message = String.format("Authentication request was denied from the provider %s", clientName);
LoggingUtils.warn(LOGGER, message, e);
throw new UnauthorizedServiceException(e.getMessage(), e);
}
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DefaultDelegatedClientIdentityProviderConfigurationProducer method produce.
@Override
public Optional<DelegatedClientIdentityProviderConfiguration> produce(final RequestContext requestContext, final IndirectClient client) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val webContext = new JEEContext(request, response);
val currentService = WebUtils.getService(requestContext);
LOGGER.debug("Initializing client [{}] with request parameters [{}] and service [{}]", client, requestContext.getRequestParameters(), currentService);
client.init();
if (delegatedClientAuthenticationRequestCustomizers.isEmpty() || delegatedClientAuthenticationRequestCustomizers.stream().anyMatch(c -> c.isAuthorized(webContext, client, currentService))) {
return DelegatedClientIdentityProviderConfigurationFactory.builder().client(client).webContext(webContext).service(currentService).casProperties(casProperties).build().resolve();
}
return Optional.empty();
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DelegatedAuthenticationClientLogoutAction method doPreExecute.
@Override
protected Event doPreExecute(final RequestContext requestContext) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val context = new JEEContext(request, response);
val currentProfile = findCurrentProfile(context);
val clientResult = currentProfile == null ? Optional.<Client>empty() : clients.findClient(currentProfile.getClientName());
if (clientResult.isPresent()) {
val client = clientResult.get();
LOGGER.debug("Handling logout for delegated authentication client [{}]", client);
WebUtils.putDelegatedAuthenticationClientName(requestContext, client.getName());
sessionStore.set(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE, client.getName());
}
return null;
}
Aggregations