work on login module
This commit is contained in:
parent
760ae20f49
commit
6c625e1edb
12 changed files with 151 additions and 46 deletions
|
|
@ -68,12 +68,11 @@
|
|||
<version>1</version>
|
||||
</dependency>
|
||||
|
||||
<!--dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver</artifactId>
|
||||
<version>${version.mongodb.driver}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency-->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.jboss.errai.security.shared.api.Group;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -45,6 +48,11 @@ public class KiePlatformGroupManager implements GroupManager, ContextualManager
|
|||
|
||||
IdentifierRuntimeSearchEngine<Group> groupsSearchEngine;
|
||||
|
||||
private MongoClient mongoClient;
|
||||
private CodecRegistry pojoCodecRegistry;
|
||||
private MongoDatabase database;
|
||||
|
||||
|
||||
public KiePlatformGroupManager() {
|
||||
this(new ConfigProperties(System.getProperties()));
|
||||
}
|
||||
|
|
@ -58,6 +66,12 @@ public class KiePlatformGroupManager implements GroupManager, ContextualManager
|
|||
// loadConfig(gitPrefs);
|
||||
}
|
||||
|
||||
public void setMongo (MongoClient mongoClient,CodecRegistry pojoCodecRegistry,MongoDatabase database){
|
||||
this.mongoClient=mongoClient;
|
||||
this.pojoCodecRegistry = pojoCodecRegistry;
|
||||
this.database=database;
|
||||
|
||||
}
|
||||
@Override
|
||||
public void initialize(UserSystemManager userSystemManager) throws Exception {
|
||||
groupsSearchEngine = new GroupsIdentifierRuntimeSearchEngine();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
|
@ -16,52 +16,65 @@
|
|||
|
||||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
import org.jboss.errai.security.shared.api.Group;
|
||||
import com.mongodb.Block;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.jboss.errai.security.shared.api.Role;
|
||||
import org.jboss.errai.security.shared.api.RoleImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.uberfire.commons.config.ConfigProperties;
|
||||
import org.uberfire.ext.security.management.api.*;
|
||||
import org.uberfire.ext.security.management.api.exception.SecurityManagementException;
|
||||
import org.uberfire.ext.security.management.api.exception.UnsupportedServiceCapabilityException;
|
||||
import org.uberfire.ext.security.management.impl.RoleManagerSettingsImpl;
|
||||
import org.uberfire.ext.security.management.search.GroupsIdentifierRuntimeSearchEngine;
|
||||
import org.uberfire.ext.security.management.search.IdentifierRuntimeSearchEngine;
|
||||
import org.uberfire.ext.security.management.impl.SearchResponseImpl;
|
||||
import org.uberfire.ext.security.management.util.SecurityManagementUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>Groups manager service provider implementation for Apache tomcat, when using default realm based on properties files.</p>
|
||||
*
|
||||
* @since 0.8.0
|
||||
*/
|
||||
public class KiePlatformRoleManager implements RoleManager,ContextualManager {
|
||||
public class KiePlatformRoleManager implements RoleManager, ContextualManager {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(KiePlatformRoleManager.class);
|
||||
|
||||
|
||||
|
||||
IdentifierRuntimeSearchEngine<Group> groupsSearchEngine;
|
||||
private MongoClient mongoClient;
|
||||
private CodecRegistry pojoCodecRegistry;
|
||||
private MongoDatabase database;
|
||||
|
||||
public KiePlatformRoleManager() {
|
||||
this(new ConfigProperties(System.getProperties()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public KiePlatformRoleManager(final Map<String, String> gitPrefs) {
|
||||
this(new ConfigProperties(gitPrefs));
|
||||
}
|
||||
|
||||
public KiePlatformRoleManager(final ConfigProperties gitPrefs) {
|
||||
// loadConfig(gitPrefs);
|
||||
// loadConfig(gitPrefs);
|
||||
}
|
||||
|
||||
public void setMongo(MongoClient mongoClient, CodecRegistry pojoCodecRegistry, MongoDatabase database) {
|
||||
this.mongoClient = mongoClient;
|
||||
this.pojoCodecRegistry = pojoCodecRegistry;
|
||||
this.database = database;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(UserSystemManager userSystemManager) throws Exception {
|
||||
groupsSearchEngine = new GroupsIdentifierRuntimeSearchEngine();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -72,48 +85,58 @@ public class KiePlatformRoleManager implements RoleManager,ContextualManager {
|
|||
|
||||
@Override
|
||||
public SearchResponse<Role> search(SearchRequest request) throws SecurityManagementException {
|
||||
throw new UnsupportedServiceCapabilityException(Capability.CAN_SEARCH_ROLES);
|
||||
SearchResponse<Role> roleSearchResponse = new SearchResponseImpl<>();
|
||||
return roleSearchResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role get(String identifier) throws SecurityManagementException {
|
||||
throw new UnsupportedServiceCapabilityException(Capability.CAN_READ_ROLE);
|
||||
RoleImpl role = new RoleImpl(identifier);
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Role> getAll() throws SecurityManagementException {
|
||||
return null;
|
||||
|
||||
MongoCollection<Document> userRolesCollection = database.getCollection("userRoles");
|
||||
List<Role> roles = new ArrayList<>();
|
||||
userRolesCollection.find().forEach((Block<? super Document>) document -> {
|
||||
String roleName = document.getString("name");
|
||||
RoleImpl role = new RoleImpl(roleName);
|
||||
roles.add(role);
|
||||
});
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role create(Role entity) throws SecurityManagementException {
|
||||
throw new UnsupportedServiceCapabilityException(Capability.CAN_ADD_ROLE);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role update(Role entity) throws SecurityManagementException {
|
||||
throw new UnsupportedServiceCapabilityException(Capability.CAN_UPDATE_ROLE);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(String... identifiers) throws SecurityManagementException {
|
||||
throw new UnsupportedServiceCapabilityException(Capability.CAN_DELETE_ROLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleManagerSettings getSettings() {
|
||||
final Map<Capability, CapabilityStatus> capabilityStatusMap = new HashMap<Capability, CapabilityStatus>(8);
|
||||
final Map<Capability, CapabilityStatus> capabilityStatusMap = new HashMap<>(8);
|
||||
for (final Capability capability : SecurityManagementUtils.ROLES_CAPABILITIES) {
|
||||
capabilityStatusMap.put(capability,
|
||||
getCapabilityStatus(capability));
|
||||
getCapabilityStatus(capability));
|
||||
}
|
||||
return new RoleManagerSettingsImpl(capabilityStatusMap);
|
||||
}
|
||||
|
||||
protected CapabilityStatus getCapabilityStatus(Capability capability) {
|
||||
/**
|
||||
|
||||
if (capability != null) {
|
||||
switch (capability) {
|
||||
case CAN_SEARCH_ROLES:
|
||||
|
|
@ -124,7 +147,7 @@ public class KiePlatformRoleManager implements RoleManager,ContextualManager {
|
|||
return CapabilityStatus.ENABLED;
|
||||
}
|
||||
}
|
||||
**/
|
||||
|
||||
return CapabilityStatus.UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.bson.codecs.pojo.PojoCodecProvider;
|
||||
import org.uberfire.ext.security.management.api.GroupManager;
|
||||
import org.uberfire.ext.security.management.api.RoleManager;
|
||||
import org.uberfire.ext.security.management.api.UserManagementService;
|
||||
|
|
@ -10,6 +16,9 @@ import javax.enterprise.context.Dependent;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
|
||||
import static org.bson.codecs.configuration.CodecRegistries.fromRegistries;
|
||||
|
||||
@Dependent
|
||||
@Named(value = "PymmaKieSecurityService")
|
||||
public class KiePlatformSecurityService implements UserManagementService {
|
||||
|
|
@ -20,30 +29,32 @@ public class KiePlatformSecurityService implements UserManagementService {
|
|||
|
||||
private String connectionString;
|
||||
private String databaseName;
|
||||
// private MongoClient mongoClient;
|
||||
// private CodecRegistry pojoCodecRegistry;
|
||||
//private MongoDatabase database;
|
||||
private MongoClient mongoClient;
|
||||
private CodecRegistry pojoCodecRegistry;
|
||||
private MongoDatabase database;
|
||||
|
||||
|
||||
public KiePlatformSecurityService() {
|
||||
System.out.println("KiePlatformSecurityService initialized with databaseName = " + connectionString );
|
||||
}
|
||||
|
||||
@Inject
|
||||
public KiePlatformSecurityService(KiePlatformUserManager userManager,
|
||||
KiePlatformGroupManager groupManager,
|
||||
KiePlatformRoleManager roleManager) {
|
||||
//-DconnectionString=localhost:28017 -Ddatabase=businessProxyDB
|
||||
|
||||
connectionString = System.getProperty("connectionString");
|
||||
databaseName=System.getProperty("name");
|
||||
databaseName=System.getProperty("database");
|
||||
System.out.println("KiePlatformSecurityService initialized with databaseName = " + connectionString );
|
||||
//mongoClient = MongoClients.create(connectionString);
|
||||
//pojoCodecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(),
|
||||
// fromProviders(PojoCodecProvider.builder().automatic(true).build()));
|
||||
// database = mongoClient.getDatabase(databaseName).withCodecRegistry(pojoCodecRegistry);
|
||||
mongoClient = MongoClients.create(connectionString);
|
||||
pojoCodecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(),
|
||||
fromProviders(PojoCodecProvider.builder().automatic(true).build()));
|
||||
database = mongoClient.getDatabase(databaseName).withCodecRegistry(pojoCodecRegistry);
|
||||
System.out.println("All setup");
|
||||
this.userManager = userManager;
|
||||
this.groupManager = groupManager;
|
||||
this.roleManager = roleManager;
|
||||
this.userManager.setMongo(mongoClient,pojoCodecRegistry,database);
|
||||
this.groupManager.setMongo(mongoClient,pojoCodecRegistry,database);
|
||||
this.roleManager.setMongo(mongoClient,pojoCodecRegistry,database);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.chtijbug.guvnor.uberfire.security;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.jboss.errai.security.shared.api.identity.User;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -42,7 +45,9 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
UserSystemManager userSystemManager;
|
||||
IdentifierRuntimeSearchEngine<User> usersSearchEngine;
|
||||
|
||||
|
||||
private MongoClient mongoClient;
|
||||
private CodecRegistry pojoCodecRegistry;
|
||||
private MongoDatabase database;
|
||||
|
||||
public KiePlatformUserManager() {
|
||||
this(new ConfigProperties(System.getProperties()));
|
||||
|
|
@ -56,7 +61,12 @@ public class KiePlatformUserManager implements UserManager, ContextualManager {
|
|||
//loadConfig(gitPrefs);
|
||||
}
|
||||
|
||||
public void setMongo (MongoClient mongoClient,CodecRegistry pojoCodecRegistry,MongoDatabase database){
|
||||
this.mongoClient=mongoClient;
|
||||
this.pojoCodecRegistry = pojoCodecRegistry;
|
||||
this.database=database;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final UserSystemManager userSystemManager) throws Exception {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
org.jboss.weld.level=DEBUG
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<jboss-deployment-structure>
|
||||
|
||||
<deployment>
|
||||
|
||||
<dependencies>
|
||||
<module name="com.pymmasoftware.pymma-kie-loginmodule" export="TRUE" />
|
||||
</dependencies>
|
||||
|
||||
</deployment>
|
||||
|
||||
</jboss-deployment-structure>
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue