Start some documentation
Refactor Admin-UI Finish the "drools-framewok-uberfire-security-service" module #97
This commit is contained in:
parent
3f1187921e
commit
13bd10561b
16 changed files with 270 additions and 101 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;
|
||||
|
|
@ -38,6 +40,8 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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>
|
||||
*
|
||||
|
|
@ -85,14 +89,39 @@ public class KiePlatformRoleManager implements RoleManager, ContextualManager {
|
|||
|
||||
@Override
|
||||
public SearchResponse<Role> search(SearchRequest request) throws SecurityManagementException {
|
||||
SearchResponse<Role> roleSearchResponse = new SearchResponseImpl<>();
|
||||
return roleSearchResponse;
|
||||
MongoCollection<Document> roleCollection = database.getCollection("userRoles");
|
||||
BasicDBObject regexQuery = new BasicDBObject();
|
||||
regexQuery.put("name", new BasicDBObject("$regex", request.getSearchPattern() + ".*").append("$options", "i"));
|
||||
List<Role> roles = new ArrayList<>();
|
||||
long totalNumber = roleCollection.countDocuments(regexQuery);
|
||||
FindIterable<Document> documents = roleCollection.find(regexQuery).skip(request.getPageSize() * (request.getPage() - 1)).limit(request.getPageSize());
|
||||
documents.forEach((Block<? super Document>) document -> {
|
||||
String roleName = document.getString("name");
|
||||
Role role = new RoleImpl(roleName);
|
||||
roles.add(role);
|
||||
});
|
||||
boolean hasNextPage = true;
|
||||
if ((request.getPageSize() * (request.getPage()) > totalNumber)) {
|
||||
hasNextPage = false;
|
||||
}
|
||||
SearchResponse<Role> response = new SearchResponseImpl(roles, request.getPage(), request.getPageSize(), Long.valueOf(totalNumber).intValue(), hasNextPage);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role get(String identifier) throws SecurityManagementException {
|
||||
RoleImpl role = new RoleImpl(identifier);
|
||||
return role;
|
||||
MongoCollection<Document> userCollection = database.getCollection("userRoles");
|
||||
List<Role> roles = new ArrayList<>();
|
||||
userCollection.find(eq("name", identifier)).forEach((Block<? super Document>) document -> {
|
||||
String roleName = document.getString("name");
|
||||
Role role = new RoleImpl(roleName);
|
||||
roles.add(role);
|
||||
});
|
||||
if (roles.size() == 1) {
|
||||
return roles.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.mongodb.client.MongoCollection;
|
|||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.jboss.errai.security.shared.api.Group;
|
||||
import org.jboss.errai.security.shared.api.GroupImpl;
|
||||
import org.jboss.errai.security.shared.api.Role;
|
||||
|
|
@ -179,7 +178,7 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
MongoCollection<Document> userRolesCollection = database.getCollection("userRoles");
|
||||
AtomicReference<ArrayList<DBRef>> roles = new AtomicReference<>(new ArrayList<>());
|
||||
AtomicReference<ArrayList<DBRef>> groups = new AtomicReference<>(new ArrayList<>());
|
||||
List<Document> users = new ArrayList<>();
|
||||
ArrayList<Document> users = new ArrayList<>();
|
||||
if (isCreated) {
|
||||
userCollection.find(eq("login", entity.getIdentifier())).forEach((Block<? super Document>) document -> {
|
||||
throw new SecurityManagementException("Existing identifier " + entity.getIdentifier());
|
||||
|
|
@ -211,15 +210,21 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
roles.get().add(dbRef);
|
||||
});
|
||||
}
|
||||
Document userDocument = new Document("_id", new ObjectId());
|
||||
userDocument.append("login", entity.getIdentifier());
|
||||
userDocument.append("password", entity.getIdentifier());
|
||||
userDocument.append("userRoles", roles);
|
||||
userDocument.append("userGroups", groups);
|
||||
|
||||
if (isCreated) {
|
||||
Document userDocument = new Document();
|
||||
userDocument.append("login", entity.getIdentifier());
|
||||
userDocument.append("password", entity.getIdentifier());
|
||||
userDocument.append("userRoles", roles);
|
||||
userDocument.append("userGroups", groups);
|
||||
|
||||
userCollection.insertOne(userDocument);
|
||||
} else {
|
||||
userCollection.replaceOne(eq("login", entity.getIdentifier()), userDocument);
|
||||
userCollection.find(eq("login", entity.getIdentifier())).forEach((Block<? super Document>) document -> {
|
||||
document.append("userRoles", roles);
|
||||
document.append("userGroups", groups);
|
||||
userCollection.replaceOne(eq("login", entity.getIdentifier()), document);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ 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.AuthorizationPolicy;
|
||||
import org.uberfire.security.authz.PermissionManager;
|
||||
import org.uberfire.security.impl.authz.AuthorizationPolicyBuilder;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -461,4 +463,21 @@ public class PackageResource {
|
|||
}
|
||||
|
||||
}
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/auth")
|
||||
public AuthorizationPolicy getAuth() {
|
||||
|
||||
AuthorizationPolicy authorizationPolicy = this.permissionManager.getAuthorizationPolicy();
|
||||
return authorizationPolicy;
|
||||
}
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/auth2")
|
||||
public AuthorizationPolicy getAuth2() {
|
||||
AuthorizationPolicyBuilder tata = this.permissionManager.newAuthorizationPolicy();
|
||||
|
||||
AuthorizationPolicy authorizationPolicy = this.permissionManager.getAuthorizationPolicy();
|
||||
return authorizationPolicy;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue