Skip to content

Instantly share code, notes, and snippets.

@sitefinitysteve
Last active March 3, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitefinitysteve/d195e2901c8bf509de91 to your computer and use it in GitHub Desktop.
Save sitefinitysteve/d195e2901c8bf509de91 to your computer and use it in GitHub Desktop.
Clear a Sitefinity users Ldap Cache key on login
public static void ClearSingleUserLdapCache(string username)
{
var keysToClear = new List<string>();
try
{
var userManager = UserManager.GetManager("LdapUsers");
var currentUser = userManager.GetUser(username);
var ldapFacade = new LdapFacade();
var mapping = Telerik.Sitefinity.Configuration.Config.Get<SecurityConfig>().LdapConnections.LdapMapping.UserMapping;
var ldapUser = ldapFacade.GetUserById(currentUser.Id, new string[1]);
var ldapUserGuid = new Guid(LdapUtilities.GetAttributeValue<byte[]>(ldapUser, LdapAttributeNames.ObjectGuidAttribute));
var ldapRuinedGuid = new LdapFormatter().ToLdapFormat(ldapUserGuid);
keysToClear.Add("DefaultLdapConnection|(&(objectGUID=" + ldapRuinedGuid + ")(&(objectClass=INetOrgPerson)(!(objectClass=computer))))|0|0|memberOf;|False");
//Clear Current users LDAP cache if it exists
var cacheManager = SystemManager.GetCacheManager(CacheManagerInstance.Global);
foreach (var key in keysToClear)
{
if (cacheManager.Contains(key))
{
cacheManager.Remove(key);
}
}
}
catch (Exception ex)
{
//Do whatever
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment