Skip to content

Commit

Permalink
avoid NPE and throw a better exception (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-patricelli authored Apr 7, 2022
1 parent 29ca317 commit 4bd87ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/main/java/net/tirasa/connid/bundles/ad/ADConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
import net.tirasa.connid.bundles.ad.schema.ADSchema;
import net.tirasa.connid.bundles.ad.util.TrustAllSocketFactory;
import net.tirasa.connid.bundles.ldap.LdapConnection;
import net.tirasa.connid.bundles.ldap.LdapConnection.AuthenticationResult;
import net.tirasa.connid.bundles.ldap.LdapConnection.AuthenticationResultType;
import org.identityconnectors.common.Pair;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.common.security.GuardedString.Accessor;
import org.identityconnectors.framework.common.exceptions.ConnectorException;
import org.identityconnectors.framework.common.exceptions.InvalidCredentialException;

public class ADConnection extends LdapConnection {

Expand Down Expand Up @@ -207,7 +206,7 @@ private Pair<AuthenticationResult, LdapContext> createContext(
@Override
public void access(char[] clearChars) {
if(clearChars == null || clearChars.length == 0){
throw new IllegalArgumentException("Password is blank");
throw new InvalidCredentialException("Password is blank");
}
env.put(Context.SECURITY_CREDENTIALS, new String(clearChars));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ public Uid authenticate(GuardedString password) {

private static boolean isSuccess(final AuthenticationResult authResult) {
// PASSWORD_EXPIRED considered success: credentials were right.
final AuthenticationResultType type = authResult.getType();

return authResult != null
&& (type.equals(AuthenticationResultType.SUCCESS)
|| type.equals(AuthenticationResultType.PASSWORD_EXPIRED));
&& (authResult.getType().equals(AuthenticationResultType.SUCCESS)
|| authResult.getType().equals(AuthenticationResultType.PASSWORD_EXPIRED));
}

private ConnectorObject getObjectToAuthenticate() {
Expand Down

0 comments on commit 4bd87ad

Please sign in to comment.