29
29
import com .mongodb .operation .CommandReadOperation ;
30
30
import com .mongodb .operation .CommandWriteOperation ;
31
31
import com .mongodb .operation .CreateCollectionOperation ;
32
- import com .mongodb .operation .CreateUserOperation ;
33
32
import com .mongodb .operation .CreateViewOperation ;
34
33
import com .mongodb .operation .DropDatabaseOperation ;
35
- import com .mongodb .operation .DropUserOperation ;
36
34
import com .mongodb .operation .ListCollectionsOperation ;
37
35
import com .mongodb .operation .ReadOperation ;
38
- import com .mongodb .operation .UpdateUserOperation ;
39
- import com .mongodb .operation .UserExistsOperation ;
40
36
import org .bson .BsonDocument ;
41
37
import org .bson .BsonDocumentWrapper ;
42
38
import org .bson .BsonInt32 ;
52
48
import java .util .concurrent .ConcurrentHashMap ;
53
49
54
50
import static com .mongodb .DBCollection .createWriteConcernException ;
55
- import static com .mongodb .MongoCredential .createMongoCRCredential ;
51
+ import static com .mongodb .MongoCredential .createCredential ;
56
52
import static com .mongodb .MongoNamespace .checkDatabaseNameValidity ;
57
53
import static com .mongodb .ReadPreference .primary ;
58
54
import static com .mongodb .assertions .Assertions .notNull ;
@@ -604,6 +600,7 @@ public CommandResult getStats() {
604
600
/**
605
601
* Adds or updates a user for this database
606
602
*
603
+ * <p>Never create or modify users over an insecure network without the use of TLS.</p>
607
604
* @param userName the user name
608
605
* @param password the password
609
606
* @return the result of executing this operation
@@ -621,6 +618,7 @@ public WriteResult addUser(final String userName, final char[] password) {
621
618
/**
622
619
* Adds or updates a user for this database
623
620
*
621
+ * <p>Never create or modify users over an insecure network without the use of TLS.</p>
624
622
* @param userName the user name
625
623
* @param password the password
626
624
* @param readOnly if true, user will only be able to read
@@ -633,21 +631,21 @@ public WriteResult addUser(final String userName, final char[] password) {
633
631
*/
634
632
@ Deprecated
635
633
public WriteResult addUser (final String userName , final char [] password , final boolean readOnly ) {
636
- MongoCredential credential = createMongoCRCredential (userName , getName (), password );
634
+ MongoCredential credential = createCredential (userName , getName (), password );
637
635
boolean userExists = false ;
638
636
try {
639
- userExists = executor .execute (new UserExistsOperation (getName (), userName ), primary ());
637
+ userExists = executor .execute (new com . mongodb . operation . UserExistsOperation (getName (), userName ), primary ());
640
638
} catch (MongoCommandException e ) {
641
639
if (e .getCode () != 13 ) {
642
640
throw e ;
643
641
}
644
642
}
645
643
try {
646
644
if (userExists ) {
647
- executor .execute (new UpdateUserOperation (credential , readOnly , getWriteConcern ()));
645
+ executor .execute (new com . mongodb . operation . UpdateUserOperation (credential , readOnly , getWriteConcern ()));
648
646
return new WriteResult (1 , true , null );
649
647
} else {
650
- executor .execute (new CreateUserOperation (credential , readOnly , getWriteConcern ()));
648
+ executor .execute (new com . mongodb . operation . CreateUserOperation (credential , readOnly , getWriteConcern ()));
651
649
return new WriteResult (1 , false , null );
652
650
}
653
651
} catch (MongoWriteConcernException e ) {
@@ -667,7 +665,7 @@ public WriteResult addUser(final String userName, final char[] password, final b
667
665
@ Deprecated
668
666
public WriteResult removeUser (final String userName ) {
669
667
try {
670
- executor .execute (new DropUserOperation (getName (), userName , getWriteConcern ()));
668
+ executor .execute (new com . mongodb . operation . DropUserOperation (getName (), userName , getWriteConcern ()));
671
669
return new WriteResult (1 , true , null );
672
670
} catch (MongoWriteConcernException e ) {
673
671
throw createWriteConcernException (e );
0 commit comments