Last active
March 3, 2016 17:25
-
-
Save sitefinitysteve/d195e2901c8bf509de91 to your computer and use it in GitHub Desktop.
Clear a Sitefinity users Ldap Cache key on login
This file contains 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 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