use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.
the class RedirectSAML2ClientTests method testSetComparisonTypeWithRedirectBinding.
@Test
public void testSetComparisonTypeWithRedirectBinding() {
final SAML2Client client = getClient();
client.getConfiguration().setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final RedirectAction action = client.getRedirectAction(context);
assertTrue(getInflatedAuthnRequest(action.getLocation()).contains("Comparison=\"exact\""));
}
use of org.pac4j.core.context.J2EContext in project cas by apereo.
the class SAML2ClientLogoutAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
try {
final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
final HttpServletResponse response = WebUtils.getHttpServletResponse(requestContext);
final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
final SAML2Client client = clients.findClient(SAML2Client.class);
if (client != null) {
LOGGER.debug("Located SAML2 client [{}]", client);
final RedirectAction action = client.getLogoutAction(context, null, null);
LOGGER.debug("Preparing logout message to send is [{}]", action.getLocation());
action.perform(context);
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return null;
}
use of org.pac4j.core.context.J2EContext in project cas by apereo.
the class OAuth20CallbackAuthorizeEndpointController method handleRequestInternal.
/**
* Handle request.
*
* @param request the request
* @param response the response
* @return the model and view
* @throws Exception the exception
*/
@GetMapping(path = OAuthConstants.BASE_OAUTH20_URL + '/' + OAuthConstants.CALLBACK_AUTHORIZE_URL)
public ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
this.callbackController.callback(request, response);
final String url = StringUtils.remove(response.getHeader("Location"), "redirect:");
final J2EContext ctx = WebUtils.getPac4jJ2EContext(request, response);
final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
return oAuth20CallbackAuthorizeViewResolver.resolve(ctx, manager, url);
}
use of org.pac4j.core.context.J2EContext in project cas by apereo.
the class OAuth20AccessTokenEndpointController method verifyAccessTokenRequest.
/**
* Verify the access token request.
*
* @param request the HTTP request
* @param response the HTTP response
* @return true, if successful
*/
private boolean verifyAccessTokenRequest(final HttpServletRequest request, final HttpServletResponse response) {
// must have the right grant type
final String grantType = request.getParameter(OAuthConstants.GRANT_TYPE);
if (!checkGrantTypes(grantType, OAuth20GrantTypes.AUTHORIZATION_CODE, OAuth20GrantTypes.PASSWORD, OAuth20GrantTypes.REFRESH_TOKEN)) {
return false;
}
// must be authenticated (client or user)
final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
final Optional<UserProfile> profile = manager.get(true);
if (profile == null || !profile.isPresent()) {
return false;
}
final UserProfile uProfile = profile.get();
// authorization code grant type
if (isGrantType(grantType, OAuth20GrantTypes.AUTHORIZATION_CODE)) {
final String clientId = uProfile.getId();
final String redirectUri = request.getParameter(OAuthConstants.REDIRECT_URI);
final OAuthRegisteredService registeredService = OAuthUtils.getRegisteredOAuthService(getServicesManager(), clientId);
return uProfile instanceof OAuthClientProfile && getValidator().checkParameterExist(request, OAuthConstants.REDIRECT_URI) && getValidator().checkParameterExist(request, OAuthConstants.CODE) && getValidator().checkCallbackValid(registeredService, redirectUri);
} else if (isGrantType(grantType, OAuth20GrantTypes.REFRESH_TOKEN)) {
// refresh token grant type
return uProfile instanceof OAuthClientProfile && getValidator().checkParameterExist(request, OAuthConstants.REFRESH_TOKEN);
} else {
final String clientId = request.getParameter(OAuthConstants.CLIENT_ID);
final OAuthRegisteredService registeredService = OAuthUtils.getRegisteredOAuthService(getServicesManager(), clientId);
// resource owner password grant type
return uProfile instanceof OAuthUserProfile && getValidator().checkParameterExist(request, OAuthConstants.CLIENT_ID) && getValidator().checkServiceValid(registeredService);
}
}
use of org.pac4j.core.context.J2EContext in project cas by apereo.
the class CasConsentReviewController method callback.
/**
* Endpoint for Cas Client Callback.
*
* @param request the request
* @param response the response
*/
@GetMapping("/callback")
public void callback(final HttpServletRequest request, final HttpServletResponse response) {
LOGGER.debug("Callback endpoint hit...");
final CallbackLogic logic = this.pac4jConfig.getCallbackLogic();
final J2EContext context = Pac4jUtils.getPac4jJ2EContext(request, response);
final String defaultUrl = this.casProperties.getServer().getPrefix().concat("/consentReview");
logic.perform(context, this.pac4jConfig, J2ENopHttpActionAdapter.INSTANCE, defaultUrl, false, false, false, null);
}
Aggregations