publicBooleancheckExpiration(Stringuser, Stringpass)throwsLDAPException {
SSLSocketFactorysocketFactory=null;try {
socketFactory=createFactory();
} catch(Exceptione) {
//CreateFactoryExceptione.printStackTrace();
}
//CreateasecureconnectiontotheActiveDirectoryserver.
finalLDAPConnectionconnection=newLDAPConnection(socketFactory, myHost, (Integer.parseInt(portLdap)),
bindDN, passDN);//Sendasimplebindrequesttothedirectoryserver.
BindRequestbindRequest=newSimpleBindRequest("uid=example1,ou=Corporate Users,dc=example,dc=com", pass);BindResultbindResult;booleanpasswordExpired;try {
bindResult=connection.bind(bindRequest);//Ifwegothere, thebindwassuccessfulandweknowthepasswordwas//notexpired. However, weshouldn't ignore the result because the//passwordmightbeabouttoexpire. Todeterminewhetherthatisthe//case, weshouldseeifthebindresultincludedapasswordexpiring//control.
passwordExpired=false;returnpasswordExpired;
} catch(LDAPExceptionle) {
//Ifwegothere, thenthebindfailed. Thefailuremayormaynothave//beenduetoanexpiredpassword. Todeterminethat, weshouldseeif//thebindresultincludedapasswordexpiredcontrol.
bindResult=newBindResult(le.toLDAPResult());ResultCoderesultCode=le.getResultCode();StringerrorMessageFromServer=le.getDiagnosticMessage();PasswordExpiredControlexpiredControl=PasswordExpiredControl.get(le);passwordExpired=expiredControl!=null;DraftBeheraLDAPPasswordPolicy10ResponseControlpwpResponse=DraftBeheraLDAPPasswordPolicy10ResponseControl
.get(bindResult);if(pwpResponse!=null) {
DraftBeheraLDAPPasswordPolicy10ErrorTypeerrorType=pwpResponse.getErrorType();if(errorType!=null) {
//Therewasapasswordpolicyerror.
System.out.print("There was a password policy error");
}
}
returnpasswordExpired;
}
}
Now, as you can see i've used the PasswordExpiredControl and, also, the DraftBeheraLDAPPasswordPolicy10ResponseControl class without succes. The response for both classes is null, then i read this
then you should work with your vendor to determine what mechanism (if any) that server offers for this capability.
so as far as i know OpenLDAP has this capabilities, so what else can be failing?
PD: Now, i've checked if the user has a password expired in the openldap host with this command
I don't know whether OpenLDAP supports the password expired response control as described in draft-vchu-ldap-pwd-policy-00, but I wouldn't be surprised if it does not. If it does support that control, then the server should return it without the client needing to do anything special in the request.
I do think that it's much more likely that it supports the password policy control described in draft-behera-ldap-password-policy-10, but the password policy response control will only be returned if the bind request includes the corresponding request control. The bind request used in the example above does not include that control, so the server wouldn't know to include the response control in the bind result. If you want to use that control, then you should change your bind request from
new SimpleBindRequest(dn, password)
to
new SimpleBindRequest(dn, password, new DraftBeheraLDAPPasswordPolicy10RequestControl())
If you include the request control and the server still doesn't return the corresponding response control, then that's probably an issue with the server rather than the client, and this probably isn't the best place to get OpenLDAP-specific help.
❤️
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dude, you're a lifesaviour :D
That control in the SimpleBindRequest do the magic with this i can validate perfectly, now is returning the errorType.name() as PASSWORD_EXPIRED.
Now the only doubt left is, does the PasswordExpiredControl need something similar to DraftBeheraLDAPPasswordPolicy10RequestControl?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I mentioned above, you shouldn't have to do anything special in the request to get the password expired response control. If you're not seeing it, then it's probably either because the server doesn't support it or maybe because it's not configured to return it. I'm not an OpenLDAP expert, so I can't say whether it supports it and if so whether there is any associated configuration.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By the way, the version of ldapsearch that the LDAP SDK provides (tools/ldapsearch) has support for both of those controls, so you could test with it before changing your code For example:
Well, with OpenLDAP it works neat! but since our customer is using Windows AD we can't make work properly. In fact it ignores many Policies, like Password history, Minimum and Maximum password age but make the password changes and logins succesfully. Anyway, thanks for your time :)
Last edit: Alvaro Felipe Garcia Mendez 2020-09-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As i saw in a post from a few years ago https://sourceforge.net/p/ldap-sdk/discussion/1001257/thread/9d60b696/, i've used then same code to do the expiration check
Now, as you can see i've used the PasswordExpiredControl and, also, the DraftBeheraLDAPPasswordPolicy10ResponseControl class without succes. The response for both classes is null, then i read this
so as far as i know OpenLDAP has this capabilities, so what else can be failing?
PD: Now, i've checked if the user has a password expired in the openldap host with this command
and it returns this
Last edit: Alvaro Felipe Garcia Mendez 2020-06-24
I don't know whether OpenLDAP supports the password expired response control as described in draft-vchu-ldap-pwd-policy-00, but I wouldn't be surprised if it does not. If it does support that control, then the server should return it without the client needing to do anything special in the request.
I do think that it's much more likely that it supports the password policy control described in draft-behera-ldap-password-policy-10, but the password policy response control will only be returned if the bind request includes the corresponding request control. The bind request used in the example above does not include that control, so the server wouldn't know to include the response control in the bind result. If you want to use that control, then you should change your bind request from
new SimpleBindRequest(dn, password)
to
new SimpleBindRequest(dn, password, new DraftBeheraLDAPPasswordPolicy10RequestControl())
If you include the request control and the server still doesn't return the corresponding response control, then that's probably an issue with the server rather than the client, and this probably isn't the best place to get OpenLDAP-specific help.
Dude, you're a lifesaviour :D
That control in the SimpleBindRequest do the magic with this i can validate perfectly, now is returning the errorType.name() as PASSWORD_EXPIRED.
Now the only doubt left is, does the PasswordExpiredControl need something similar to DraftBeheraLDAPPasswordPolicy10RequestControl?
As I mentioned above, you shouldn't have to do anything special in the request to get the password expired response control. If you're not seeing it, then it's probably either because the server doesn't support it or maybe because it's not configured to return it. I'm not an OpenLDAP expert, so I can't say whether it supports it and if so whether there is any associated configuration.
Well, it's probably that, anyway thank you so much for your help!
By the way, the version of ldapsearch that the LDAP SDK provides (
tools/ldapsearch
) has support for both of those controls, so you could test with it before changing your code For example:tools/ldapsearch --hostname myhost --port 636 --useSSL --bindDN dn --promptForBindPassword --usePasswordPolicyControl --baseDN "" --scope base "(objectClass=*)"
If the server includes any controls in the bind response, then they should be written to standard output before the tool attempts the search.
Hello again, do you know if an AD in Windows server 2016 can handle the password expired with the DraftBeheraLDAPPasswordPolicy10RequestControl?
Last edit: Alvaro Felipe Garcia Mendez 2020-09-07
I'm not an AD expert, but it does not appear that its root DSE advertises support for the control, so I would guess that it does not.
By the way, it looks like OpenLDAP version 2.4.51 (released in mid-August) added support for the password expired and password expiring controls.
Well, with OpenLDAP it works neat! but since our customer is using Windows AD we can't make work properly. In fact it ignores many Policies, like Password history, Minimum and Maximum password age but make the password changes and logins succesfully. Anyway, thanks for your time :)
Last edit: Alvaro Felipe Garcia Mendez 2020-09-07