I want that application will be accessible for end user regardless on which server node LoadBalancer redirects. So, I would like to use OrmLiteCacheClient to store session in MSSQL DB.
I have the following code (there is only part of SetupPlugins):
private void SetupPlugins (Container container)
{
//Register OrmLite Db Factory if not already
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(connString, SqlServerDialect.Provider));
container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
//Create 'CacheEntry' RDBMS table if it doesn't exist already
container.Resolve<ICacheClient>().InitSchema();
container.Register<IAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
container.Resolve<IAuthRepository>().InitSchema();
Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
new AdGroupAuthProvider(container.Resolve<IActiveDirectoryAuthHelper>(),
GlobalConfiguration.Instance.AllowedActiveDirectoryGroup)
}));
}
internal class AdGroupAuthProvider : BasicAuthProvider
{
private readonly IActiveDirectoryAuthHelper _adLoggingHelper;
private readonly string _loggedUserAdGroup;
public AdGroupAuthProvider(IActiveDirectoryAuthHelper loggingHelper, string loggedUserAdGroup)
{
_adLoggingHelper = loggingHelper;
_loggedUserAdGroup = loggedUserAdGroup;
}
public override bool Authenticate(IServiceBase loggingServiceBase, string userName, string password)
{
return _adLoggingHelper.HasUserAssignedGroup(userName, password, _loggedUserAdGroup);
}
}
}
How to get AdGroupAuthProvider worked with OrmLiteCacheClient? The above programme builds and I can authenticate. However, the CacheEntry MSSQL table is empty.
ServiceStack uses
ICacheClientto store User Sessions in normal session-based Auth Providers although it does not persist Sessions to the Cache in IAuthWithRequest Providers.I'm not familiar with
AdGroupAuthProviderbut if it implementsIAuthWithRequestthe request contains the authentication per request which is what's used to populate the session that's only attached to the Request and not persisted in theICacheClient.