Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

USING ABP role & user manager with another table/view #474


User avatar
0
klainer created

Hello, i often need to use another table for users, mostly is a VIEW from another system like Active Directory. Is is possible to have custom View table for users and using role, permission and another good functionality of ABP ?

My poople view look like:

PeopleView: Login, Department, Email with thousands of row.

User will be automaticly logged to system by his login - Windows Auth.

Do anybody have the same problem ?

Thanks !


9 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You may try to define EntityFramework mapping onmodelcreating. I did not try to map entities to views in EF. I'm not sure if it works. I assume that you're using module-zero. If so, it has an Actice Directory (LDAP) login support (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/User-Management#ldapactive-directory">http://www.aspnetboilerplate.com/Pages/ ... -directory</a>). Isn't that sufficient? Also you can override methods of LdapAuthenticationSource to get additional info from AD (see <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero.Ldap/Ldap/Authentication/LdapAuthenticationSource.cs">https://github.com/aspnetboilerplate/mo ... nSource.cs</a> to understand it).

  • User Avatar
    0
    klainer created

    Thanks for reply! Let´s assume that I need to use different table than AbpUser for login check, how would you preoceed ? For login to apllication is windows username needed, if username is in DB , then user is logged. Thats all..

    By the way Views is possible to map...

    Thanks !

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I designed External Authentication for that. See docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/User-Management#external-authentication">http://www.aspnetboilerplate.com/Pages/ ... entication</a>

    public class MyExternalAuthSource : DefaultExternalAuthenticationSource<Tenant, User>
    {
        public override string Name
        {
            get { return "MyCustomSource"; }
        }
    
        public override Task<bool> TryAuthenticateAsync(string userNameOrEmailAddress, string plainPassword, Tenant tenant)
        {
            //TODO: authenticate user from any other table, database or even from an external service...
        }
    }
    

    This may help.

  • User Avatar
    0
    klainer created

    Ok I used your basic sample, with simply retun true. I registered this MyExternalAuthSource, in Web project.

    public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
    
                AreaRegistration.RegisterAllAreas();
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
            }
        }
    
        public class MyExternalAuthSource : DefaultExternalAuthenticationSource<Tenant, User>
        {
            public override string Name
            {
                get { return "MyCustomSource"; }
            }
    
             
    
            public override async Task<bool> TryAuthenticateAsync(string userNameOrEmailAddress, string plainPassword, Tenant tenant)
            {
                //TODO: authenticate user and return true or false
                return true;
            }
        }
    

    But i dont know what i must tu do next for login person by using this external source. In documentation this is missing and I´m confused . What i must change in Login method in auth controller ?

    I algo got this error:

    No component for supporting the service TT.MyExternalAuthSource was found
    
    Popis: Při provádění aktuálního webového požadavku došlo k neošetřené výjimce. Další informace o chybě a o jejím původu v kódu naleznete v trasování zásobníku. 
    
    Podrobnosti o výjimce: Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service TT.MyExternalAuthSource was found
    

    Ok I solved this by add this code to intialization of Core Module:

    public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
                IocManager.Register<MyExternalAuthSource>(DependencyLifeStyle.Transient);
            }
    

    Mayby another question. I notice that when use Custom auth login, AbpUser table automaticly create new record for logged person name and also generate password. Is this appropoach good for my situation ( I have onother table with users) so roles and other stuff are still depended on AbpUser ?

    Thnaks for any tip!

  • User Avatar
    0
    hikalkan created
    Support Team

    ABP creates user if he does not exists or can update. You can override some virtual methods to override create/update logic. This is better since there are many foreign key relations to AbpUsers table and User record should be there.

    By the way, you could register MyExternalAuthSource as shown below:

    public class MyExternalAuthSource : DefaultExternalAuthenticationSource<Tenant, User>, ITransientDependency { ... }

  • User Avatar
    0
    klainer created

    Ok tahnks works. I´m aldo traing LDAP auth:

    In my core module in PreInitialize method I call this:

    IocManager.Register<ILdapSettings, MNDLdapSettings>(); //change default setting source
    Configuration.Modules.ZeroLdap().Enable(typeof(MyLdapAuthenticationSource));
    

    I have also class:

    public class MyLdapAuthenticationSource : LdapAuthenticationSource<Tenant, User>
        {
            public MyLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
                : base(settings, ldapModuleConfig)
            {
            }
        }
    

    Then i Created this settings class:

    public class MNDLdapSettings : ILdapSettings
        {
            public async Task<bool> GetIsEnabled(int? tenantId)
            {
                return true;
            }
    
            public async Task<ContextType> GetContextType(int? tenantId)
            {
                return ContextType.Domain;
            }
    
            public async Task<string> GetContainer(int? tenantId)
            {
                return "";
            }
    
            public async Task<string> GetDomain(int? tenantId)
            {
                return "domain";
            }
    
            public async Task<string> GetUserName(int? tenantId)
            {
                return "name";
            }
    
            public async Task<string> GetPassword(int? tenantId)
            {
                return "pass";
            }
        }
    

    I also tried use your default setting like you noted:

    Note: If you don't define domain, username and password, LDAP authentication works for current domain if your application runs in a domain with appropriate privileges.

    And try enable LDAP like in this post / last unanswered question: #205@a9e9ccf7-5841-4126-9423-c0d5b678eb9b

    But no work , the same problem with : Abp.AbpException: There is no setting defined with name: Abp.Zero.Ldap.IsEnabled

    When is LDAP enablet and in cotroller is [AbdAuthorized] attribute. User will be logged automaticly ?

    Please help ... Thnaks!

    But auth no work for me, how can I detect error in credectials etc or debug auth using LDAP ? Thnaks

  • User Avatar
    0
    klainer created

    OK SOLVED :)

    I created my custom config and enable correctly, LDAP support . Works perfect !! Thank you!

  • User Avatar
    0
    VuCA created

    <cite>klainer: </cite> OK SOLVED :)

    I created my custom config and enable correctly, LDAP support . Works perfect !! Thank you!

    Hi @klainer, Do you create external authentication source? Can you tell me how to do? This document <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Zero/User-Management#external-authentication">https://aspnetboilerplate.com/Pages/Doc ... entication</a> is poor :( , I do not know how to implement it.

    Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @VuCA,

    Probably @klainer is just configured the Ldap settings, didn't create an external auth source. When you debug your code, can you get a breakpoint in your custom auth source ?

    If not, please send your project to us and we will check it.

    Thanks.