Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module For LDAP #1189

Closed
akinix opened this issue May 31, 2019 · 7 comments · Fixed by #1190
Closed

Module For LDAP #1189

akinix opened this issue May 31, 2019 · 7 comments · Fixed by #1190

Comments

@akinix
Copy link
Contributor

akinix commented May 31, 2019

Source Volo.Abp.Ldap
UnitTest Volo.Abp.Ldap.Tests
Because the unit test requires environment for AD.
I have skipped all the tests when I submitted the code.
I have passed all the tests in the local.
image

Volo.Abp.Ldap

Only Authenticate(not read/write AD)

Configure

add section in appsettings.json

use SSL

"LDAP": {
    "ServerHost": "192.168.101.54", 
    "ServerPort": 636,
    "UseSSL": true
}

not use SSL

"LDAP": {
    "ServerHost": "192.168.101.54", 
    "ServerPort": 389,
    "UseSSL": false
}

Authenticate

Injecting ILdapManager into a class. For example:

public class TaxAppService : ApplicationService
{
    private readonly ILdapManager _ldapManager;

    public TaxAppService(ILdapManager ldapManager)
    {
        _ldapManager = ldapManager;
    }

    public void Authenticate(string userName, string password)
    { 
        var result = _ldapManager.Authenticate(userName, password);
    }
}

Read/Write AD

Configure

use SSL

"LDAP": {
    "ServerHost": "192.168.101.54",
    "ServerPort": 636,
    "UseSSL": true,
    "Credentials": {
        "DomainUserName": "[email protected]",
        "Password": "yH.20190528"
    },
    "SearchBase": "DC=yourdomain,DC=com,DC=cn",
    "DomainName": "yourdomain.com.cn",
    "DomainDistinguishedName": "DC=yourdomain,DC=com,DC=cn"
}

not use SSL

"LDAP": {
    "ServerHost": "192.168.101.54",
    "ServerPort": 389,
    "UseSSL": false,
    "Credentials": {
        "DomainUserName": "[email protected]",
        "Password": "yH.20190528"
    },
    "SearchBase": "DC=yourdomain,DC=com,DC=cn",
    "DomainName": "yourdomain.com.cn",
    "DomainDistinguishedName": "DC=yourdomain,DC=com,DC=cn"
}
  • Credentials:DomainUserName a administrator of AD.

  • Credentials:Password the password for the administrator.

  • SearchBase: where search from AD.

  • DomainName: name of you domain. no need www.

  • DomainDistinguishedName: distinguished name of root domain.

Query Organizations

// query all organizations
// filter: (&(objectClass=organizationalUnit)) 
_ldapManager.GetOrganizations();

// query organizations by name
// filter: (&(name=abc)(objectClass=organizationalUnit))
_ldapManager.GetOrganizations("abc");

Query Organization

// query organization by distinguished name
// filter: (&(distinguishedName=abc)(objectClass=organizationalUnit))
_ldapManager.GetOrganization("abc");

Add Organization

// use LdapOrganization
_ldapManager.AddSubOrganization("nameA", parentOrganization);

// or use OrganizationDistinguishedName
_ldapManager.AddSubOrganization("nameA", "OU=Domain Controllers,DC=yourdomain,DC=com,DC=cn");

Query Users

// query all users
// filter: (&(objectCategory=person)(objectClass=user))
_ldapManager.GetUsers();

// query organizations by name
// filter: (&(name=abc)(objectCategory=person)(objectClass=user))
_ldapManager.GetUsers(name : "abc");

// query organizations by displayName
// filter: (&(displayName=abc)(objectCategory=person)(objectClass=user))
_ldapManager.GetUsers(displayName : "abc");

// query organization by commonName
// filter: (&(cn=abc)(objectCategory=person)(objectClass=user))
_ldapManager.GetUsers(commonName : "abc");

Query User

// query a user by distinguished name
// filter: (&(distinguishedName=abc)(objectCategory=person)(objectClass=user))
_ldapManager.GetUser("abc");

Add User

// use LdapOrganization
_ldapManager.AddUserToOrganization("nameA", "passwordA", parentOrganization);

// or use OrganizationDistinguishedName
_ldapManager.AddUserToOrganization("nameA", "passwordA", "OU=Domain Controllers,DC=yourdomain,DC=com,DC=cn");
@akinix
Copy link
Contributor Author

akinix commented Jun 1, 2019

<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />

used Novell.Directory.Ldap.NETStandard for NETStandard

Source Novell.Directory.Ldap.NETStandard

@akinix
Copy link
Contributor Author

akinix commented Jun 1, 2019

how to test?

  • prepare LDAP environment. run a openldap in docker.

dockerhub : osixia/openldap
source https://github.com/osixia/docker-openldap

  • pull image
docker pull osixia/openldap
  • run ldap
docker run --name ldap -d --env LDAP_ORGANISATION="abp" --env LDAP_DOMAIN="abp.com" --env LDAP_ADMIN_PASSWORD="123456" -p 389:389 -p 636:639 --detach osixia/openldap
  • configure
"LDAP": {
    "ServerHost": "127.0.0.1",
    "ServerPort": 636,
    "UseSSL": true,
    "Credentials": {
        "DomainUserName": "[email protected]", // or cn=admin,dc=abp,dc=com
        "Password": "123456"
    },
    "SearchBase": "DC=abp,DC=com",
    "DomainName": "abp.com",
    "DomainDistinguishedName": "DC=abp,DC=com"
}

@hikalkan
Copy link
Member

hikalkan commented Jun 1, 2019

Great! Would you like to send a PR? I can copy it, but I like that you have a contribution in the contributors list.

@leonkosak
Copy link
Contributor

Does LDAP authentication in abp.io work in multitenant environment (for instance in ANZ you have to disable multitenancy if you want using LDAP)?

@maliming
Copy link
Member

maliming commented Aug 7, 2020

hi @leonkosak We will make it support multi-tenancy. : ) #4983

@leonkosak
Copy link
Contributor

@maliming I have scenario to authenticate via local Active Directory (AD). I am confused how to properly implement this external login.
Probably, when one user login to application for the first time, should we create new external user (AbpUsers table) and then when we have a record for new user in AbpUsers table add permissions and roles to this user?
User would always manually make login with his/her AD user.

Could you please describe steps how to properly implement this integration (robust and secure)?
Thank you.

@maliming
Copy link
Member

hi @leonkosak

Please create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants