Last active
August 29, 2015 14:03
-
-
Save lowedown/a35aea634d9410921659 to your computer and use it in GitHub Desktop.
Extension of a Sitecore PublishAgent to run publish jobs under a specific user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuthenticatedPublishAgent : PublishAgent | |
{ | |
private readonly string _userName; | |
public string UserName | |
{ | |
get | |
{ | |
return this._userName; | |
} | |
} | |
public AuthenticatedPublishAgent(string sourceDatabase, string targetDatabase, string mode, string languages, string user) : base(sourceDatabase, targetDatabase, mode, languages) | |
{ | |
this._userName = user; | |
} | |
public void RunAsUser() | |
{ | |
if (string.IsNullOrEmpty(UserName) || !Sitecore.Security.Accounts.User.Exists(UserName)) | |
{ | |
Log.Error(string.Format("Unable to run AuthenticatedPublishAgent as user: {0}", UserName), this); | |
return; | |
} | |
var user = Sitecore.Security.Accounts.User.FromName(UserName, false); | |
using (new Sitecore.Security.Accounts.UserSwitcher(user)) | |
{ | |
base.Run(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<agent type="MyNameSpace.AuthenticatedPublishAgent" method="RunAsUser" interval="01:00:00"> | |
<param desc="source database">master</param> | |
<param desc="target database">web</param> | |
<param desc="mode (full or smart or incremental)">smart</param> | |
<param desc="languages">en</param> | |
<param desc="user">sitecore\AutoPublishingUser</param> | |
</agent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment