use of org.pac4j.core.http.ajax.DefaultAjaxRequestResolver in project pac4j by pac4j.
the class ClientsTests method testValuesSet.
@Test
public void testValuesSet() {
MockIndirectClient facebookClient = newFacebookClient();
final Clients clients = new Clients(facebookClient);
final AjaxRequestResolver ajaxRequestResolver = new DefaultAjaxRequestResolver();
final UrlResolver urlResolver = new DefaultUrlResolver();
final CallbackUrlResolver callbackUrlResolver = new QueryParameterCallbackUrlResolver();
final AuthorizationGenerator authorizationGenerator = (context, profile) -> profile;
clients.setCallbackUrl(CALLBACK_URL);
clients.setAjaxRequestResolver(ajaxRequestResolver);
clients.setUrlResolver(urlResolver);
clients.setCallbackUrlResolver(callbackUrlResolver);
clients.addAuthorizationGenerator(authorizationGenerator);
clients.init();
assertEquals(CALLBACK_URL, facebookClient.getCallbackUrl());
assertEquals(urlResolver, facebookClient.getUrlResolver());
assertEquals(callbackUrlResolver, facebookClient.getCallbackUrlResolver());
assertEquals(ajaxRequestResolver, facebookClient.getAjaxRequestResolver());
assertEquals(authorizationGenerator, facebookClient.getAuthorizationGenerators().get(0));
}
use of org.pac4j.core.http.ajax.DefaultAjaxRequestResolver in project pac4j by pac4j.
the class IndirectClient method internalInit.
@Override
protected final void internalInit() {
// check configuration
CommonHelper.assertNotBlank("callbackUrl", this.callbackUrl, "set it up either on this IndirectClient or on the global Config");
if (this.urlResolver == null) {
this.urlResolver = new DefaultUrlResolver();
}
if (this.callbackUrlResolver == null) {
this.callbackUrlResolver = new QueryParameterCallbackUrlResolver();
}
if (this.ajaxRequestResolver == null) {
ajaxRequestResolver = new DefaultAjaxRequestResolver();
}
clientInit();
// ensures components have been properly initialized
CommonHelper.assertNotNull("redirectActionBuilder", this.redirectActionBuilder);
CommonHelper.assertNotNull("credentialsExtractor", getCredentialsExtractor());
CommonHelper.assertNotNull("authenticator", getAuthenticator());
CommonHelper.assertNotNull("profileCreator", getProfileCreator());
CommonHelper.assertNotNull("logoutActionBuilder", this.logoutActionBuilder);
}
use of org.pac4j.core.http.ajax.DefaultAjaxRequestResolver in project ddf by codice.
the class OidcLogoutActionProvider method getAction.
/**
* *
*
* @param <T> is a Map<String, Subject>
* @param subjectMap containing the corresponding subject
* @return OidcLogoutActionProvider containing the logout url
*/
@Override
public <T> Action getAction(T subjectMap) {
if (!canHandle(subjectMap)) {
return null;
}
String logoutUrlString = "";
URL logoutUrl = null;
try {
HttpServletRequest request = (HttpServletRequest) ((Map) subjectMap).get("http_request");
HttpServletResponse response = (HttpServletResponse) ((Map) subjectMap).get("http_response");
JEESessionStore sessionStore = new JEESessionStore();
JEEContext jeeContext = new JEEContext(request, response, sessionStore);
HttpSession session = request.getSession(false);
PrincipalHolder principalHolder = null;
if (session != null) {
principalHolder = (PrincipalHolder) session.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY);
}
OidcProfile oidcProfile = null;
if (principalHolder != null && principalHolder.getPrincipals() != null) {
Collection<SecurityAssertion> securityAssertions = principalHolder.getPrincipals().byType(SecurityAssertion.class);
for (SecurityAssertion securityAssertion : securityAssertions) {
if (SecurityAssertionJwt.JWT_TOKEN_TYPE.equals(securityAssertion.getTokenType())) {
oidcProfile = (OidcProfile) securityAssertion.getToken();
break;
}
}
}
if (oidcProfile == null) {
throw new IllegalStateException("Unable to determine OIDC profile for logout");
}
OidcLogoutActionBuilder logoutActionBuilder = handlerConfiguration.getOidcLogoutActionBuilder();
logoutActionBuilder.setAjaxRequestResolver(new DefaultAjaxRequestResolver() {
@Override
public boolean isAjax(final WebContext context) {
return false;
}
});
URIBuilder urlBuilder = new URIBuilder(SystemBaseUrl.EXTERNAL.constructUrl("/oidc/logout", true));
String prevUrl = getPreviousUrl(request);
if (prevUrl != null) {
urlBuilder.addParameter(PREV_URL, prevUrl);
}
RedirectionAction logoutAction = logoutActionBuilder.getLogoutAction(jeeContext, oidcProfile, urlBuilder.build().toString()).orElse(null);
if (logoutAction instanceof WithLocationAction) {
logoutUrlString = ((WithLocationAction) logoutAction).getLocation();
}
logoutUrl = new URL(logoutUrlString);
} catch (MalformedURLException | URISyntaxException e) {
LOGGER.info("Unable to resolve logout URL: {}", logoutUrlString);
} catch (ClassCastException e) {
LOGGER.debug("Unable to cast parameter to Map<String, Object>, {}", subjectMap, e);
}
return new ActionImpl(ID, TITLE, DESCRIPTION, logoutUrl);
}
Aggregations