Search in sources :

Example 1 with CallbackUrlResolver

use of org.pac4j.core.http.callback.CallbackUrlResolver in project pac4j by pac4j.

the class ClientsTests method testValuesSet.

@Test
public void testValuesSet() {
    var facebookClient = newFacebookClient();
    final var clients = new Clients(facebookClient);
    final AjaxRequestResolver ajaxRequestResolver = new DefaultAjaxRequestResolver();
    final UrlResolver urlResolver = new DefaultUrlResolver();
    final CallbackUrlResolver callbackUrlResolver = new QueryParameterCallbackUrlResolver();
    final AuthorizationGenerator authorizationGenerator = (context, store, profile) -> Optional.of(profile);
    clients.setCallbackUrl(CALLBACK_URL);
    clients.setAjaxRequestResolver(ajaxRequestResolver);
    clients.setUrlResolver(urlResolver);
    clients.setCallbackUrlResolver(callbackUrlResolver);
    clients.addAuthorizationGenerator(authorizationGenerator);
    clients.findAllClients();
    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) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test) AjaxRequestResolver(org.pac4j.core.http.ajax.AjaxRequestResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) ArrayList(java.util.ArrayList) List(java.util.List) UrlResolver(org.pac4j.core.http.url.UrlResolver) Ignore(org.junit.Ignore) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Optional(java.util.Optional) TechnicalException(org.pac4j.core.exception.TechnicalException) Assert(org.junit.Assert) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver) 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) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver) 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) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Test(org.junit.Test)

Example 2 with CallbackUrlResolver

use of org.pac4j.core.http.callback.CallbackUrlResolver in project pac4j by pac4j.

the class CasClientTests method testCallbackUrlResolver.

@Test
public void testCallbackUrlResolver() {
    final var configuration = new CasConfiguration();
    configuration.setPrefixUrl(CAS);
    configuration.setLoginUrl(CAS + LOGIN);
    final var casClient = new CasClient(configuration);
    casClient.setCallbackUrl(CASBACK);
    casClient.setUrlResolver((url, context) -> HOST + url);
    casClient.setCallbackUrlResolver(new CallbackUrlResolver() {

        @Override
        public String compute(final UrlResolver urlResolver, final String url, final String clientName, final WebContext context) {
            return null;
        }

        @Override
        public boolean matches(final String clientName, final WebContext context) {
            return false;
        }
    });
    casClient.init();
    assertEquals(HOST + CAS + LOGIN, configuration.computeFinalLoginUrl(null));
    assertEquals(HOST + CAS + "/", configuration.computeFinalPrefixUrl(null));
}
Also used : UrlResolver(org.pac4j.core.http.url.UrlResolver) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 CallbackUrlResolver (org.pac4j.core.http.callback.CallbackUrlResolver)2 UrlResolver (org.pac4j.core.http.url.UrlResolver)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Assert (org.junit.Assert)1 Ignore (org.junit.Ignore)1 CasConfiguration (org.pac4j.cas.config.CasConfiguration)1 AuthorizationGenerator (org.pac4j.core.authorization.generator.AuthorizationGenerator)1 MockWebContext (org.pac4j.core.context.MockWebContext)1 WebContext (org.pac4j.core.context.WebContext)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1 FoundAction (org.pac4j.core.exception.http.FoundAction)1 AjaxRequestResolver (org.pac4j.core.http.ajax.AjaxRequestResolver)1 DefaultAjaxRequestResolver (org.pac4j.core.http.ajax.DefaultAjaxRequestResolver)1 NoParameterCallbackUrlResolver (org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)1 QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)1 DefaultUrlResolver (org.pac4j.core.http.url.DefaultUrlResolver)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1