简体   繁体   中英

Sitecore with LDAP - authenticate programmatically

I am creating an app inside Sitecore and I only want it available to the users via a direct URL. I want the authentication to occur against LDAP. I tried going directly to the app and let it redirect to the auto login page and redirect me to the app but it didn't do it. Instead it took me to the Sitecore login page.

I'm wondering if it is possible for me to write some code to auto authenticate a LDAP user and redirect to the app page. I want the user to never see the login page or Sitecore desktop or any of the Sitecore screens other than that one app.

Thanks

We accomplished something similar by combining the AD module with some custom code in the Global.asax. Below are a few lines that might be helpful. You'll likely need a bunch of logic to check if the user is already logged in, and whether they are accessing a path you want to auto-login for.

NOTE : Make sure windows authentication is enabled in IIS.

protected void Session_Start(object sender, EventArgs e){
        // The user from Windows Authentication in IIS
        var user = Context.Request.ServerVariables["LOGON_USER"];
        //Log the user in
        bool success = Sitecore.Security.Authentication.AuthenticationManager.Provider.Login(user, false);

}

You'll note that the sample I provided goes directly to the provider. You can also call Login at the AuthenticationManager class, and this will also do some other work with cache. In my case, I was trying to bypass that.

UPDATE (2017-06-29): In newer versions of Sitecore it is not recommended to make changes to the Global.asax. Unfortunately, there is no equivalent pipeline in Sitecore. You can attempt to use httpRequestBegin (where the UserResolver processor is) or httpRequestProcessed, but these will fire on every single request.

One alternative (credit to @Mark Cassidy on SlackChat) is to use the Initialize pipeline and in that processor register to the session start event.

It is possible yes, a quick Google search turned up these:

http://www.nehemiahj.com/2013/01/how-to-enable-single-sign-on-in-sitecore.html

based on the AD Module from Sitecore

http://sdn.sitecore.net/SDN5/Products/AD/AD11/Documentation.aspx

That should give you a good place to start from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM