Search in sources :

Example 1 with DefaultUrlResolver

use of org.pac4j.core.http.url.DefaultUrlResolver 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));
}
Also used : TestsConstants(org.pac4j.core.util.TestsConstants) CommonProfile(org.pac4j.core.profile.CommonProfile) TestsHelper(org.pac4j.core.util.TestsHelper) Test(org.junit.Test) AjaxRequestResolver(org.pac4j.core.http.ajax.AjaxRequestResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) ArrayList(java.util.ArrayList) RedirectAction(org.pac4j.core.redirect.RedirectAction) List(java.util.List) UrlResolver(org.pac4j.core.http.url.UrlResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Credentials(org.pac4j.core.credentials.Credentials) Assert(org.junit.Assert) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) UrlResolver(org.pac4j.core.http.url.UrlResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) AjaxRequestResolver(org.pac4j.core.http.ajax.AjaxRequestResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Test(org.junit.Test)

Example 2 with DefaultUrlResolver

use of org.pac4j.core.http.url.DefaultUrlResolver in project pac4j by pac4j.

the class QueryParameterCallbackUrlResolverTests method testComputeCallbackUrlAlreadyDefined.

@Test
public void testComputeCallbackUrlAlreadyDefined() {
    final String callbackUrl = CALLBACK_URL + '?' + Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER + "=cn";
    final String url = resolver.compute(new DefaultUrlResolver(), callbackUrl, CLIENT_NAME, MockWebContext.create());
    assertEquals(callbackUrl, url);
}
Also used : DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) Test(org.junit.Test)

Example 3 with DefaultUrlResolver

use of org.pac4j.core.http.url.DefaultUrlResolver in project pac4j by pac4j.

the class QueryParameterCallbackUrlResolverTests method testParams.

@Test
public void testParams() {
    final String url = new QueryParameterCallbackUrlResolver(ImmutableMap.of("param1", "value", "param2", "value2")).compute(new DefaultUrlResolver(), CALLBACK_URL, CLIENT_NAME, MockWebContext.create());
    assertEquals(CALLBACK_URL + '?' + Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER + '=' + CLIENT_NAME + "&param1=value&param2=value2", url);
}
Also used : DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) Test(org.junit.Test)

Example 4 with DefaultUrlResolver

use of org.pac4j.core.http.url.DefaultUrlResolver in project pac4j by pac4j.

the class CasConfiguration method internalInit.

@Override
protected void internalInit() {
    if (CommonHelper.isBlank(this.loginUrl) && CommonHelper.isBlank(this.prefixUrl) && CommonHelper.isBlank(this.restUrl)) {
        throw new TechnicalException("loginUrl, prefixUrl and restUrl cannot be all blank");
    }
    if (urlResolver == null) {
        urlResolver = new DefaultUrlResolver();
    }
    initializeClientConfiguration();
    initializeLogoutHandler();
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver)

Example 5 with DefaultUrlResolver

use of org.pac4j.core.http.url.DefaultUrlResolver 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);
}
Also used : DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)

Aggregations

DefaultUrlResolver (org.pac4j.core.http.url.DefaultUrlResolver)9 Test (org.junit.Test)6 DefaultAjaxRequestResolver (org.pac4j.core.http.ajax.DefaultAjaxRequestResolver)2 QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assert (org.junit.Assert)1 AuthorizationGenerator (org.pac4j.core.authorization.generator.AuthorizationGenerator)1 Config (org.pac4j.core.config.Config)1 Credentials (org.pac4j.core.credentials.Credentials)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1 AjaxRequestResolver (org.pac4j.core.http.ajax.AjaxRequestResolver)1 CallbackUrlResolver (org.pac4j.core.http.callback.CallbackUrlResolver)1 NoParameterCallbackUrlResolver (org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)1 UrlResolver (org.pac4j.core.http.url.UrlResolver)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 RedirectAction (org.pac4j.core.redirect.RedirectAction)1 TestsConstants (org.pac4j.core.util.TestsConstants)1 TestsHelper (org.pac4j.core.util.TestsHelper)1 OidcClient (org.pac4j.oidc.client.OidcClient)1