work on security uberfire security extension with mongodb
Refactor for Sonarlint
This commit is contained in:
parent
f3beaaabab
commit
7feaeee7d8
9 changed files with 110 additions and 119 deletions
|
|
@ -112,7 +112,18 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
|
||||
@Override
|
||||
public User get(String identifier) throws SecurityManagementException {
|
||||
return new UserImpl(identifier);
|
||||
MongoCollection<Document> userCollection = database.getCollection("user");
|
||||
List<User> users = new ArrayList<>();
|
||||
userCollection.find(eq("login", identifier)).forEach((Block<? super Document>) document -> {
|
||||
String userName = document.getString("login");
|
||||
User user = fillUser(userName, document);
|
||||
users.add(user);
|
||||
});
|
||||
if (users.size()==1){
|
||||
return users.get(0);
|
||||
}else {
|
||||
throw new SecurityManagementException("Unknown identifier "+identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -133,17 +144,15 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
AtomicReference<ArrayList<DBRef>> groups = new AtomicReference<ArrayList<DBRef>>(new ArrayList());
|
||||
roles.set((ArrayList) document.get("userRoles"));
|
||||
groups.set((ArrayList) document.get("userGroups"));
|
||||
MongoCollection<Document> userRolesCollection = database.getCollection("userRoles");
|
||||
List<Role> roleList = new ArrayList<>();
|
||||
for (DBRef dbRef : roles.get()) {
|
||||
Document roleDocument = userRolesCollection.find(eq("_id", dbRef.getId())).first();
|
||||
Document roleDocument = Utils.getDocumentFromRef(dbRef,database);
|
||||
Role role = new RoleImpl(roleDocument.getString("name"));
|
||||
roleList.add(role);
|
||||
}
|
||||
MongoCollection<Document> userGroupsCollection = database.getCollection("userGroups");
|
||||
List<Group> groupList = new ArrayList<>();
|
||||
for (DBRef dbRef : groups.get()) {
|
||||
Document groupDocument = userGroupsCollection.find(eq("_id", dbRef.getId())).first();
|
||||
Document groupDocument = Utils.getDocumentFromRef(dbRef,database);
|
||||
Group group = new GroupImpl(groupDocument.getString("name"));
|
||||
groupList.add(group);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
import com.mongodb.DBRef;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
|
||||
import static com.mongodb.client.model.Filters.eq;
|
||||
|
||||
public class Utils {
|
||||
public static Document getDocumentFromRef(DBRef dbRef, MongoDatabase database){
|
||||
if (dbRef!=null) {
|
||||
MongoCollection<Document> userRolesCollection = database.getCollection(dbRef.getCollectionName());
|
||||
Document document = userRolesCollection.find(eq("_id", dbRef.getId())).first();
|
||||
return document;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue