8

This is what I am trying to do,

If the user is authenticated in sitecore, and not authenticated in external system then log out the user from sitecore.

So, here is the pipeline I use:

<processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.UserResolver, Sitecore.Kernel']" type="xxx.SitecoreExtensions.Pipelines.HttpRequest.ExternalSystemUserAuthenticationResolver, xxx.SitecoreExtensions">  

The processor xxx.SitecoreExtensions.Pipelines.HttpRequest.ExternalSystemUserAuthenticationResolver reads some data from Session and returns true or false if the external system token is present in session or not.

This is what is happening: When I sign in (sign in logs me in both the systems, sitecore and external), a token is set in the session and the ExternalSystemUserAuthenticationResolver method gives me correct status of authentication. When I am redirected to other page after login, the ExternalSystemUserAuthenticationResolver method does not find anything in session and says that I am not logged into external system so the overall authentication status is false.

Here is the implementation of the new method:

public class ExternalSystemUserAuthenticationResolver: HttpRequestProcessor
{
    protected override void SiteSpecificProcess(HttpRequestArgs args)
    {
        try
        {
            if (Sitecore.Context.User.IsAuthenticated && !AccountHelper.IsExternalSystemAuthenticated())
            {
                AuthenticationManager.Logout();
            }
        }
        catch (Exception ex)
        {
            Log.Error(ex.Message, ex, this);
        }
    }
}

AccountHelper.IsExternalSystemAuthenticated() reads data from the session to check if the token and if the session is null then I am redirected to another page after login.

Where should I place my new processor so that the session object is populated?

0

1 Answer 1

10

You actually need to use a completely different pipeline: httpRequestProcessed. This pipeline executes after the session has been initialized.

The example below is taken from this blog by Brian Pedersen:

namespace MyNamespace
{
  public class MyClass : HttpRequestProcessor
  {
    public override void Process(HttpRequestArgs args)
    {
      Assert.ArgumentNotNull(args, "args");
      if (Context.Site == null)
        return;
      if (Context.Site.Domain != DomainManager.GetDomain("extranet"))
        return;
      if (args.Url.FilePathWithQueryString.ToUpperInvariant().Contains("redirected=true".ToUpperInvariant()))
        return; // already redirected
      if (Context.PageMode.IsPageEditor)  
        return;

      // DO CODE
    }
  }
}
2
  • 2
    Great answer! In Sitecore 8.X+, want to also mention that IsPageEditor has been changed to IsExperienceEditor.
    – Pete Navarra
    Oct 7, 2016 at 22:18
  • Thanks Ben, I implemented the approach with httpRequestProcessed. The user is logged out appropriately but the page still loads (as anonymous user) instead of redirecting the user to the login page. The login logic is in the processor Sitecore.Pipelines.RenderLayout.SecurityCheck, Sitecore.Kernel. Is there a way to implement redirection without writing the redirection logic in the new processor that I created? Oct 10, 2016 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.