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

LDAP bind with just incoming username/pw #1350

Open
tooptoop4 opened this issue Jun 13, 2023 · 9 comments
Open

LDAP bind with just incoming username/pw #1350

tooptoop4 opened this issue Jun 13, 2023 · 9 comments

Comments

@tooptoop4
Copy link

Feature description

I don't want to have a service account binding (ie managerDN) but want to use incoming user creds to bind. but they will only supply username/email not DN.
note:server does not allow anon bind

I read "Active Directory will let you also bind using userPrincipalName instead of DN, so it might be helpful to attempt to bind as username@domain.com instead of username. Either users can be instructed to log in this way or the application can add @domain.com part upon binding attempt if feasible."

@sdelamo
Copy link
Contributor

sdelamo commented Jun 13, 2023

@tooptoop4 I am not sure I understand what you want to achieve. can you ellaborate more. Do you have a sample app which shows what you want to be possible?

@tooptoop4
Copy link
Author

tooptoop4 commented Jun 13, 2023

@sdelamo
I want the bind to LDAP to happen with each username/password being entered in the UI. I don't want a common managerDN that is used for all different users binding to LDAP, as I want to avoid issues when the common managerDN's password is wrong.
For ActiveDirectory specifically the full DN name is NOT required, just username + domain ie someuser@some.company.com and password can be used to bind https://github.com/jeevatkm/generic-repo/blob/master/ActiveDirectoryJava/src/com/myjeeva/ad/ActiveDirectory.java#L69-L70

https://trino.io/docs/current/security/ldap.html#active-directory has more docs

rough idea to make micronaut support this:

seems to be where the bind happens but is called twice (
managerContext = contextBuilder.build(configuration.getManagerSettings());
debug(LOG, "Manager context initialized successfully");
} catch (NamingException e) {
debug(LOG, "Failed to create manager context. Returning unknown authentication failure. Encountered {}", e.getMessage());
emitter.error(AuthenticationResponse.exception(AuthenticationFailureReason.UNKNOWN));
return;
}
debug(LOG, "Attempting to authenticate with user [{}]", username);
try {
Optional<LdapSearchResult> optionalResult = ldapSearchService.searchFirst(managerContext, configuration.getSearch().getSettings(new Object[]{username}));
if (optionalResult.isPresent()) {
LdapSearchResult result = optionalResult.get();
debug(LOG, "User found in context [{}]. Attempting to bind.", result.getDn());
DirContext userContext = null;
try {
String dn = result.getDn();
userContext = contextBuilder.build(configuration.getSettings(result.getDn(), password));
) firstly by generic bind then by the user. Need a new config for the domain name (ie some.company.com), if not empty then edit the username
String username = authenticationRequest.getIdentity().toString();
to be username+'@'+<domain_name_config> and only do single bind

@tooptoop4
Copy link
Author

@sdelamo feedback ^

@sdelamo
Copy link
Contributor

sdelamo commented Jun 28, 2023

can you replace LdapAuthenticationProvider in your project and adjust it to your needs?

@tooptoop4
Copy link
Author

do u like the idea @tchiotludo ? this login feature is for akhq

@tchiotludo
Copy link
Contributor

it's totally possible for akhq (with a PR), but it can be useful for the micronaut community as well. @sdelamo do you think this make sense for this project directly?

@sdelamo
Copy link
Contributor

sdelamo commented Jul 7, 2023

@tchiotludo Please send a PR I am not 100% sure I follow what you want to change.

@tooptoop4
Copy link
Author

its single bind instead of two binds

@jonatasvieira
Copy link

Has anyone solved this? Is there another (less intrusive) alternative?

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

No branches or pull requests

4 participants