Search in sources :

Example 1 with UrlResolver

use of org.pac4j.core.http.url.UrlResolver 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 UrlResolver

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

the class CasClientTests method testCallbackUrlResolver.

@Test
public void testCallbackUrlResolver() {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setPrefixUrl(CAS);
    configuration.setLoginUrl(CAS + LOGIN);
    final CasClient 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 Assert (org.junit.Assert)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 Credentials (org.pac4j.core.credentials.Credentials)1 AjaxRequestResolver (org.pac4j.core.http.ajax.AjaxRequestResolver)1 DefaultAjaxRequestResolver (org.pac4j.core.http.ajax.DefaultAjaxRequestResolver)1 QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)1 DefaultUrlResolver (org.pac4j.core.http.url.DefaultUrlResolver)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