MongoCredential(@Nullable final AuthenticationMechanism mechanism, @Nullable final String userName, final String source, @Nullable final char[] password, final Map<String, Object> mechanismProperties) { if (mechanism != MONGODB_X509 && userName == null) { throw new IllegalArgumentException("username can not be null"); } if (mechanism == null && password == null) { throw new IllegalArgumentException("Password can not be null when the authentication mechanism is unspecified"); } if (mechanismRequiresPassword(mechanism) && password == null) { throw new IllegalArgumentException("Password can not be null for " + mechanism + " mechanism"); } if ((mechanism == GSSAPI || mechanism == MONGODB_X509) && password != null) { throw new IllegalArgumentException("Password must be null for the " + mechanism + " mechanism"); } this.mechanism = mechanism; this.userName = userName; this.source = notNull("source", source); this.password = password != null ? password.clone() : null; this.mechanismProperties = new HashMap<String, Object>(mechanismProperties); }
MongoCredential(@Nullable final AuthenticationMechanism mechanism, @Nullable final String userName, final String source, @Nullable final char[] password, final Map<String, Object> mechanismProperties) { if (mechanism != MONGODB_X509 && userName == null) { throw new IllegalArgumentException("username can not be null"); } if (mechanism == null && password == null) { throw new IllegalArgumentException("Password can not be null when the authentication mechanism is unspecified"); } if (mechanismRequiresPassword(mechanism) && password == null) { throw new IllegalArgumentException("Password can not be null for " + mechanism + " mechanism"); } if ((mechanism == GSSAPI || mechanism == MONGODB_X509) && password != null) { throw new IllegalArgumentException("Password must be null for the " + mechanism + " mechanism"); } this.mechanism = mechanism; this.userName = userName; this.source = notNull("source", source); this.password = password != null ? password.clone() : null; this.mechanismProperties = new HashMap<String, Object>(mechanismProperties); }