bug: Fixed NPE.

This commit is contained in:
yadong.zhang 2021-10-08 16:59:07 +08:00
parent 38c8dda0a3
commit 320d14fa14
2 changed files with 7 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import com.fujieid.jap.core.store.JapUserStore;
import com.fujieid.jap.core.strategy.AbstractJapStrategy;
import com.fujieid.jap.http.JapHttpRequest;
import com.fujieid.jap.http.JapHttpResponse;
import com.fujieid.jap.ldap.exception.LdapPasswordException;
import com.fujieid.jap.ldap.model.LdapPerson;
import com.fujieid.jap.ldap.template.LdapDefaultTemplate;
import com.fujieid.jap.ldap.template.LdapTemplate;
@ -68,6 +69,9 @@ public class LdapStrategy extends AbstractJapStrategy {
String password = request.getParameter(ldapConfig.getPasswordField());
LdapTemplate ldapTemplate = new LdapDefaultTemplate(new LdapDataSource(ldapConfig));
LdapPerson ldapPerson = ldapTemplate.login(username, password);
if (null == ldapPerson) {
throw new LdapPasswordException(JapErrorCode.INVALID_PASSWORD);
}
JapUser japUser = this.japUserService.createAndGetLdapUser(ldapPerson);
if (null == japUser) {
return JapResponse.error(JapErrorCode.UNABLE_SAVE_USERINFO);

View File

@ -83,6 +83,9 @@ public class LdapDefaultTemplate implements LdapTemplate {
@Override
public LdapPerson login(String userName, String password) {
LdapPerson ldapPerson = this.findPerson(userName);
if (null == ldapPerson) {
return null;
}
LdapPasswordMatch ldapPasswordMatch = LdapPasswordMatchFactory.getMatcherByPassword(ldapPerson.getPassword());
if (ldapPasswordMatch.matches(password, ldapPerson.getPassword())) {
return ldapPerson;