SAML based SSO for a Single page application (angular JS) + ADFS

1,568 views
Skip to first unread message

Akshay

unread,
Oct 12, 2017, 2:25:41 PM10/12/17
to Pac4j users mailing list
Hello!

We are implementing a SAML based SSO using ADFS. We have a single page application(SPA) on the client side implemented using angular 4. And our RESTful API is secured by Pac4j. We are facing a few difficulties with handling the AJAX requests. Here is what we are doing - 

We make an AJAX call to a protected URL. A 401 is returned (because it is the default behaviour of the DefaultAjaxRequestResolver?). When we get a 401 on the client side, we call a protected URL(a controller whose only job is to redirect back to the front end application after authentication) at the window level, which triggers authentication via ADFS.

But the issue is, even after the user is authenticated, for every AJAX call that is made, a 401 is returned.

1) Is this the expected behaviour?
2) If so, what is the alternate solution? I understand that we can specify another behaviour using a custom AjaxRequestResolver. But, I'm not sure how I should go about it.
3) Is there any other way I can solve this problem?

Any help would be greatly appreciated :)

Jérôme LELEU

unread,
Oct 13, 2017, 9:47:00 AM10/13/17
to Akshay, Pac4j users mailing list
Hi,

After the successful ADFS authentication, the user profile has been saved in the session, but by default web services do not rely on the web session (just the HTTP request, to avoid creating useless sessions).

You can control that by overriding the loadProfilesFromSession method of the DefaultSecurityLogic which is internally used by the SecurityFilter. Maybe we should have a loadProfileFromSession property like the saveProfileInSession property to control that as well.

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Akshay

unread,
Oct 15, 2017, 2:12:02 PM10/15/17
to Pac4j users mailing list
Jérôme, thank you so much for the reply!

 Can you please guide me as to how I might override the loadProfilesFromSession method? When I check the logs, the loadProfilesFromSession method appears to return true. 

Also, I'm not really sure how overriding this method might help solve the problem I have?

Thanks in advance!

Jérôme LELEU

unread,
Oct 16, 2017, 11:20:56 AM10/16/17
to Akshay, Pac4j users mailing list
Hi,

I meant overriding by creating a new class, but the goal was to return true instead of false, which is already the case.

It's not exactly what I expected. Can you turn on DEBUG logs on org.pac4j and post them?

Thanks.
Best regards,
Jérôme


--

Akshay

unread,
Oct 16, 2017, 12:20:06 PM10/16/17
to Pac4j users mailing list
Thanks again Jerome!

Here are the logs -
second_ajax_request_after_authentication_logs
after_authentication_pac4j_logs
before_authentication_pac4j_logs

Jérôme LELEU

unread,
Oct 18, 2017, 2:25:07 AM10/18/17
to Akshay, Pac4j users mailing list
Hi,

The login process works as you are authenticated on the https://our-url/rest/user/saml/redirect URL (after_authentication_pac4j_logs), though the second AJAX request fails despite the loadProfilesFromSession: true.

Even stranger, the request just after works. So I assume that there is something wrong with your AJAX request: is the JSESSIONID available on this request? Can you post one of these AJAX requests?

Thanks.
Best regards,
Jérôme


On Mon, Oct 16, 2017 at 6:20 PM, Akshay <akshay.s...@gmail.com> wrote:
Thanks again Jerome!

Here are the logs -

--

Akshay

unread,
Oct 31, 2017, 3:15:40 AM10/31/17
to Pac4j users mailing list
Thank you so much Jerome! You were right, it was indeed a problem with the AJAX requests. I had to set 'withCredentials: true' while sending the AJAX requests, and it solved the problem.

Thank you so much for taking your time out to help me! Really appreciate it!

rangde...@gmail.com

unread,
Jun 30, 2018, 4:44:21 AM6/30/18
to Pac4j users mailing list
Dear Akshay,

We are having requirement to establish SPA with ADFS and SAML 2.0.
Can you please guide me how to set up the infrastructure to access the same?

Thanks and Regards,
Rakesh Kamble

Phalgun Vaddepalli

unread,
Dec 27, 2018, 7:15:43 AM12/27/18
to Pac4j users mailing list
Hi Rakesh,

Even I want to the same information. Did you happen to find it?
Reply all
Reply to author
Forward
0 new messages