Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 3f5a7219 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Fix springboot properties

parent c0a2eda7
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 76 deletions
......@@ -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());
}
......
......@@ -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);
......
......@@ -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.
......
......@@ -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 ?
......
......@@ -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";
......
......@@ -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() {
......
......@@ -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.
......
#
# 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
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment