Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
<option name="HOST" value="serverdev" />
|
||||
<option name="PORT" value="8002" />
|
||||
<option name="AUTO_RESTART" value="false" />
|
||||
<RunnerSettings RunnerId="Debug">
|
||||
<option name="DEBUG_PORT" value="8002" />
|
||||
<option name="LOCAL" value="false" />
|
||||
</RunnerSettings>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -27,7 +27,7 @@ public class EmsDBConst {
|
||||
}
|
||||
|
||||
|
||||
public class Const {
|
||||
public static class Const {
|
||||
|
||||
private String applicationDbName;
|
||||
private String nomeAzienda;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250128113218 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Carelli_Murgia))
|
||||
createOrUpdateView("gvw_part_iva_infragroup",
|
||||
"CREATE VIEW [dbo].[gvw_part_iva_infragroup] AS\n" +
|
||||
" SELECT part_iva\n" +
|
||||
" FROM murgia.dbo.azienda\n");
|
||||
else if (isCustomerDb(IntegryCustomerDB.Carelli_Format))
|
||||
createOrUpdateView("gvw_part_iva_infragroup",
|
||||
"CREATE VIEW [dbo].[gvw_part_iva_infragroup] AS\n" +
|
||||
" SELECT part_iva\n" +
|
||||
" FROM format.dbo.azienda\n");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250128123943 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetup("W_VLIST_AGG_LAST_DOC_DISP", "DATAWINDOW", "D_VLIST_AGG_ULTC_REP", null,
|
||||
null, false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
|
||||
createSetup("W_VLIST_AGG_LAST_DOC_DISP", "DATAWINDOW", "D_VLIST_AGG_LAST_DOC_REP", null,
|
||||
null, false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250128152927 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateFunction("getsitartadataDett", "CREATE FUNCTION [dbo].[getsitartadataDett](@adt_adata datetime, @codMdep varchar(8000)) RETURNS TABLE AS \n" +
|
||||
"return \n" +
|
||||
"with anno as (\n" +
|
||||
"select case\n" +
|
||||
" when year(IsNull(@adt_adata, GetDate()) + 1) <= azienda.anno_magaz\n" +
|
||||
" then year(IsNull(@adt_adata, GetDate()) + 1) \n" +
|
||||
" else azienda.anno_magaz end as anno_iniz FROM azienda ),\n" +
|
||||
"periodo as \n" +
|
||||
"(select data_iniz from gtb_periodo_fisc inner join anno on gtb_periodo_fisc.anno = anno.anno_iniz) ,\n" +
|
||||
"movimenti as (\n" +
|
||||
"select mtb_sart.cod_mdep,\n" +
|
||||
" mtb_sart.cod_mart,\n" +
|
||||
" mtb_sart_dt.partita_mag,\n" +
|
||||
" mtb_sart_dt.cod_col,\n" +
|
||||
" mtb_sart_dt.cod_tagl,\n" +
|
||||
" mtb_sart_dt.qta_iniz,\n" +
|
||||
" CONVERT(numeric(20, 5), 0) as qta_car,\n" +
|
||||
" CONVERT(numeric(20, 5), 0) as qta_scar,\n" +
|
||||
" mtb_sart_dt.num_iniz,\n" +
|
||||
" CONVERT(numeric(20, 5), 0) as num_car,\n" +
|
||||
" CONVERT(numeric(20, 5), 0) as num_scar\n" +
|
||||
" from mtb_sart\n" +
|
||||
" INNER JOIN mtb_aart ON mtb_sart.cod_mart = mtb_aart.cod_mart\n" +
|
||||
" INNER JOIN mtb_grup ON mtb_aart.cod_mgrp = mtb_grup.cod_mgrp\n" +
|
||||
" INNER JOIN mtb_depo ON mtb_sart.cod_mdep = mtb_depo.cod_mdep\n" +
|
||||
" INNER JOIN mtb_sart_dt ON mtb_sart.cod_mdep = mtb_sart_dt.cod_mdep\n" +
|
||||
" and mtb_sart.cod_mart = mtb_sart_dt.cod_mart\n" +
|
||||
" and mtb_sart.anno = mtb_sart_dt.anno\n" +
|
||||
" where (@codMdep is null or mtb_depo.cod_mdep IN (SELECT value_string as cod_mdep FROM ParseStringIntoArray(@codMdep, ',')))\n" +
|
||||
" and mtb_grup.flag_val_mag = 'S'\n" +
|
||||
" and mtb_sart.anno IN (select anno_iniz from anno ) \n" +
|
||||
" UNION ALL\n" +
|
||||
" select mtb_movi.cod_mdep,\n" +
|
||||
" mtb_movi.cod_mart,\n" +
|
||||
" mtb_movi.partita_mag,\n" +
|
||||
" mtb_movi.cod_col,\n" +
|
||||
" mtb_movi.cod_tagl,\n" +
|
||||
" 0 as qta_iniz,\n" +
|
||||
" sum(mtb_movi.qta_car) as qta_car,\n" +
|
||||
" sum(mtb_movi.qta_scar) as qta_scar,\n" +
|
||||
" CONVERT(numeric(20, 5), 0) as num_iniz,\n" +
|
||||
" SUM(mtb_movi.num_car) as num_car,\n" +
|
||||
" SUM(mtb_movi.num_scar) as num_scar\n" +
|
||||
" from mtb_movi \n" +
|
||||
" INNER JOIN mtb_aart ON mtb_movi.cod_mart = mtb_aart.cod_mart\n" +
|
||||
" INNER JOIN mtb_grup ON mtb_aart.cod_mgrp = mtb_grup.cod_mgrp\n" +
|
||||
" INNER JOIN mtb_depo ON mtb_movi.cod_mdep = mtb_depo.cod_mdep\n" +
|
||||
" where (@codMdep is null or mtb_depo.cod_mdep IN (SELECT value_string as cod_mdep FROM ParseStringIntoArray(@codMdep, ',')))\n" +
|
||||
" and mtb_grup.flag_val_mag = 'S'\n" +
|
||||
" and mtb_movi.data_reg between (select data_iniz from periodo) and IsNull(@adt_adata, GetDate())\n" +
|
||||
" group by mtb_movi.cod_mdep, mtb_movi.cod_mart, mtb_movi.partita_mag, mtb_movi.cod_col,\n" +
|
||||
" mtb_movi.cod_tagl,\n" +
|
||||
" mtb_movi.data_reg )\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" SELECT cod_mdep,\n" +
|
||||
" cod_mart,\n" +
|
||||
" partita_mag,\n" +
|
||||
" cod_col,\n" +
|
||||
" cod_tagl,\n" +
|
||||
" SUM(qta_iniz) as qta_iniz,\n" +
|
||||
" SUM(qta_car) as qta_car,\n" +
|
||||
" SUM(qta_scar) as qta_scar,\n" +
|
||||
" SUM(qta_iniz) + SUM(qta_car) - SUM(qta_scar) as qta_fine,\n" +
|
||||
" SUM(num_iniz) as num_iniz,\n" +
|
||||
" SUM(num_car) as num_car,\n" +
|
||||
" SUM(num_scar) as num_scar,\n" +
|
||||
" SUM(num_iniz) + SUM(num_car) - SUM(num_scar) as num_fine\n" +
|
||||
" FROM movimenti sart_iniz_movi_fine\n" +
|
||||
" GROUP BY cod_mdep, cod_mart, partita_mag, cod_col, cod_tagl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250128172026 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
executeStatement("update atb_list_data set flag_riversa_promo = 1 where flag_riversa_promo is null");
|
||||
addDefault("atb_list_data", "flag_riversa_promo", 1 );
|
||||
executeStatement("alter table atb_list_data alter column flag_riversa_promo bit not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomer;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250129152213 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetupQuery("SI_NO", "SI_NO", "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
createSetup("PVM", "CONTO_ECONOMICO_PRODOTTO", "FILTRA_EQUIVALENTI", "N",
|
||||
"visualizza solo uno degli articoli equivalenti", false, "SI_NO", false, false,
|
||||
false, false, false, null, false, "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
|
||||
if (isCustomer(IntegryCustomer.RossoGargano))
|
||||
updateSetupValue("PVM", "CONTO_ECONOMICO_PRODOTTO", "FILTRA_EQUIVALENTI", "S");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.exception.UnexpectedConnectionSwitchException;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -169,11 +168,11 @@ public class BasicConnectionPool {
|
||||
}
|
||||
|
||||
if (!currentCatalog.equalsIgnoreCase(model.getDbName())) {
|
||||
handleCatalogMismatch(ds, model, currentCatalog);
|
||||
handleCatalogMismatch(ds, currentCatalog);
|
||||
return false;
|
||||
}
|
||||
|
||||
return handleConnectionRelease(ds, model);
|
||||
return handleConnectionRelease(ds);
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
}
|
||||
@@ -214,19 +213,19 @@ public class BasicConnectionPool {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private void handleCatalogMismatch(DataSource ds, AvailableConnectionsModel model, String currentCatalog)
|
||||
private void handleCatalogMismatch(DataSource ds, String currentCatalog)
|
||||
throws UnexpectedConnectionSwitchException, SQLException, IOException {
|
||||
String connectionName = ds.getApplicationName();
|
||||
usedConnections.get(model.getDbName()).remove(ds);
|
||||
activeConnectionNames.get(model.getDbName()).remove(connectionName);
|
||||
usedConnections.get(currentCatalog).remove(ds);
|
||||
activeConnectionNames.get(currentCatalog).remove(connectionName);
|
||||
ds.forceClose();
|
||||
throw new UnexpectedConnectionSwitchException(model.getDbName(), currentCatalog);
|
||||
throw new UnexpectedConnectionSwitchException(ds.getConnection().getCatalog(), currentCatalog);
|
||||
}
|
||||
|
||||
private boolean handleConnectionRelease(DataSource ds, AvailableConnectionsModel model)
|
||||
private boolean handleConnectionRelease(DataSource ds)
|
||||
throws SQLException {
|
||||
String connectionName = ds.getApplicationName();
|
||||
String dbName = model.getDbName();
|
||||
String dbName = ds.getDbName();
|
||||
|
||||
if (connectionName.startsWith("EMS Extra Connection #")) {
|
||||
activeConnectionNames.get(dbName).remove(connectionName);
|
||||
|
||||
@@ -89,7 +89,6 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
public void Destroy() throws Exception {
|
||||
this.commitAll();
|
||||
this.closeAll();
|
||||
this.dbDatasources.clear();
|
||||
this.dbPrimary = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,6 @@ public class UserSession {
|
||||
return currentUser != null && currentUser.isAttivo();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return currentUser.getType();
|
||||
}
|
||||
|
||||
public MtbDepo getDefaultDepo() {
|
||||
return currentUserDepo;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package it.integry.ems.user;
|
||||
|
||||
import it.integry.ems._context.ApplicationContextProvider;
|
||||
import it.integry.ems.dto.EntityPermissionsDTO;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.user.exception.InvalidUserException;
|
||||
import it.integry.ems.user.service.UserCacheService;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.MtbDepo;
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
import it.integry.ems_model.entity.WtbDepo;
|
||||
import it.integry.ems_model.exception.DataConverterNotFoundException;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
@@ -17,9 +20,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -52,21 +52,12 @@ public class UtilityUser {
|
||||
public static UserDTO getCurrentUser(MultiDBTransactionManager multiDBTransactionManager, String username) {
|
||||
if (UtilityString.isNullOrEmpty(username)) return null;
|
||||
|
||||
String sql =
|
||||
"SELECT User_name, " +
|
||||
" e_mail AS email, " +
|
||||
" Full_name, " +
|
||||
" key_group, " +
|
||||
" CAST(CASE WHEN flag_attivo = 'S' THEN 1 ELSE 0 END AS bit) AS attivo, " +
|
||||
" 'internal' AS type " +
|
||||
"FROM " + StbUser.ENTITY + " " +
|
||||
"WHERE user_name = " + UtilityDB.valueToString(username);
|
||||
final UserCacheService userCacheService = ApplicationContextProvider.getApplicationContext().getBean(UserCacheService.class);
|
||||
final RequestDataDTO requestData = ApplicationContextProvider.getApplicationContext().getBean(RequestDataDTO.class);
|
||||
|
||||
try {
|
||||
List<UserDTO> result = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, UserDTO.class);
|
||||
|
||||
if (result == null || result.isEmpty()) return null;
|
||||
|
||||
return result.get(0);
|
||||
final UserDTO userDTO = userCacheService.retrieveUserData(multiDBTransactionManager.getPrimaryDatasource().getProfile(), username, requestData.getApplication());
|
||||
return userDTO;
|
||||
} catch (Exception exception) {
|
||||
logger.error("User validation", exception);
|
||||
return null;
|
||||
|
||||
@@ -1,26 +1,51 @@
|
||||
package it.integry.ems.user.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class UserDTO {
|
||||
|
||||
@SqlField("user_name")
|
||||
private String username;
|
||||
|
||||
@SqlField("email")
|
||||
private String email;
|
||||
|
||||
@SqlField("full_name")
|
||||
private String fullname;
|
||||
@JsonIgnore
|
||||
@SqlField("password_hash")
|
||||
private String passwordHash;
|
||||
|
||||
@SqlField("key_group")
|
||||
private Integer keyGroup;
|
||||
|
||||
@SqlField("attivo")
|
||||
@SqlField("full_name")
|
||||
private String fullname;
|
||||
|
||||
@SqlField("e_mail")
|
||||
private String email;
|
||||
|
||||
@SqlField("last_access_datetime")
|
||||
private LocalDateTime lastAccessDateTime;
|
||||
|
||||
@SqlField("password_endtime")
|
||||
private LocalDateTime passwordEndTime;
|
||||
|
||||
@SqlField("is_password_expired")
|
||||
private boolean passwordExpired;
|
||||
|
||||
@SqlField("user_code")
|
||||
private String userCode;
|
||||
|
||||
@SqlField("cod_mdep")
|
||||
private String codMdep;
|
||||
|
||||
@SqlField("is_attivo")
|
||||
private boolean attivo;
|
||||
|
||||
@SqlField("type")
|
||||
private String type;
|
||||
@SqlField("is_internal")
|
||||
private boolean internal;
|
||||
|
||||
@SqlField("is_web")
|
||||
private boolean web;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
@@ -31,24 +56,6 @@ public class UserDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public UserDTO setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFullname() {
|
||||
return fullname;
|
||||
}
|
||||
|
||||
public UserDTO setFullname(String fullname) {
|
||||
this.fullname = fullname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getKeyGroup() {
|
||||
return keyGroup;
|
||||
}
|
||||
@@ -58,6 +65,69 @@ public class UserDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFullname() {
|
||||
return fullname;
|
||||
}
|
||||
|
||||
public UserDTO setFullname(String fullname) {
|
||||
this.fullname = fullname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public UserDTO setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalDateTime getLastAccessDateTime() {
|
||||
return lastAccessDateTime;
|
||||
}
|
||||
|
||||
public UserDTO setLastAccessDateTime(LocalDateTime lastAccessDateTime) {
|
||||
this.lastAccessDateTime = lastAccessDateTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalDateTime getPasswordEndTime() {
|
||||
return passwordEndTime;
|
||||
}
|
||||
|
||||
public UserDTO setPasswordEndTime(LocalDateTime passwordEndTime) {
|
||||
this.passwordEndTime = passwordEndTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isPasswordExpired() {
|
||||
return passwordExpired;
|
||||
}
|
||||
|
||||
public UserDTO setPasswordExpired(boolean passwordExpired) {
|
||||
this.passwordExpired = passwordExpired;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserCode() {
|
||||
return userCode;
|
||||
}
|
||||
|
||||
public UserDTO setUserCode(String userCode) {
|
||||
this.userCode = userCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodMdep() {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
public UserDTO setCodMdep(String codMdep) {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isAttivo() {
|
||||
return attivo;
|
||||
}
|
||||
@@ -67,12 +137,30 @@ public class UserDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
public boolean isInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public UserDTO setType(String type) {
|
||||
this.type = type;
|
||||
public UserDTO setInternal(boolean internal) {
|
||||
this.internal = internal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isWeb() {
|
||||
return web;
|
||||
}
|
||||
|
||||
public UserDTO setWeb(boolean web) {
|
||||
this.web = web;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public UserDTO setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package it.integry.ems.user.service;
|
||||
import it.integry.annotations.PostContextConstruct;
|
||||
import it.integry.ems.expansion.RunnableThrowable;
|
||||
import it.integry.ems.looper.service.LooperService;
|
||||
import it.integry.ems.model.IntegryApplicationEnum;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||
@@ -12,12 +13,14 @@ import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHash;
|
||||
import it.integry.ems_model.utility.UtilityThread;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -46,11 +49,10 @@ public class UserCacheService {
|
||||
}
|
||||
|
||||
private void internalCheck() {
|
||||
Map<String, List<AvailableConnectionsModel>> availableConnectionsModels = settingsModel.getAvailableConnections(true).stream()
|
||||
Map<String, List<AvailableConnectionsModel>> availableConnectionsModels = settingsModel.getAvailableConnections(true).stream()
|
||||
.collect(Collectors.groupingBy(AvailableConnectionsModel::getDbName));
|
||||
|
||||
|
||||
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager()) {
|
||||
for (Map.Entry<String, List<AvailableConnectionsModel>> profiles : availableConnectionsModels.entrySet()) {
|
||||
final AvailableConnectionsModel firstModel = profiles.getValue().get(0);
|
||||
@@ -99,6 +101,51 @@ public class UserCacheService {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public @Nullable UserDTO retrieveUser(String profileDb, String username, String password, IntegryApplicationEnum application) {
|
||||
String dbName = settingsModel.getDbNameFromProfileDb(profileDb);
|
||||
|
||||
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
|
||||
|
||||
if (users == null || users.isEmpty())
|
||||
return null;
|
||||
|
||||
if (password == null || password.isEmpty())
|
||||
return null;
|
||||
|
||||
String finalPasswordHex = UtilityHash.generateHash(password.toUpperCase());
|
||||
final Optional<UserDTO> foundUser = users.stream()
|
||||
.filter(x -> x.getUsername().equalsIgnoreCase(username) &&
|
||||
x.getPasswordHash().contentEquals(finalPasswordHex) &&
|
||||
(application == null ||
|
||||
(application == IntegryApplicationEnum.PVM && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.WMS && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal())))
|
||||
.findFirst();
|
||||
|
||||
return foundUser.orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable UserDTO retrieveUserData(String profileDb, String username, IntegryApplicationEnum application) {
|
||||
String dbName = settingsModel.getDbNameFromProfileDb(profileDb);
|
||||
|
||||
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
|
||||
|
||||
if (users == null || users.isEmpty())
|
||||
return null;
|
||||
|
||||
final Optional<UserDTO> foundUser = users.stream()
|
||||
.filter(x -> x.getUsername().equalsIgnoreCase(username) &&
|
||||
(application == null ||
|
||||
(application == IntegryApplicationEnum.PVM && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.WMS && x.isWeb()) ||
|
||||
(application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal())))
|
||||
.findFirst();
|
||||
|
||||
return foundUser.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public void discoverAllUsers(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||
cacheLock.lock();
|
||||
@@ -109,14 +156,25 @@ public class UserCacheService {
|
||||
try {
|
||||
Connection conn = advancedDataSource.getConnection();
|
||||
|
||||
String sql =
|
||||
"SELECT User_name, " +
|
||||
" e_mail as email, " +
|
||||
" Full_name, " +
|
||||
" CAST(CASE WHEN flag_attivo = 'S' THEN 1 ELSE 0 END AS bit) AS attivo, " +
|
||||
" 'internal' AS type " +
|
||||
"FROM " + StbUser.ENTITY + " " +
|
||||
"WHERE ( " + StbUser.ENTITY + ".flag_intra_user = 'S' OR " + StbUser.ENTITY + ".flag_extra_user = 'S') ";
|
||||
String sql = "SELECT su.user_name,\n" +
|
||||
" CONVERT(varchar(max), HASHBYTES('SHA2_512', UPPER(dbo.sys_dcd_pss(su.password))),2) AS password_hash,\n" +
|
||||
" su.key_group,\n" +
|
||||
" su.full_name,\n" +
|
||||
" su.e_mail,\n" +
|
||||
" su.last_access_datetime,\n" +
|
||||
" su.password_endtime,\n" +
|
||||
" CAST(IIF(su.destruction_datetime IS NOT NULL AND\n" +
|
||||
" DATEDIFF(DAY, su.destruction_datetime, GETDATE()) > 0 AND su.flag_password_expiring = 'S', 1,\n" +
|
||||
" 0) AS BIT) AS is_password_expired,\n" +
|
||||
" IIF(su.key_group = '3' AND su.user_code IS NULL, wc.cod_anag, su.user_code) AS user_code,\n" +
|
||||
" wd.cod_mdep,\n" +
|
||||
" CAST(IIF(ISNULL(su.flag_attivo, 'N') = 'S', 1, 0) AS BIT) AS is_attivo,\n" +
|
||||
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_dba = 'S', 1, 0) AS BIT) AS is_internal,\n" +
|
||||
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_extra_user = 'S', 1, 0) AS BIT) AS is_web\n" +
|
||||
"FROM " + StbUser.ENTITY + " su " +
|
||||
" LEFT OUTER JOIN wtb_clie wc ON su.user_name = wc.user_name\n" +
|
||||
" LEFT OUTER JOIN wtb_depo wd ON su.user_name = wd.user_name\n" +
|
||||
" LEFT OUTER JOIN mtb_depo md ON wd.cod_mdep = md.cod_mdep";
|
||||
|
||||
|
||||
final List<UserDTO> userDTOS = UtilityDB.executeSimpleQueryDTO(conn, sql, UserDTO.class);
|
||||
|
||||
@@ -117,31 +117,5 @@ public class UserService {
|
||||
}
|
||||
|
||||
return profiles;
|
||||
//
|
||||
// for (String profile : profiles) {
|
||||
// multiDBTransactionManager.closeAll();
|
||||
// multiDBTransactionManager.setPrimaryDs(profile);
|
||||
//
|
||||
// try {
|
||||
// StbUser tmpUserData = this.getUser(username, password, multiDBTransactionManager);
|
||||
//
|
||||
// if (tmpUserData != null) {
|
||||
// UserDTO userDTO = new UserDTO()
|
||||
// .setUsername(tmpUserData.getUsername())
|
||||
// .setEmail(tmpUserData.geteMail())
|
||||
// .setFullname(tmpUserData.getFullName())
|
||||
// .setType("web")
|
||||
// .setAttivo("S".equalsIgnoreCase(tmpUserData.getFlagAttivo()));
|
||||
//
|
||||
// userCacheService.cache(profile, userDTO);
|
||||
//
|
||||
// userData.setUser(tmpUserData);
|
||||
//
|
||||
// profilesWhereUserFound.add(profile);
|
||||
// }
|
||||
// } finally {
|
||||
// multiDBTransactionManager.closeAll();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class AtbListData extends EntityBase {
|
||||
@SqlField(value = "costo_trasp")
|
||||
private BigDecimal costoTrasp;
|
||||
|
||||
@SqlField(value = "flag_riversa_promo")
|
||||
@SqlField(value = "flag_riversa_promo", defaultObjectValue = "1")
|
||||
private Boolean flagRiversaPromo;
|
||||
|
||||
// //////////
|
||||
|
||||
@@ -39,6 +39,9 @@ public class NtbTipiInca extends EntityBase {
|
||||
@SqlField(value = "cod_ccon_storno_corr", maxLength = 6)
|
||||
private String codCconStornoCorr;
|
||||
|
||||
@SqlField(value = "cod_aliq", maxLength = 6)
|
||||
private String codAliq;
|
||||
|
||||
@SqlField(value = "flag_tipo_inca", maxLength = 1)
|
||||
private String flagTipoInca;
|
||||
|
||||
@@ -55,56 +58,72 @@ public class NtbTipiInca extends EntityBase {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
public void setCodMdep(String codMdep) {
|
||||
public NtbTipiInca setCodMdep(String codMdep) {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTipoInca() {
|
||||
return tipoInca;
|
||||
}
|
||||
|
||||
public void setTipoInca(String tipoInca) {
|
||||
public NtbTipiInca setTipoInca(String tipoInca) {
|
||||
this.tipoInca = tipoInca;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodCcon() {
|
||||
return codCcon;
|
||||
}
|
||||
|
||||
public void setCodCcon(String codCcon) {
|
||||
public NtbTipiInca setCodCcon(String codCcon) {
|
||||
this.codCcon = codCcon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return descrizione;
|
||||
}
|
||||
|
||||
public void setDescrizione(String descrizione) {
|
||||
public NtbTipiInca setDescrizione(String descrizione) {
|
||||
this.descrizione = descrizione;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagBuoni() {
|
||||
return flagBuoni;
|
||||
}
|
||||
|
||||
public void setFlagBuoni(String flagBuoni) {
|
||||
public NtbTipiInca setFlagBuoni(String flagBuoni) {
|
||||
this.flagBuoni = flagBuoni;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodCconStornoCorr() {
|
||||
return codCconStornoCorr;
|
||||
}
|
||||
|
||||
public void setCodCconStornoCorr(String codCconStornoCorr) {
|
||||
public NtbTipiInca setCodCconStornoCorr(String codCconStornoCorr) {
|
||||
this.codCconStornoCorr = codCconStornoCorr;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodAliq() {
|
||||
return codAliq;
|
||||
}
|
||||
|
||||
public NtbTipiInca setCodAliq(String codAliq) {
|
||||
this.codAliq = codAliq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagTipoInca() {
|
||||
return flagTipoInca;
|
||||
}
|
||||
|
||||
public void setFlagTipoInca(String flagTipoInca) {
|
||||
public NtbTipiInca setFlagTipoInca(String flagTipoInca) {
|
||||
this.flagTipoInca = flagTipoInca;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodPaga() {
|
||||
|
||||
@@ -7,12 +7,14 @@ import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@@ -88,7 +90,7 @@ public class StbUser extends EntityBase {
|
||||
private String details;
|
||||
|
||||
@SqlField(value = "Last_access_datetime")
|
||||
private Date lastAccessDatetime;
|
||||
private LocalDateTime lastAccessDatetime;
|
||||
|
||||
@SqlField(value = "last_passwords", maxLength = 255)
|
||||
private String lastPasswords;
|
||||
@@ -399,11 +401,11 @@ public class StbUser extends EntityBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getLastAccessDatetime() {
|
||||
public LocalDateTime getLastAccessDatetime() {
|
||||
return lastAccessDatetime;
|
||||
}
|
||||
|
||||
public StbUser setLastAccessDatetime(Date lastAccessDatetime) {
|
||||
public StbUser setLastAccessDatetime(LocalDateTime lastAccessDatetime) {
|
||||
this.lastAccessDatetime = lastAccessDatetime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,14 @@ import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@@ -50,7 +52,7 @@ public class WtbUsers extends EntityBase {
|
||||
private Integer keyGroup;
|
||||
|
||||
@SqlField(value = "Last_access_datetime")
|
||||
private Date lastAccessDatetime;
|
||||
private LocalDateTime lastAccessDatetime;
|
||||
|
||||
@SqlField(value = "last_passwords", maxLength = 255)
|
||||
private String lastPasswords;
|
||||
@@ -184,11 +186,11 @@ public class WtbUsers extends EntityBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getLastAccessDatetime() {
|
||||
public LocalDateTime getLastAccessDatetime() {
|
||||
return lastAccessDatetime;
|
||||
}
|
||||
|
||||
public WtbUsers setLastAccessDatetime(Date lastAccessDatetime) {
|
||||
public WtbUsers setLastAccessDatetime(LocalDateTime lastAccessDatetime) {
|
||||
this.lastAccessDatetime = lastAccessDatetime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package it.integry.ems_model.utility;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class UtilityHash {
|
||||
private static final char[] HEX_ARRAY = "0123456789abcdefABCDEF".toCharArray();
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars);
|
||||
}
|
||||
|
||||
|
||||
public static String generateHash(String password) {
|
||||
try {
|
||||
// Creo l'oggetto MessageDigest con algoritmo SHA-512
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||
byte[] hash = digest.digest(password.getBytes(StandardCharsets.US_ASCII));
|
||||
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString().toUpperCase();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Errore nel calcolo dell'hash", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import it.integry.ems.exception.AuthorizationExpriredException;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems_model.entity.StbAuthToken;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import it.integry.security.cache.JwtTokenCacheComponent;
|
||||
import it.integry.security.dto.LoginRequestDTO;
|
||||
import it.integry.security.dto.LogoutRequestDTO;
|
||||
@@ -35,20 +34,19 @@ public class AuthController {
|
||||
|
||||
@Autowired
|
||||
private AuthService authService;
|
||||
|
||||
@Autowired
|
||||
private JwtTokenCacheComponent jwtTokenCacheComponent;
|
||||
|
||||
@Autowired
|
||||
private RefreshTokenService refreshTokenService;
|
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
public ServiceRestResponse login(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam(value = CommonConstants.PROFILE_DB, required = false) String profileDb,
|
||||
@RequestParam(value = CommonConstants.PROFILE_DB) String profileDb,
|
||||
@RequestBody LoginRequestDTO loginRequestDTO) {
|
||||
try {
|
||||
if(UtilityString.isNullOrEmpty(loginRequestDTO.getProfileDb()))
|
||||
loginRequestDTO.setProfileDb(profileDb);
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(authService.login(loginRequestDTO));
|
||||
return ServiceRestResponse.createPositiveResponse(authService.login(profileDb, loginRequestDTO));
|
||||
} catch (AuthorizationExpriredException ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
response.setStatus(420);
|
||||
@@ -63,7 +61,7 @@ public class AuthController {
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public ServiceRestResponse user(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String profileDb) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(authService.getUser(profileDb));
|
||||
return ServiceRestResponse.createPositiveResponse(authService.getUserDetails());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/refresh", method = RequestMethod.POST)
|
||||
|
||||
@@ -4,7 +4,6 @@ public class LoginRequestDTO {
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
private String profileDb;
|
||||
private String deviceId;
|
||||
|
||||
private String md5User;
|
||||
@@ -27,15 +26,6 @@ public class LoginRequestDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getProfileDb() {
|
||||
return profileDb;
|
||||
}
|
||||
|
||||
public LoginRequestDTO setProfileDb(String profileDb) {
|
||||
this.profileDb = profileDb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package it.integry.security.dto;
|
||||
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserDataDTO {
|
||||
private StbUser user;
|
||||
private List<String> availableProfiles;
|
||||
|
||||
public StbUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public UserDataDTO setUser(StbUser user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getAvailableProfiles() {
|
||||
return availableProfiles;
|
||||
}
|
||||
|
||||
public UserDataDTO setAvailableProfiles(List<String> availableProfiles) {
|
||||
this.availableProfiles = availableProfiles;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,66 @@
|
||||
package it.integry.security.service;
|
||||
|
||||
import it.integry.ems.exception.AuthorizationExpriredException;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.user.service.UserCacheService;
|
||||
import it.integry.ems.user.service.UserService;
|
||||
import it.integry.ems_model.entity.StbAuthToken;
|
||||
import it.integry.ems_model.entity.StbDevices;
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
import it.integry.ems_model.exception.DataConverterNotFoundException;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import it.integry.security.dto.AuthTokenDetails;
|
||||
import it.integry.security.dto.LoginRequestDTO;
|
||||
import it.integry.security.dto.LogoutRequestDTO;
|
||||
import it.integry.security.dto.UserDataDTO;
|
||||
import it.integry.security.event.TokenCreateEvent;
|
||||
import it.integry.security.event.TokenExpireEvent;
|
||||
import it.integry.security.jwt.AccessTokenProvider;
|
||||
import it.integry.security.response.JwtResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.ws.rs.NotAuthorizedException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class AuthService {
|
||||
@Autowired
|
||||
private UserCacheService userCacheService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SettingsModel settingsModel;
|
||||
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
@Autowired
|
||||
private AccessTokenProvider accessTokenProvider;
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private RefreshTokenService refreshTokenService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestDataDTO;
|
||||
|
||||
public JwtResponse login(LoginRequestDTO loginRequestDTO) throws Exception {
|
||||
public JwtResponse login(String profileDb, LoginRequestDTO loginRequestDTO) throws Exception {
|
||||
if (UtilityString.isNullOrEmpty(loginRequestDTO.getUsername())) {
|
||||
throw new Exception("Username mancante.");
|
||||
}
|
||||
@@ -71,140 +76,58 @@ public class AuthService {
|
||||
String username = loginRequestDTO.getUsername();
|
||||
String password = loginRequestDTO.getPassword();
|
||||
String deviceId = loginRequestDTO.getDeviceId();
|
||||
String profileDb = loginRequestDTO.getProfileDb();
|
||||
|
||||
UserDataDTO userData = new UserDataDTO();
|
||||
final UserDTO foundUser = userCacheService.retrieveUser(profileDb, username, password, requestDataDTO.getApplication());
|
||||
|
||||
if (UtilityString.isNullOrEmpty(profileDb)) {
|
||||
List<String> profiles = userService.retrieveAvailableProfiles(username);
|
||||
userData.setAvailableProfiles(profiles);
|
||||
|
||||
|
||||
if (profiles != null && profiles.size() == 1) {
|
||||
profileDb = userData.getAvailableProfiles().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(profileDb)) { // SELEZIONE DB DIRETTO
|
||||
multiDBTransactionManager.closeAll();
|
||||
multiDBTransactionManager.setPrimaryDs(profileDb);
|
||||
|
||||
userData.setUser(this.getUser(username, password, multiDBTransactionManager));
|
||||
}
|
||||
|
||||
if (userData.getUser() == null) {
|
||||
if (foundUser == null) {
|
||||
throw new Exception("Credenziali non valide");
|
||||
} else if (userData.getUser().getFlagAttivo().equalsIgnoreCase("N")) {
|
||||
} else if (!foundUser.isAttivo()) {
|
||||
throw new Exception("Utente non attivo");
|
||||
} else if (userData.getUser().getPasswordEndtime() != null &&
|
||||
userData.getUser().getPasswordEndtime().before(new Date())) {
|
||||
} else if (foundUser.isPasswordExpired()) {
|
||||
throw new AuthorizationExpriredException("Password scaduta", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (multiDBTransactionManager != null) {
|
||||
StbUser stbUser = new StbUser()
|
||||
.setUserName(userData.getUser().getUserName())
|
||||
.setLastAccessDatetime(new Date());
|
||||
StbUser stbUser = new StbUser()
|
||||
.setUserName(foundUser.getUsername())
|
||||
.setLastAccessDatetime(UtilityLocalDate.getNowTime());
|
||||
|
||||
stbUser.setOperation(OperationType.UPDATE);
|
||||
stbUser.setOperation(OperationType.UPDATE);
|
||||
|
||||
entityProcessor.processEntity(stbUser, multiDBTransactionManager);
|
||||
entityProcessor.processEntity(stbUser, multiDBTransactionManager);
|
||||
|
||||
StbDevices stbDevices = deviceService.createIfNotExist(requestDataDTO.getApplication().toString(), deviceId);
|
||||
StbDevices stbDevices = deviceService.createIfNotExist(requestDataDTO.getApplication().toString(), deviceId);
|
||||
|
||||
// Ottengo access_token se token già creato per device id
|
||||
String sql = String.format(
|
||||
"SELECT access_token FROM %s WHERE user_name = %s AND device_id = %d",
|
||||
StbAuthToken.ENTITY,
|
||||
UtilityDB.valueToString(userData.getUser().getUserName()),
|
||||
stbDevices.getId()
|
||||
);
|
||||
|
||||
String oldAccessToken = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
String primaryProfileDb = multiDBTransactionManager.getPrimaryDatasource().getProfile();
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(oldAccessToken)) {
|
||||
applicationEventPublisher.publishEvent(new TokenExpireEvent(primaryProfileDb, oldAccessToken));
|
||||
}
|
||||
|
||||
// Ricreo token di accesso e refresh
|
||||
StbAuthToken stbAuthToken = refreshTokenService.createRefreshTokenIfNotExists(
|
||||
username,
|
||||
password,
|
||||
userData.getUser().getKeyGroup(),
|
||||
primaryProfileDb,
|
||||
stbDevices.getId()
|
||||
);
|
||||
|
||||
applicationEventPublisher.publishEvent(new TokenCreateEvent(primaryProfileDb, stbAuthToken));
|
||||
|
||||
return new JwtResponse()
|
||||
.setAccessToken(stbAuthToken.getAccessToken())
|
||||
.setRefreshToken(stbAuthToken.getRefreshToken())
|
||||
.setExpiryDate(stbAuthToken.getExpiryDate())
|
||||
.setExpireIn(ChronoUnit.SECONDS.between(UtilityLocalDate.getNowTime(), stbAuthToken.getExpiryDate()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StbUser getUser(String profileDb) throws Exception {
|
||||
return this.getUser(requestDataDTO.getUsername(), null, profileDb);
|
||||
}
|
||||
|
||||
public StbUser getUser(String username, String profileDb) throws Exception {
|
||||
return this.getUser(username, null, profileDb);
|
||||
}
|
||||
|
||||
public StbUser getUser(String username, String password, String profileDb) throws Exception {
|
||||
return this.getUser(username, password, new MultiDBTransactionManager(profileDb));
|
||||
}
|
||||
|
||||
public StbUser getUser(String username, String password, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||
if (UtilityString.isNullOrEmpty(username)) {
|
||||
throw new Exception("Username mancante in getUserData.");
|
||||
}
|
||||
|
||||
String sql = String.format("SELECT su.user_name,\n" +
|
||||
" su.key_group,\n" +
|
||||
" su.full_name,\n" +
|
||||
" su.password_endtime,\n" +
|
||||
" su.e_mail,\n" +
|
||||
" su.Last_access_datetime,\n" +
|
||||
" su.flag_password_expiring,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN su.key_group = '3' AND su.user_code IS NULL THEN wc.cod_anag\n" +
|
||||
" ELSE su.user_code END AS user_code,\n" +
|
||||
" wd.cod_mdep,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN su.destruction_datetime IS NOT NULL AND\n" +
|
||||
" DATEDIFF(DAY, su.destruction_datetime, GETDATE()) > 0 AND su.flag_password_expiring = 'S'\n" +
|
||||
" THEN 'N'\n" +
|
||||
" ELSE ISNULL(su.flag_attivo, 'N')\n" +
|
||||
" END AS flag_attivo\n" +
|
||||
"FROM stb_user su\n" +
|
||||
" LEFT OUTER JOIN wtb_clie wc ON su.user_name = wc.user_name\n" +
|
||||
" LEFT OUTER JOIN wtb_depo wd ON su.user_name = wd.user_name\n" +
|
||||
" LEFT OUTER JOIN mtb_depo md ON wd.cod_mdep = md.cod_mdep\n" +
|
||||
"WHERE su.user_name = '%s'\n",
|
||||
username
|
||||
// Ottengo access_token se token già creato per device id
|
||||
String sql = Query.format(
|
||||
"SELECT access_token FROM " + StbAuthToken.ENTITY + " WHERE user_name = {} AND device_id = {}",
|
||||
foundUser.getUsername(),
|
||||
stbDevices.getId()
|
||||
);
|
||||
|
||||
switch (requestDataDTO.getApplication()) {
|
||||
case GESTIONALE_BASE:
|
||||
sql += " AND ( su.flag_intra_user = 'S' OR su.flag_dba = 's') ";
|
||||
break;
|
||||
case PVM:
|
||||
sql += " AND ( su.flag_intra_user = 'S' OR su.flag_extra_user = 's') ";
|
||||
break;
|
||||
String oldAccessToken = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
String primaryProfileDb = multiDBTransactionManager.getPrimaryDatasource().getProfile();
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(oldAccessToken)) {
|
||||
applicationEventPublisher.publishEvent(new TokenExpireEvent(primaryProfileDb, oldAccessToken));
|
||||
}
|
||||
|
||||
if (password != null) {
|
||||
sql += String.format("AND su.password = dbo.sys_enc_pss('%s')\n", password.toLowerCase());
|
||||
}
|
||||
// Ricreo token di accesso e refresh
|
||||
StbAuthToken stbAuthToken = refreshTokenService.createRefreshTokenIfNotExists(
|
||||
username,
|
||||
password,
|
||||
foundUser.getKeyGroup(),
|
||||
primaryProfileDb,
|
||||
stbDevices.getId()
|
||||
);
|
||||
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, StbUser.class);
|
||||
applicationEventPublisher.publishEvent(new TokenCreateEvent(primaryProfileDb, stbAuthToken));
|
||||
|
||||
return new JwtResponse()
|
||||
.setAccessToken(stbAuthToken.getAccessToken())
|
||||
.setRefreshToken(stbAuthToken.getRefreshToken())
|
||||
.setExpiryDate(stbAuthToken.getExpiryDate())
|
||||
.setExpireIn(ChronoUnit.SECONDS.between(UtilityLocalDate.getNowTime(), stbAuthToken.getExpiryDate()));
|
||||
}
|
||||
|
||||
public void logout(String profileDb, LogoutRequestDTO logoutRequestDTO) throws Exception {
|
||||
@@ -212,4 +135,19 @@ public class AuthService {
|
||||
TokenExpireEvent tokenExpireEvent = new TokenExpireEvent(profileDb, logoutRequestDTO.getToken());
|
||||
applicationEventPublisher.publishEvent(tokenExpireEvent);
|
||||
}
|
||||
|
||||
|
||||
public StbUser getUserDetails() throws SQLException, IOException, PrimaryDatabaseNotPresentException, DataConverterNotFoundException, InstantiationException, IllegalAccessException {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null || authentication instanceof AnonymousAuthenticationToken) {
|
||||
throw new NotAuthorizedException("Devi effettuare la login prima di procedere");
|
||||
}
|
||||
final AuthTokenDetails authTokenDetails = (AuthTokenDetails) authentication.getDetails();
|
||||
|
||||
UserDTO userData = authTokenDetails.getUserDTO();
|
||||
|
||||
String sql = Query.format("SELECT * FROM " + StbUser.ENTITY + " WHERE user_name = {}", userData.getUsername());
|
||||
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, StbUser.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,7 +541,6 @@ public class TrasformaPrevServices {
|
||||
pStmt.close();
|
||||
|
||||
multiDBTransactionManager.commitAll();
|
||||
multiDBTransactionManager.closeAll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EntityNotFound;
|
||||
import it.integry.ems_model.db.ResultSetMapper;
|
||||
import it.integry.ems_model.entity.*;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
@@ -107,25 +106,15 @@ public class DistribuzioneColliService {
|
||||
String sqlSelectMtbColrs = "SELECT mtb_colr.*, mtb_aart.flag_qta_cnf_fissa as flagQtaCnfFissa " +
|
||||
"FROM mtb_colr, mtb_aart WHERE mtb_colr.cod_mart = mtb_aart.cod_mart AND " + UtilityQuery.concatFieldListInWhereCond(mtbColtData);
|
||||
|
||||
PreparedStatement psMtbColr = multiDBTransactionManager.prepareStatement(sqlSelectMtbColrs);
|
||||
psMtbColr.setQueryTimeout(30);
|
||||
ResultSet rsMtbColr = psMtbColr.executeQuery();
|
||||
|
||||
ResultSetMapper rsMapperMtbColr = new ResultSetMapper();
|
||||
List<MtbColr> sourceMtbColrs = rsMapperMtbColr.mapResultSetToList(rsMtbColr, MtbColr.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
rsMtbColr.close();
|
||||
psMtbColr.close();
|
||||
|
||||
List<MtbColr> sourceMtbColrs = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sqlSelectMtbColrs, MtbColr.class);
|
||||
if (sourceMtbColrs == null) return null;
|
||||
|
||||
|
||||
//Carico tutte le informazioni riguardanti gli articoli
|
||||
List<String> codMarts = Stream.of(sourceMtbColrs)
|
||||
.withoutNulls()
|
||||
List<String> codMarts = sourceMtbColrs.stream()
|
||||
.filter(mtbColr -> mtbColr != null && !UtilityString.isNullOrEmpty(mtbColr.getCodMart()))
|
||||
.map(MtbColr::getCodMart)
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MtbAart> mtbAarts = productServices.getArticoliByCodMarts(codMarts);
|
||||
|
||||
@@ -800,7 +789,7 @@ public class DistribuzioneColliService {
|
||||
private List<MtbColt> splitMtbColrsByCodJfas(MtbColt inputMtbColt, List<DtbOrdt> inputOrders, List<MtbColr> inputMtbColrs) {
|
||||
final Map<Object, List<HashMap<String, Object>>> ordersByCodJfas = inputOrders.stream()
|
||||
.map(x -> new HashMap<String, Object>() {{
|
||||
put("data_ord", x.getDataOrd());
|
||||
put("data_ord", UtilityLocalDate.localDateFromDate(x.getDataOrd()));
|
||||
put("num_ord", x.getNumOrd());
|
||||
put("gestione", x.getGestione());
|
||||
put("cod_jfas", x.getCodJfas());
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.List;
|
||||
public class InventarioService {
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
@@ -458,8 +459,6 @@ public class InventarioService {
|
||||
// CANCELLAZIONE TABELLE TEMPORANEE
|
||||
UtilityDB.dropTmpTable(conn, tmpTable);
|
||||
|
||||
multiDBTransactionManager.closeAll();
|
||||
|
||||
return mtbInvent;
|
||||
}
|
||||
|
||||
|
||||
@@ -592,8 +592,8 @@ public class SmartLogisticService {
|
||||
String dataOrd = "";
|
||||
Integer numOrd = 0;
|
||||
String dataVers = "";
|
||||
if (!UtilityString.isNullOrEmpty(collo.getDataOrd()))
|
||||
dataOrd = CommonConstants.DATETIME_YMD_DASHED_FORMATTER.format(collo.getDataOrd());
|
||||
if (collo.getDataOrd() != null)
|
||||
dataOrd = CommonConstants.DATE_YMD_DASHED_FORMATTER.format(collo.getDataOrd());
|
||||
if (!UtilityString.isNullOrEmpty(collo.getNumOrd()))
|
||||
numOrd = collo.getNumOrd();
|
||||
if (!UtilityString.isNullOrEmpty(collo.getDataVers()))
|
||||
|
||||
@@ -1314,7 +1314,10 @@ public class MesProductionServiceV2 {
|
||||
// continue;
|
||||
}
|
||||
|
||||
if (rowArt.getCodMgrp().equalsIgnoreCase(codMgrpSL) && matchLottoSlToOrdine && !UtilityString.isNullOrEmpty(ordineLav.getPartitaMag()) && !ordineLav.getPartitaMag().equalsIgnoreCase(row.getPartitaMag())) {
|
||||
if (rowArt.getCodMgrp().equalsIgnoreCase(codMgrpSL) &&
|
||||
matchLottoSlToOrdine &&
|
||||
!UtilityString.isNullOrEmpty(ordineLav.getPartitaMag()) &&
|
||||
!ordineLav.getPartitaMag().startsWith(row.getPartitaMag())) {
|
||||
anomalie.add(AnomalieDTO.warning(String.format("La partita di semilavorato che si vuole versare (%s) non corrisponde a quella dell'ordine (%s), per concludere la procedura di versamento verrà creato un nuovo ordine di lavorazione con la partita selezionata!", row.getPartitaMag(), ordineLav.getPartitaMag())));
|
||||
response.setNewOrderRequired(true);
|
||||
continue;
|
||||
@@ -1460,13 +1463,21 @@ public class MesProductionServiceV2 {
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(partitaSL, multiDBTransactionManager);
|
||||
|
||||
|
||||
String partitaMagPf = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(),Query.format("with datiPartita as (\n" +
|
||||
" select MAX(ASCII(right(partita_mag,LEN(partita_mag) - LEN({})))) + 1 as nextProgressivo\n" +
|
||||
" from mtb_partita_mag where cod_mart = {} and partita_mag like {}\n" +
|
||||
")\n" +
|
||||
"select concat({},ISNULL(CHAR(nextProgressivo),'A'))\n" +
|
||||
"from datiPartita", partitaSL.getPartitaMag(), ordine.getCodProd(),partitaSL.getPartitaMag()+"%",partitaSL.getPartitaMag()));
|
||||
partitaMagPf = UtilityString.isNull(partitaMagPf,partitaSL.getPartitaMag());
|
||||
MtbPartitaMag partitaPf = new MtbPartitaMag();
|
||||
partitaPf.setCodMart(ordine.getCodProd())
|
||||
.setPartitaMag(partitaSL.getPartitaMag())
|
||||
.setPartitaMag(partitaMagPf)
|
||||
.setDataScad(partitaSL.getDataScad())
|
||||
.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
entityProcessor.processEntity(partitaPf, true, multiDBTransactionManager);
|
||||
ordine.setPartitaMag(partitaSL.getPartitaMag())
|
||||
ordine.setPartitaMag(partitaMagPf)
|
||||
.setOperation(OperationType.UPDATE);
|
||||
|
||||
entityProcessor.processEntity(ordine, true, multiDBTransactionManager);
|
||||
|
||||
@@ -112,7 +112,6 @@ public class WMSAccettazioneBollaService {
|
||||
" (SELECT CAST(count(*) as bit) FROM mtb_comp WHERE wdtb_docr.cod_mart = mtb_comp.cod_comp)as componente\n" +
|
||||
" FROM Wdtb_docr left outer join mtb_aart on Wdtb_docr.cod_mart = mtb_aart.cod_mart \n" +
|
||||
" left outer join mtb_grup on mtb_aart.cod_mgrp = mtb_grup.cod_mgrp \n" +
|
||||
" left outer join mtb_grup on mtb_aart.cod_mgrp = mtb_grup.cod_mgrp \n" +
|
||||
" WHERE wdtb_docr.cod_art_for is not null AND \n" +
|
||||
" wdtb_docr.cod_mart is not null AND \n" +
|
||||
" ( mtb_grup.tipo_mgrp is null or mtb_grup.tipo_mgrp <> 'FTT') \n" +
|
||||
|
||||
@@ -532,7 +532,6 @@ public class SystemController {
|
||||
username = UtilityString.isNull(loginRequestDTO.getUsername(), username);
|
||||
password = UtilityString.isNull(loginRequestDTO.getPassword(), password);
|
||||
md5User = UtilityString.isNull(loginRequestDTO.getMd5User(), md5User);
|
||||
profileDb = UtilityString.isNull(loginRequestDTO.getProfileDb(), profileDb);
|
||||
}
|
||||
return ServiceRestResponse.createPositiveResponse(systemService.login(username, password, md5User, profileDb));
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -341,7 +341,7 @@ public class SystemService {
|
||||
.setUsername(UtilityHashMap.getValueIfExists(tmpUserData, "user_name"))
|
||||
.setEmail(UtilityHashMap.getValueIfExists(tmpUserData, "e_mail"))
|
||||
.setFullname(UtilityHashMap.getValueIfExists(tmpUserData, "full_name"))
|
||||
.setType("web")
|
||||
.setWeb(true)
|
||||
.setAttivo("S".equalsIgnoreCase(UtilityHashMap.getValueIfExists(tmpUserData, "flag_attivo")));
|
||||
|
||||
userCacheService.cache(settingsModel.getDbNameFromProfileDb(profile), userDTO);
|
||||
@@ -368,7 +368,7 @@ public class SystemService {
|
||||
StbUser stbUser = new StbUser();
|
||||
stbUser.setOperation(OperationType.UPDATE);
|
||||
stbUser.setUserName((String) userData.get("user_name"));
|
||||
stbUser.setLastAccessDatetime(new Date());
|
||||
stbUser.setLastAccessDatetime(UtilityLocalDate.getNowTime());
|
||||
multiDBTransactionManager.setPrimaryDs((String) userData.get("profile_db"));
|
||||
requestDataDTO.setUsername((String) userData.get("user_name"));
|
||||
entityProcessor.processEntity(stbUser, true, multiDBTransactionManager);
|
||||
|
||||
Reference in New Issue
Block a user