diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfig.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfig.java index 7b548641f644bac15648f7c5d5619b1388f880f9..084f36cac13d1ab8f0bf0e83147b9d3cd8801098 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfig.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfig.java @@ -40,7 +40,9 @@ import javax.sql.DataSource; public class SMPDatabaseConfig { static final SMPLogger LOG = SMPLoggerFactory.getLogger(SMPDatabaseConfig.class); final DatabaseConnectionBeanCreator databaseConnectionBeanCreator; + public SMPDatabaseConfig() { + databaseConnectionBeanCreator = new DatabaseConnectionBeanCreator(SMPEnvironmentProperties.getInstance()); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentProperties.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentProperties.java index 554d38798786aa497d2a5605c2fb142ab87817ab..48f2fb2a12b03acfb9f9dee4160fb754c31e828c 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentProperties.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentProperties.java @@ -44,9 +44,13 @@ public class SMPEnvironmentProperties implements DatabaseConnectionProperties { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(SMPEnvironmentProperties.class); private static final String CLASSPATH_PROPERTIES = "/smp.config.properties"; + private static final String INIT_SPRINGBOOT_PROPERTIES = "application.properties"; + Properties extInitFileProperties = null; Properties extEnvFileProperties = null; + Properties extSpringBootFileProperties = null; + Properties classPathEnvFileProperties = null; ClassLoader classLoader = null; @@ -88,13 +92,19 @@ public class SMPEnvironmentProperties implements DatabaseConnectionProperties { // get init file property String extInitPropFilePath = getEnvPropertyValue(INIT_CONFIGURATION_FILE); - extInitFileProperties = readProperties(extInitPropFilePath, false); if (extInitFileProperties != null) { LOG.debug("------ Print classPathEnvFileProperties ------"); extInitFileProperties.entrySet().stream().forEach(e -> LOG.info(e.getKey() + ":" + e.getValue())); } + // get init file property + extSpringBootFileProperties = readProperties(INIT_SPRINGBOOT_PROPERTIES, false); + if (extSpringBootFileProperties != null) { + LOG.debug("------ Print extSpringBootFileProperties ------"); + extSpringBootFileProperties.entrySet().stream().forEach(e -> LOG.info(e.getKey() + ":" + e.getValue())); + } + String extAppFilePath = getEnvPropertyValue(CONFIGURATION_FILE); extEnvFileProperties = readProperties(extAppFilePath, false); if (extInitFileProperties != null) { @@ -117,6 +127,7 @@ public class SMPEnvironmentProperties implements DatabaseConnectionProperties { Path initFilePath = Paths.get(path); if (Files.exists(initFilePath)) { + LOG.info("Read properties from file:[{}] ", initFilePath); try (FileInputStream fos = new FileInputStream(initFilePath.toFile())) { return readProperties(fos); } catch (IOException e) { @@ -198,6 +209,13 @@ public class SMPEnvironmentProperties implements DatabaseConnectionProperties { LOG.debug("Got external configuration property: [{}] with value: [{}].", propertyName, propVal); return propVal; } + + if (extSpringBootFileProperties != null && extSpringBootFileProperties.containsKey(propertyName)) { + String propVal = extSpringBootFileProperties.getProperty(propertyName); + LOG.debug("Got springboot configuration property: [{}] with value: [{}].", propertyName, propVal); + return propVal; + } + if (classPathEnvFileProperties != null && classPathEnvFileProperties.containsKey(propertyName)) { String propVal = classPathEnvFileProperties.getProperty(propertyName); LOG.debug("Got classpath configuration property: [{}] with value: [{}].", propertyName, propVal); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java index 3be0c75925e09d688cfa54de152cfe1b41cd581e..36c8521575c2d8740a2e4b6249581d4e7daccb40 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java @@ -13,6 +13,7 @@ package eu.europa.ec.edelivery.smp.data.dao; +import eu.europa.ec.edelivery.smp.data.enums.MembershipRoleType; import eu.europa.ec.edelivery.smp.data.model.DBDomain; import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; @@ -23,6 +24,7 @@ import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; import javax.persistence.TypedQuery; import javax.transaction.Transactional; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -110,6 +112,26 @@ public class DomainDao extends BaseDao<DBDomain> { return query.getSingleResult(); } + public Long getDomainsByUserIdAndRolesCount(Long userId, List<MembershipRoleType> roleTypes) { + if (roleTypes.isEmpty()) { + return 0L; + } + TypedQuery<Long> query = memEManager.createNamedQuery(QUERY_DOMAIN_BY_USER_ROLES_COUNT, Long.class); + query.setParameter(PARAM_USER_ID, userId); + query.setParameter(PARAM_MEMBERSHIP_ROLES, roleTypes); + return query.getSingleResult(); + } + + public List<DBDomain> getDomainsByUserIdAndRoles(Long userId, List<MembershipRoleType> roleTypes) { + if (roleTypes.isEmpty()) { + return Collections.emptyList(); + } + TypedQuery<DBDomain> query = memEManager.createNamedQuery(QUERY_DOMAIN_BY_USER_ROLES, DBDomain.class); + query.setParameter(PARAM_USER_ID, userId); + query.setParameter(PARAM_MEMBERSHIP_ROLES, roleTypes); + return query.getResultList(); + } + /** * Check if domain for domain code exists. If not SMPRuntimeException with DOMAIN_NOT_EXISTS is thrown. * If code is null or blank - then null is returned. diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDao.java index f04fc0c7de1fe44c6933f68f4a2235ab025df6ba..e4740a158ff32298d700f167118fef19da2c7738 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDao.java @@ -60,6 +60,17 @@ public class DomainMemberDao extends BaseDao<DBDomainMember> { return query.getResultList().stream().anyMatch(member -> member.getRole() == roleType); } + public boolean isUserDomainAdministrator(Long userId){ + return false; + } + public boolean isUserGroupAdministrator(Long userId){ + return false; + } + + public boolean isUserMemberAdministrator(Long userId){ + return false; + } + public List<DBDomainMember> getDomainMembers(Long domainId, int iPage, int iPageSize, String filter) { boolean hasFilter = StringUtils.isNotBlank(filter); TypedQuery<DBDomainMember> query = memEManager.createNamedQuery(hasFilter ? diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/QueryNames.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/QueryNames.java index aa93f3db7ef25f2678cddd6f382df870ccc237ee..2e9b56e51feaad78833e4d4bc4e37f17a50155b6 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/QueryNames.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/QueryNames.java @@ -13,6 +13,9 @@ public class QueryNames { public static final String QUERY_DOMAIN_ALL = "DBDomain.getAll"; public static final String QUERY_DOMAIN_CODE = "DBDomain.getDomainByCode"; + + public static final String QUERY_DOMAIN_BY_USER_ROLES_COUNT = "DBDomain.getByUserAndRolesCount"; + public static final String QUERY_DOMAIN_BY_USER_ROLES = "DBDomain.getByUserAmdRoles"; public static final String QUERY_EXTENSION_ALL = "DBExtension.getAll"; public static final String QUERY_EXTENSION_BY_IDENTIFIER = "DBExtension.getByIdentifier"; @@ -37,7 +40,6 @@ public class QueryNames { public static final String QUERY_DOMAIN_RESOURCE_DEF_DOMAIN_RES_DEF = "DBDomainResourceDef.getByDomainResDef"; - public static final String QUERY_RESOURCE_BY_IDENTIFIER_RESOURCE_DEF_DOMAIN = "DBResource.getResByIdentifierAndResourceDefAndDomain"; public static final String QUERY_RESOURCES_BY_DOMAIN_ID_COUNT = "DBResource.getResByDomainIdCount"; public static final String QUERY_RESOURCES_BY_DOMAIN_ID_RESOURCE_DEF_ID_COUNT = "DBResource.getResByDomainIdAndResourceDefCount"; @@ -123,6 +125,8 @@ public class QueryNames { public static final String PARAM_GROUP_IDS = "group_ids"; public static final String PARAM_MEMBERSHIP_ROLE = "membership_role"; + + public static final String PARAM_MEMBERSHIP_ROLES = "membership_roles"; public static final String PARAM_USER_USERNAME = "username"; public static final String IDENTIFIER_VALUE = "identifier_value"; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java index 63e5c96bf93b730f036a21f0b4c6294b19ef98d9..49c3c4c7e1bbda962c8490f74ea341f3317c0a07 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java @@ -41,6 +41,13 @@ import static eu.europa.ec.edelivery.smp.data.dao.QueryNames.*; @NamedNativeQuery(name = "DBDomain.updateNullSMLAlias", query = "update SMP_DOMAIN set SIGNATURE_KEY_ALIAS=:alias " + "WHERE SML_CLIENT_KEY_ALIAS IS null") + +@NamedQuery(name = QUERY_DOMAIN_BY_USER_ROLES_COUNT, query = "SELECT count(c) FROM DBDomain c JOIN DBDomainMember dm " + + "WHERE c.id = dm.domain.id and dm.role in (:membership_roles) and dm.user.id= :user_id") + +@NamedQuery(name = QUERY_DOMAIN_BY_USER_ROLES, query = "SELECT c FROM DBDomain c JOIN DBDomainMember dm " + + "WHERE c.id = dm.domain.id and dm.role in (:membership_roles) and dm.user.id= :user_id") + @org.hibernate.annotations.Table(appliesTo = "SMP_DOMAIN", comment = "SMP can handle multiple domains. This table contains domain specific data") public class DBDomain extends BaseEntity { @@ -109,7 +116,7 @@ public class DBDomain extends BaseEntity { orphanRemoval = true, fetch = FetchType.LAZY ) - private List<DBDomainResourceDef> domainResourceDefs= new ArrayList<>(); + private List<DBDomainResourceDef> domainResourceDefs = new ArrayList<>(); @Override public Long getId() { diff --git a/smp-springboot/README.md b/smp-springboot/README.md index 29b5140438e7050df3bf897d1d50060c676c256e..966025b15a69e01a94be3f1ce79b6161a311c9a3 100644 --- a/smp-springboot/README.md +++ b/smp-springboot/README.md @@ -61,8 +61,7 @@ and insert the init data from ``` #!/bin/sh -PROJECT_HOME=[The DomiSMP project home: exp.: /code/smp] -SQLFOLDER=$PROJECT_HOME/smp-webapp/src/main/sml-setup/database-scripts/ +PROJECT_HOME=/cef/code/smp DATABASE=smpdb DB_ADMIN=root @@ -76,9 +75,9 @@ mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD -e "drop schema if # create new database echo "create database" -mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$SQLFOLDER/mysql5innodb.ddl" +mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$PROJECT_HOME/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb.ddl" echo "init database for soapui tests" -mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$PROJECT_HOME/smp-soapui-tests/src/test/resources/init-data/init-test-mysql-soapui.sql" +mysql -h localhost -u $DB_ADMIN --password=$DB_ADMIN_PASSWORD $DATABASE < "$PROJECT_HOME/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql" ``` ### Prepare the DomiSMP database configuration. @@ -96,6 +95,7 @@ The configuration properties must be set in the file "application.properties" an spring-boot application. For alternatives on how to set spring-boot properties please read the spring-boot documentation; for the DomiSMP startup properties, please read the DomiSMP Admin guide. +NOTE: Only the "java property type" of the springboot properties format is supported (json or yaml types are not supported!) Example of the springboot configuration: application.properties: NOTE: Please update the properties to meet you local mysql installation configuration @@ -105,11 +105,16 @@ NOTE: Please update the properties to meet you local mysql installation configur server.port=8084 # Database configuration -smp.jdbc.hibernate.dialect=org.hibernate.dialect.MySQLDialect -smp.jdbc.driver=com.mysql.cj.jdbc.Driver -smp.jdbc.url=jdbc:mysql://localhost:3306/smpdb?allowPublicKeyRetrieval=true -smp.jdbc.user=smltest -smp.jdbc.password=smltest +smp.jdbc.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect + +# ********************************* +# Custom defined datasource +# ********************************* +# mysql database example +smp.jdbc.driver=com.mysql.jdbc.Driver +smp.jdbc.url=jdbc:mysql://localhost:3306/smpdb +smp.jdbc.user=smp +smp.jdbc.password=smp ``` ### Start the application. diff --git a/smp-springboot/src/main/resources/smp.config.properties b/smp-springboot/src/main/resources/smp.config.properties deleted file mode 100644 index 922d29aa971b07e1ca20b567102331edfe4a04a6..0000000000000000000000000000000000000000 --- a/smp-springboot/src/main/resources/smp.config.properties +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright 2018 European Commission | CEF eDelivery -# -# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# -# You may obtain a copy of the Licence attached in file: LICENCE-EUPL-v1.2.pdf -# -# Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the Licence for the specific language governing permissions and limitations under the Licence. -# - -# ************************************************************************** -# Database connection can be achieved using custom datasource configuration -# or reusing application server datasource. -# ************************************************************************** -## set database hibernate dialect -#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect -smp.jdbc.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect - -# ********************************* -# Custom defined datasource -# ********************************* -# mysql database example -smp.jdbc.driver=com.mysql.jdbc.Driver -smp.jdbc.url=jdbc:mysql://localhost:3306/smpdbdtest -smp.jdbc.user=smptest -smp.jdbc.password=smptest - -# Oracle database example -#smp.jdbc.driver = oracle.jdbc.driver.OracleDriver -#smp.jdbc.url=jdbc:oracle:thin:@localhost:1521/xe -#smp.jdbc.user=smp -#smp.jdbc.password=secret123 - - -# ********************************* -# Datasource JNDI configuration alternative -# ********************************* -# weblogic datasource JNDI example -# smp.datasource.jndi=jdbc/eDeliverySmpDs -# tomcat datasource JNDI example -# smp.datasource.jndi=java:comp/env/jdbc/eDeliverySmpDs - - -# ********************************* -# Logging properties -# ********************************* -# smp log folder -# smp.log.folder=../logs/ - -# custom logback configuration file -# smp.log.configuration.file=smp-logback.xml - -# ********************************* -# Extension folder -# ********************************* -# path where SMP extensions are located. The Folder is loaded by the SMP classloader at startup. -# smp.libraries.folder=/cef/test/smp/apache-tomcat-8.5.73/smp/ext-lib - - - - diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/UserResource.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/UserResource.java index d60307bd8a301206f215417a51d97fb44e8a343c..4cd77619294efb860817bbd9c76b3b9b80c644a9 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/UserResource.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/ui/external/UserResource.java @@ -120,6 +120,7 @@ public class UserResource { DBUser user = uiUserService.findUser(entityId); NavigationTreeNodeRO home = new NavigationTreeNodeRO("home", "Home", "home", ""); home.addChild(createPublicNavigationTreeNode()); + // home.addChild(createEditNavigationTreeNode()); if (user.getApplicationRole() == ApplicationRoleType.SYSTEM_ADMIN) { home.addChild(createSystemAdminNavigationTreeNode()); } @@ -278,4 +279,17 @@ public class UserResource { node.addChild(new NavigationTreeNodeRO("system-admin-alert", "Alerts", "notifications", "alert")); return node; } + + protected NavigationTreeNodeRO createEditNavigationTreeNode() { + NavigationTreeNodeRO node = new NavigationTreeNodeRO("admin-entities", "Administration", "settings", "admin-entities"); + // is domain admin + + node.addChild(new NavigationTreeNodeRO("admin-domain", "Edit domains", "account_circle", "admin-domain")); + // is group admin + node.addChild(new NavigationTreeNodeRO("admin-group", "Edit groups", "key", "admin-group")); + // is resource admin + node.addChild(new NavigationTreeNodeRO("admin-resource", "Edit resources", "article", "admin-resource")); + // node.addChild(new NavigationTreeNodeRO("user-data-membership", "Membership", "person", "user-membership")); + return node; + } }