jee-pac4j-demo how to set callbackUrl

58 views
Skip to first unread message

S Zhou

unread,
May 13, 2020, 4:03:35 PM5/13/20
to Pac4j users mailing list
Hello!

Based on jee-pac4j-demo project, I wrote two java classes and put them into my existing web-based(servlet/jsp) java application. When I hit this application in a browser, I got below error:

org.pac4j.core.exception.TechnicalException: callbackUrl cannot be blank: set it up either on this IndirectClient or on the global Config

It tells me that I doesn't set callback url properly. Could anyone let me know what I did wrong? Followings are two related classes and parts of web.xml. Thanks.

public class SAMLConfigFactory {

   public static Config build() {
SAML2Configuration cfg = new SAML2Configuration();
        cfg.setKeystoreResourceFilepath("samlKeystore.jks");
        cfg.setKeystorePassword("pac4j-demo-passwd");
        cfg.setPrivateKeyPassword("pac4j-demo-passwd");
        cfg.setIdentityProviderMetadataPath("samltest-providers.xml");
        cfg.setServiceProviderMetadataPath(new File("sp-metadata.xml").getAbsolutePath());

        final SAML2Client saml2Client = new SAML2Client(cfg);
        final Clients clients = new Clients("http://localhost:8080/myapp", saml2Client);
        Config config = new Config(clients);
     
        return config;
   }
}

public class ForceLoginFilter extends AbstractConfigFilter {
    @Override
    public void init(final FilterConfig filterConfig) throws ServletException {
    }

    @Override
    protected void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
            final FilterChain chain) throws IOException, ServletException {

        final JEEContext context = new JEEContext(request, response);
        Config cfg = SAMLConfigFactory.build();
      List<Client> clientList = cfg.getClients().getClients();
        SAML2Client client = (SAML2Client)clientList.get(0);
        HttpAction action = (HttpAction) client.getRedirectionAction(context).get();
        JEEHttpActionAdapter.INSTANCE.adapt(action, context);
    }
}

web.xml

    <filter>
        <filter-name>callbackFilter</filter-name>
        <filter-class>org.pac4j.jee.filter.CallbackFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>callbackFilter</filter-name>
        <url-pattern>/callback</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <filter>
        <filter-name>ForceLoginFilter</filter-name>
        <filter-class>com.abc.xyz.ForceLoginFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ForceLoginFilter</filter-name>
        <url-pattern>*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

Jérôme LELEU

unread,
May 14, 2020, 2:51:34 AM5/14/20
to S Zhou, Pac4j users mailing list
Hi,

I don't understand how you can get that. The client should auto-initialize itself. And the callback URL is set thanks to : new Clients("http://localhost:8080/myapp", saml2Client);

Can you copy/paste the full stack trace?

Thanks.
Best regards,
Jérôme



--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pac4j-users/f60bf9c4-8ac6-41b2-b175-33f6f0c2bfc8%40googlegroups.com.

S Zhou

unread,
May 14, 2020, 8:22:31 AM5/14/20
to Pac4j users mailing list
Good morning!

There is no errors in console window. Below is the info displayed on browser. 

Type Exception Report

Message callbackUrl cannot be blank: set it up either on this IndirectClient or on the global Config

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.pac4j.core.exception.TechnicalException: callbackUrl cannot be blank: set it up either on this IndirectClient or on the global Config
	org.pac4j.core.util.CommonHelper.assertTrue(CommonHelper.java:107)
	org.pac4j.core.util.CommonHelper.assertNotBlank(CommonHelper.java:119)
	org.pac4j.core.client.IndirectClient.internalInit(IndirectClient.java:52)
	org.pac4j.core.util.InitializableObject.init(InitializableObject.java:20)
	org.pac4j.core.client.IndirectClient.getRedirectionAction(IndirectClient.java:91)
	gov.cis.nps.icamssoclient.ForceLoginFilter.internalFilter(ForceLoginFilter.java:46)
	org.pac4j.jee.filter.AbstractConfigFilter.doFilter(AbstractConfigFilter.java:70)

Note The full stack trace of the root cause is available in the server logs.


By the way, here are two lines in my samltest-provider.xml. I am not sure if they are right. Is there any other places I should put callback url?

<!-- The entity describing the SAMLtest IdP, named by the entityID below -->
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui" entityID="https://samltest.id/saml/idp">

<!-- This is the metadata for the SAMLtest SP, named by entityID -->
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://localhost:8080/myApp">

Thank you for your time and help.

Jérôme LELEU

unread,
May 14, 2020, 10:37:46 AM5/14/20
to S Zhou, Pac4j users mailing list
Hi,

You must call the init() on the Clients component before using the getRedirectionAction method.
Thanks.
Best regards,
Jérôme


--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.

S Zhou

unread,
May 15, 2020, 12:13:39 AM5/15/20
to Pac4j users mailing list
I added client.init(); in front of client.getRedirectionAction(); but I got the same error.
Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j...@googlegroups.com.

Jérôme LELEU

unread,
May 15, 2020, 2:14:29 AM5/15/20
to S Zhou, Pac4j users mailing list
Hi,

I wrote about the Clients component, not about the SAML2Client.

clients.init();

Thanks.
Best regards,
Jérôme


To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pac4j-users/674bb2d4-c1bb-4aad-8601-7c8486e3ec58%40googlegroups.com.

S Zhou

unread,
May 15, 2020, 9:24:21 AM5/15/20
to Pac4j users mailing list
The issue got fixed after clients.init() was added. Thanks!
Reply all
Reply to author
Forward
0 new messages