Work on Finish the "drools-framewok-uberfire-security-service" module #97
Allow only users with a user group that gives access to the Workbench #96
This commit is contained in:
parent
f23eec8ec3
commit
3f1187921e
18 changed files with 416 additions and 131 deletions
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.Block;
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
|
@ -37,6 +39,8 @@ import org.uberfire.ext.security.management.util.SecurityManagementUtils;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static com.mongodb.client.model.Filters.eq;
|
||||
|
||||
/**
|
||||
* <p>Groups manager service provider implementation for Apache tomcat, when using default realm based on properties files.</p>
|
||||
* @since 0.8.0
|
||||
|
|
@ -85,14 +89,39 @@ public class KiePlatformGroupManager implements GroupManager, ContextualManager
|
|||
|
||||
@Override
|
||||
public SearchResponse<Group> search(SearchRequest request) throws SecurityManagementException {
|
||||
SearchResponse<Group> result = new SearchResponseImpl<>();
|
||||
return result;
|
||||
MongoCollection<Document> userCollection = database.getCollection("userGroups");
|
||||
BasicDBObject regexQuery = new BasicDBObject();
|
||||
regexQuery.put("name", new BasicDBObject("$regex", request.getSearchPattern() + ".*").append("$options", "i"));
|
||||
List<Group> groups = new ArrayList<>();
|
||||
long totalNumber = userCollection.countDocuments(regexQuery);
|
||||
FindIterable<Document> documents = userCollection.find(regexQuery).skip(request.getPageSize() * (request.getPage() - 1)).limit(request.getPageSize());
|
||||
documents.forEach((Block<? super Document>) document -> {
|
||||
String groupName = document.getString("name");
|
||||
Group group = new GroupImpl(groupName);
|
||||
groups.add(group);
|
||||
});
|
||||
boolean hasNextPage = true;
|
||||
if ((request.getPageSize() * (request.getPage()) > totalNumber)) {
|
||||
hasNextPage = false;
|
||||
}
|
||||
SearchResponse<Group> response = new SearchResponseImpl(groups, request.getPage(), request.getPageSize(), Long.valueOf(totalNumber).intValue(), hasNextPage);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group get(String identifier) throws SecurityManagementException {
|
||||
Group group = new GroupImpl(identifier);
|
||||
return group;
|
||||
MongoCollection<Document> userCollection = database.getCollection("userGroups");
|
||||
List<Group> groups = new ArrayList<>();
|
||||
userCollection.find(eq("name", identifier)).forEach((Block<? super Document>) document -> {
|
||||
String groupName = document.getString("name");
|
||||
Group group = new GroupImpl(groupName);
|
||||
groups.add(group);
|
||||
});
|
||||
if (groups.size() == 1) {
|
||||
return groups.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class KiePlatformSecurityService implements UserManagementService {
|
|||
//-DconnectionString=localhost:28017 -Ddatabase=businessProxyDB
|
||||
|
||||
this.connectionString = System.getProperty("connectionString");
|
||||
this.databaseName=System.getProperty("database");
|
||||
this.databaseName=System.getProperty("name");
|
||||
System.out.println("KiePlatformSecurityService initialized with databaseName = " + connectionString );
|
||||
this.mongoClient = MongoClients.create(connectionString);
|
||||
this.pojoCodecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(),
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@
|
|||
<scope>provided</scope>
|
||||
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.uberfire</groupId>
|
||||
<artifactId>uberfire-rest-backend</artifactId>
|
||||
<version>${jbpm.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.guvnor.common.services.project.model.GAV;
|
|||
import org.guvnor.common.services.project.model.POM;
|
||||
import org.guvnor.common.services.project.model.WorkspaceProject;
|
||||
import org.guvnor.common.services.project.service.WorkspaceProjectService;
|
||||
import org.guvnor.rest.backend.UserManagementResourceHelper;
|
||||
import org.guvnor.structure.organizationalunit.OrganizationalUnit;
|
||||
import org.guvnor.structure.organizationalunit.OrganizationalUnitService;
|
||||
import org.guvnor.structure.repositories.Branch;
|
||||
|
|
@ -18,10 +19,12 @@ import org.guvnor.structure.repositories.Repository;
|
|||
import org.guvnor.structure.repositories.RepositoryService;
|
||||
import org.kie.workbench.common.screens.datamodeller.service.DataModelerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.uberfire.backend.authz.AuthorizationService;
|
||||
import org.uberfire.io.IOService;
|
||||
import org.uberfire.java.nio.base.options.CommentedOption;
|
||||
import org.uberfire.java.nio.file.DirectoryStream;
|
||||
import org.uberfire.java.nio.file.Paths;
|
||||
import org.uberfire.security.authz.PermissionManager;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -63,7 +66,13 @@ public class PackageResource {
|
|||
private WorkspaceProjectService workspaceProjectService;
|
||||
@Inject
|
||||
private AssetService assetService;
|
||||
@Inject
|
||||
private PermissionManager permissionManager;
|
||||
@Inject
|
||||
private AuthorizationService authorizationService;
|
||||
|
||||
@Inject
|
||||
private UserManagementResourceHelper userManagementResourceHelper;
|
||||
|
||||
public PackageResource() {
|
||||
System.out.println("coucou");
|
||||
|
|
@ -76,6 +85,22 @@ public class PackageResource {
|
|||
|
||||
UserLoginInformation userLoginInformation = new UserLoginInformation();
|
||||
|
||||
userLoginInformation.setUsername(sc.getUserPrincipal().getName());
|
||||
for (String role : PermissionConstants.tableauChaine) {
|
||||
if (sc.isUserInRole(role) == true) {
|
||||
userLoginInformation.getRoles().add(role);
|
||||
}
|
||||
}
|
||||
return userLoginInformation;
|
||||
|
||||
}
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/content")
|
||||
public UserLoginInformation getUserContent() {
|
||||
|
||||
UserLoginInformation userLoginInformation = new UserLoginInformation();
|
||||
|
||||
userLoginInformation.setUsername(sc.getUserPrincipal().getName());
|
||||
for (String role : PermissionConstants.tableauChaine) {
|
||||
if (sc.isUserInRole(role) == true) {
|
||||
|
|
@ -86,7 +111,6 @@ public class PackageResource {
|
|||
return userLoginInformation;
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/detailedSpaces")
|
||||
|
|
@ -123,6 +147,8 @@ public class PackageResource {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{organizationalUnitName}/{projectName}/assets")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ public class AssetService {
|
|||
return repoNames;
|
||||
}
|
||||
|
||||
public void todo(){
|
||||
// workspaceProjectService.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue