After upgrading ServiceStack to version 5.11 we get an error while authenticating with AD:
System.SystemException: The trust relationship between the primary domain and the trusted domain failed.
at System.Security.Principal.NTAccount.TranslateToSids(IdentityReferenceCollection sourceAccounts, Boolean& someFailed)
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.WindowsPrincipal.IsInRole(String role)
at ServiceStack.Auth.AspNetWindowsAuthProvider.PopulateUserSessionWithIsInRole(IRequest req, IPrincipal user, IAuthSession session) in
...
It seems that in commit https://github.com/ServiceStack/ServiceStack/commit/41c7a06720c0fac0a77fb23cb4ba8bfbf71cf4bf a new “Admin” role was added. After googling I found out that this error is often thrown when WindowsPrincipal.IsInRole is called and the group doesn’t exist in the AD (which doesn’t in our case).
Roles are loaded in AspNetWindowsAuthProvider:
appHost.AfterInitCallbacks.Add(host =>
{
var allExistingRoles = host.Metadata.GetAllRoles();
allExistingRoles.Each(x => AllRoles.AddIfNotExists(x));
});
since we are not using any additional roles, “Admin” is the only role in AllRoles property.
If I (for example) comment out the code above (so that AllRoles is empty), we don’t get exceptions anymore.
On some servers, this error can always be reproduced, while on some servers it appears randomly.
Can you investigate what is causing this and what is the possible workaround?
Best regards