Skip to content

Commit

Permalink
feat: Add subject and issuer config
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Dec 10, 2023
1 parent e0563b2 commit 306b740
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static final class Config {
// VALUES
public static final String PROPS_NAME_AUDIT_ENABLED = "audit-enabled";
public static final String PROPS_NAME_CONTROL_LOG_ENABLED = "control-log-persistence-enabled";
public static final String PROPS_NAME_ISSUER_CF = "issuer-cf-cleaning";
public static final String PROPS_NAME_SUBJECT = "subject-persistence";


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ public void trace(String logType,String workflowInstanceId, String message, ILog
jwtPayloadDTO = new JWTPayloadDTO();
}
LogDTO logDTO = LogDTO.builder().
op_issuer(jwtPayloadDTO.getIss()).
op_locality(jwtPayloadDTO.getLocality()).
message(message).
operation(operation.getCode()).
op_result(result.getCode()).
op_timestamp_start(dateFormat.format(startDateOperation)).
op_timestamp_end(dateFormat.format(new Date())).
op_role(jwtPayloadDTO.getSubject_role()).
op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())).
gateway_name(getGatewayName()).
microservice_name(msName).
op_application_id(jwtPayloadDTO.getSubject_application_id()).
Expand All @@ -84,6 +82,14 @@ public void trace(String logType,String workflowInstanceId, String message, ILog
workflow_instance_id(workflowInstanceId).
build();

if(configSRV.isSubjectPersistenceEnabled()) {
logDTO.setOp_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub()));
}

if(configSRV.isCfOnIssuerNotAllowed()) {
logDTO.setOp_issuer(jwtPayloadDTO.getIss());
}

final String logMessage = StringUtility.toJSON(logDTO);
log.trace(logMessage);

Expand All @@ -102,15 +108,13 @@ public void debug(String logType,String workflowInstanceId, String message, ILo
jwtPayloadDTO = new JWTPayloadDTO();
}
LogDTO logDTO = LogDTO.builder().
op_issuer(jwtPayloadDTO.getIss()).
op_locality(jwtPayloadDTO.getLocality()).
message(message).
operation(operation.getCode()).
op_result(result.getCode()).
op_timestamp_start(dateFormat.format(startDateOperation)).
op_timestamp_end(dateFormat.format(new Date())).
op_role(jwtPayloadDTO.getSubject_role()).
op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())).
gateway_name(getGatewayName()).
microservice_name(msName).
op_application_id(jwtPayloadDTO.getSubject_application_id()).
Expand All @@ -120,6 +124,14 @@ public void debug(String logType,String workflowInstanceId, String message, ILo
workflow_instance_id(workflowInstanceId).
build();

if(configSRV.isSubjectPersistenceEnabled()) {
logDTO.setOp_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub()));
}

if(configSRV.isCfOnIssuerNotAllowed()) {
logDTO.setOp_issuer(jwtPayloadDTO.getIss());
}

final String logMessage = StringUtility.toJSON(logDTO);
log.debug(logMessage);
if (Boolean.TRUE.equals(kafkaLogEnable)) {
Expand All @@ -137,7 +149,6 @@ public void info(String logType,String workflowInstanceId, String message, ILogE
jwtPayloadDTO = new JWTPayloadDTO();
}
LogDTO logDTO = LogDTO.builder().
op_issuer(jwtPayloadDTO.getIss()).
op_locality(jwtPayloadDTO.getLocality()).
message(message).
operation(operation.getCode()).
Expand All @@ -146,7 +157,6 @@ public void info(String logType,String workflowInstanceId, String message, ILogE
op_timestamp_end(dateFormat.format(new Date())).
op_document_type(documentType).
op_role(jwtPayloadDTO.getSubject_role()).
op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())).
gateway_name(getGatewayName()).
microservice_name(msName).
op_application_id(jwtPayloadDTO.getSubject_application_id()).
Expand All @@ -157,6 +167,14 @@ public void info(String logType,String workflowInstanceId, String message, ILogE
typeIdExtension(typeIdExtension).
build();

if(configSRV.isSubjectPersistenceEnabled()) {
logDTO.setOp_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub()));
}

if(configSRV.isCfOnIssuerNotAllowed()) {
logDTO.setOp_issuer(jwtPayloadDTO.getIss());
}

final String logMessage = StringUtility.toJSON(logDTO);
log.info(logMessage);

Expand All @@ -173,15 +191,13 @@ public void warn(String logType,String workflowInstanceId, String message, ILogE
jwtPayloadToken = new JWTPayloadDTO();
}
LogDTO logDTO = LogDTO.builder().
op_issuer(jwtPayloadToken.getIss()).
op_locality(jwtPayloadToken.getLocality()).
message(message).
operation(operation.getCode()).
op_result(result.getCode()).
op_timestamp_start(dateFormat.format(startDateOperation)).
op_timestamp_end(dateFormat.format(new Date())).
op_role(jwtPayloadToken.getSubject_role()).
op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())).
gateway_name(getGatewayName()).
microservice_name(msName).
op_application_id(jwtPayloadToken.getSubject_application_id()).
Expand All @@ -191,6 +207,13 @@ public void warn(String logType,String workflowInstanceId, String message, ILogE
workflow_instance_id(workflowInstanceId).
build();

if(configSRV.isSubjectPersistenceEnabled()) {
logDTO.setOp_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub()));
}

if(configSRV.isCfOnIssuerNotAllowed()) {
logDTO.setOp_issuer(jwtPayloadToken.getIss());
}
final String logMessage = StringUtility.toJSON(logDTO);
log.warn(logMessage);
if (Boolean.TRUE.equals(kafkaLogEnable)) {
Expand All @@ -208,7 +231,6 @@ public void error(String logType,String workflowInstanceId, String message, ILog
jwtPayloadToken = new JWTPayloadDTO();
}
LogDTO logDTO = LogDTO.builder().
op_issuer(jwtPayloadToken.getIss()).
op_locality(jwtPayloadToken.getLocality()).
message(message).
operation(operation.getCode()).
Expand All @@ -219,7 +241,6 @@ public void error(String logType,String workflowInstanceId, String message, ILog
op_error_description(error.getDescription()).
op_document_type(documentType).
op_role(jwtPayloadToken.getSubject_role()).
op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())).
gateway_name(getGatewayName()).
microservice_name(msName).
op_application_id(jwtPayloadToken.getSubject_application_id()).
Expand All @@ -229,6 +250,12 @@ public void error(String logType,String workflowInstanceId, String message, ILog
workflow_instance_id(workflowInstanceId).
build();

if(configSRV.isSubjectPersistenceEnabled()) {
logDTO.setOp_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub()));
}
if(configSRV.isCfOnIssuerNotAllowed()) {
logDTO.setOp_issuer(jwtPayloadToken.getIss());
}
final String logMessage = StringUtility.toJSON(logDTO);
log.error(logMessage);
if (Boolean.TRUE.equals(kafkaLogEnable)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public interface IConfigSRV {

Boolean isControlLogPersistenceEnable();

Boolean isCfOnIssuerNotAllowed();

Boolean isSubjectPersistenceEnabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_AUDIT_ENABLED;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_CONTROL_LOG_ENABLED;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_ISSUER_CF;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_SUBJECT;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.ConfigItemDTO.*;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfigItemTypeEnum.DISPATCHER;
import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfigItemTypeEnum.GENERIC;
Expand Down Expand Up @@ -88,4 +90,33 @@ private void refresh(ConfigItemTypeEnum type, String name) {
props.put(name, Pair.of(new Date().getTime(), prop));
}

@Override
public Boolean isSubjectPersistenceEnabled() {
long lastUpdate = props.get(PROPS_NAME_SUBJECT).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
synchronized (PROPS_NAME_SUBJECT) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
refresh(GENERIC, PROPS_NAME_SUBJECT);
}
}
}
return Boolean.parseBoolean(
props.get(PROPS_NAME_SUBJECT).getValue()
);
}

@Override
public Boolean isCfOnIssuerNotAllowed() {
long lastUpdate = props.get(PROPS_NAME_ISSUER_CF).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
synchronized(PROPS_NAME_ISSUER_CF) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
refresh(GENERIC, PROPS_NAME_ISSUER_CF);
}
}
}
return Boolean.parseBoolean(
props.get(PROPS_NAME_ISSUER_CF).getValue()
);
}
}

0 comments on commit 306b740

Please sign in to comment.