Hello everyone,
is there a complete example of LDAP authentication. I've read the documentation but I can't get it work. It will only authenticate against the mssql database. That's what I already did:
Created Authentication Source Class
class HagebauRzPortalLdapAuthenticationSource : LdapAuthenticationSource<Tenant, User>
{
public HagebauRzPortalLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
: base(settings, ldapModuleConfig)
{
}
}
Then I changed the core module file:
[DependsOn(typeof(AbpZeroCoreModule),typeof(AbpZeroLdapModule))]
public class HagebauRzPortalCoreModule : AbpModule
{
public override void PreInitialize()
{
Configuration.Modules.ZeroLdap().Enable(typeof(HagebauRzPortalLdapAuthenticationSource));
//Remove the following line to disable multi-tenancy.
//Configuration.MultiTenancy.IsEnabled = false;
//Add/remove localization sources here
Configuration.Localization.Sources.Add(
new DictionaryBasedLocalizationSource(
HagebauRzPortalConsts.LocalizationSourceName,
new XmlEmbeddedFileLocalizationDictionaryProvider(
Assembly.GetExecutingAssembly(),
"PM.HagebauRzPortal.Localization.Source"
)
)
);
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
SettingManager settingsManager = IocManager.Resolve<SettingManager>();
settingsManager.ChangeSettingForApplication("LdapSettingNames.IsEnabled", "true");
}
}
Now I get an exception telling me that there is no setting defined with property "LdapSettingNames.IsEnabled" :? What am I doing wrong? Any help would be greatly appreciated.
Best regards, Phillip
4 Answer(s)
-
0
Hi,
Chenge this:
SettingManager settingsManager = IocManager.Resolve<SettingManager>(); settingsManager.ChangeSettingForApplication("LdapSettingNames.IsEnabled", "true");
to this:
SettingManager settingsManager = IocManager.Resolve<SettingManager>(); settingsManager.ChangeSettingForApplication(LdapSettingNames.IsEnabled, "true");
and move these 2 lines to PostInitialize method of your module, not Initialize.
It will work. But, actually this is not true. Because it change the setting everytime application starts. You should change it in a some setting page of your application or add seed code to your db migration.
-
0
Hi,
thank you very much but it still wont authenticate against ldap. I would really appreciate if you could provide a minimal example of ldap authentication with the module zero. We are evaluating your framework for different projects but the documentation is lacking especially the ldap part. I guess this will improve over time right?
But, actually this is not true. Because it change the setting everytime application starts. You should change it in a some setting page of your application or add seed code to your db migration.
Where and how do I do that? Could you explain little more in Detail please?
SettingManager settingsManager = IocManager.Resolve<SettingManager>(); settingsManager.ChangeSettingForApplication(LdapSettingNames.IsEnabled, "true");
and move these 2 lines to PostInitialize method of your module, not Initialize.
Was this the only change to be made? Or do I also have to adjust Web.config for example? Sorry for so many question, I really appreciate your help.
Best regards
-
0
OK, then I improved LDAP doc a bit more: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/User-Management#ldapactive-directory">http://www.aspnetboilerplate.com/Pages/ ... -directory</a> Hope it helps.
You probably did not understand the setting manager :)
Settings are stored in DB and can be get/set using SettingManager. A setting is normally changed with a setting page of your application. User enters to setting page, you get setting's current value using setting manager. Then user enters a different value for a setting and saves it. Then you change the setting using setting manager's changeSetting methods. So, setting manager should be used in application runtime, not initialization (also, why we change setting in every initialization if it's already the same value in the database).
If you don't have such a setting page, you can open database and change settings manually. AbpSettings table is very simple. When you read setting manager doc (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Setting-Management">http://www.aspnetboilerplate.com/Pages/ ... Management</a>) you can understand the table fields.
Alternatively, you can write a EF seed code to set default values into database.
Lastly, for Ldap settings, you can implement ILdapSettings (as described in the document), so you can return hard-coded values if you want.
But never change settings in your application initialization.
Have a nice day.
-
0
Perfect, now it's working. Thanks a lot!