Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into develop

This commit is contained in:
harish
2024-10-01 19:17:14 +05:30
16 changed files with 225 additions and 9 deletions

View File

@@ -49,6 +49,12 @@ public class SamlConfig {
@Value("${base-url}")
String baseUrl;
@Value("${spid.ipd.base.url}")
String ipdBaseUrl;
@Value("${active.profile.folder}")
String activeProfileFolder;
@Bean
public RelyingPartyRegistrationRepository relyingPartyRegistrationRepository() {
@@ -66,8 +72,8 @@ public class SamlConfig {
}
})
.assertionConsumerServiceLocation(acsUrl)
.assertingPartyDetails(details -> details.entityId("https://federatest.umbriadigitale.it/gw/metadata")
.singleSignOnServiceLocation("https://federatest.umbriadigitale.it/gw/SSOProxy/SAML2")
.assertingPartyDetails(details -> details.entityId(ipdBaseUrl + "/gw/metadata")
.singleSignOnServiceLocation(ipdBaseUrl + "/gw/SSOProxy/SAML2")
.singleSignOnServiceBinding(Saml2MessageBinding.POST)
.wantAuthnRequestsSigned(true)
.verificationX509Credentials(credentials -> {
@@ -133,8 +139,8 @@ public Saml2AuthenticationRequestResolver authenticationRequestResolver(RelyingP
authnRequest.setRequestedAuthnContext(buildRequestedAuthnContext());
// Log the SAML AuthnRequest after setting context
// String samlRequest = SamlRequestLogger.convertSAMLObjectToString(authnRequest);
logger.info("SAML Authentication Request.");
String samlRequest = SamlRequestLogger.convertSAMLObjectToString(authnRequest);
logger.info("SAML AuthnRequest after setting context: " + samlRequest);
});
return authenticationRequestResolver;
@@ -158,7 +164,7 @@ private RequestedAuthnContext buildRequestedAuthnContext() {
public PrivateKey readPrivateKey() throws Exception {
// Path to your private key PEM file
try (PemReader pemReader = new PemReader(new InputStreamReader(readKey("dev/saml/private-key.pem")))) {
try (PemReader pemReader = new PemReader(new InputStreamReader(readKey(activeProfileFolder + "/saml/private-key.pem")))) {
// Read the PEM content
byte[] pemContent = pemReader.readPemObject().getContent();
// Decode the PEM content
@@ -170,7 +176,7 @@ private RequestedAuthnContext buildRequestedAuthnContext() {
}
public X509Certificate readCertificate() throws Exception {
// Path to your certificate PEM fileFile
try (InputStream inStream = readKey("dev/saml/public-cert.pem")) {
try (InputStream inStream = readKey(activeProfileFolder + "/saml/public-cert.pem")) {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
return (X509Certificate) certFactory.generateCertificate(inStream);
}
@@ -178,7 +184,7 @@ private RequestedAuthnContext buildRequestedAuthnContext() {
public X509Certificate readIdpCertificate() throws Exception {
// Path to your IDP public certificate PEM file
try (InputStream inStream = readKey("dev/saml/idp-certificate.pem")) {
try (InputStream inStream = readKey(activeProfileFolder + "/saml/idp-certificate.pem")) {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
return (X509Certificate) certFactory.generateCertificate(inStream);
}

View File

@@ -45,6 +45,7 @@ public class SamlSuccessHandler implements AuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException {
try {
logger.info("SAML login in Authentication Success Handler");
Saml2Authentication samlAuth = (Saml2Authentication) authentication;
Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) samlAuth.getPrincipal();

View File

@@ -1,5 +1,6 @@
package net.gepafin.tendermanagement.dao;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -10,6 +11,7 @@ import java.util.stream.Collectors;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.service.*;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -124,6 +126,17 @@ public class CallDao {
callEntity.setConfidi(createCallRequest.getConfidi());
}
callEntity.setDocumentationRequested(createCallRequest.getDocumentationRequested());
if (createCallRequest.getAmountMin() != null && createCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) {
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
}
callEntity.setAmountMin(createCallRequest.getAmountMin());
if(createCallRequest.getEmail()==null || Boolean.FALSE.equals(Utils.isValidEmail(createCallRequest.getEmail()))){
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.VALIDATION_EMAIL,createCallRequest.getEmail()));
}
callEntity.setEmail(createCallRequest.getEmail());
callEntity.setPhoneNumber(createCallRequest.getPhoneNumber());
callEntity.setStartTime(DateTimeUtil.parseTime(createCallRequest.getStartTime()));
callEntity.setEndTime(DateTimeUtil.parseTime(createCallRequest.getEndTime()));
callEntity = callRepository.save(callEntity);
return callEntity;
}
@@ -259,6 +272,11 @@ public class CallDao {
createCallResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
createCallResponseBean.setPriorityArea(callEntity.getPriorityArea());
createCallResponseBean.setConfidi(callEntity.getConfidi());
createCallResponseBean.setAmountMin(callEntity.getAmountMin());
createCallResponseBean.setPhoneNumber(callEntity.getPhoneNumber());
createCallResponseBean.setEndTime(callEntity.getEndTime());
createCallResponseBean.setStartTime(callEntity.getStartTime());
createCallResponseBean.setEmail(callEntity.getEmail());
createCallResponseBean.setCreatedDate(callEntity.getCreatedDate());
createCallResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
return createCallResponseBean;
@@ -456,6 +474,18 @@ public class CallDao {
setIfUpdated(callEntity::getAmountMax, callEntity::setAmountMax, updateCallRequest.getAmountMax());
setIfUpdated(callEntity::getDocumentationRequested, callEntity::setDocumentationRequested,
updateCallRequest.getDocumentationRequested());
if (updateCallRequest.getAmountMin() != null && updateCallRequest.getAmountMin().compareTo(BigDecimal.ZERO) < 0) {
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
}
if(updateCallRequest.getEmail()==null || Boolean.FALSE.equals(Utils.isValidEmail(updateCallRequest.getEmail()))){
throw new CustomValidationException(Status.VALIDATION_ERROR,Translator.toLocale(GepafinConstant.VALIDATION_EMAIL,updateCallRequest.getEmail()));
}
setIfUpdated(callEntity::getAmountMin, callEntity::setAmountMin, updateCallRequest.getAmountMin());
setIfUpdated(callEntity::getEmail, callEntity::setEmail, updateCallRequest.getEmail());
setIfUpdated(callEntity::getPhoneNumber, callEntity::setPhoneNumber, updateCallRequest.getPhoneNumber());
setIfUpdated(callEntity::getStartTime, callEntity::setStartTime, DateTimeUtil.parseTime(updateCallRequest.getStartTime()));
setIfUpdated(callEntity::getEndTime, callEntity::setEndTime, DateTimeUtil.parseTime(updateCallRequest.getEndTime()));
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO);
updateFaq(updateCallRequest.getFaq(), callEntity, userEntity, LookUpDataTypeEnum.FAQ);
@@ -531,6 +561,11 @@ public class CallDao {
callDetailsResponseBean.setThreshold(callEntity.getThreshold());
callDetailsResponseBean.setDocumentationRequested(callEntity.getDocumentationRequested());
callDetailsResponseBean.setPriorityArea(callEntity.getPriorityArea());
callDetailsResponseBean.setAmountMin(callEntity.getAmountMin());
callDetailsResponseBean.setEmail(callEntity.getEmail());
callDetailsResponseBean.setEndTime(callEntity.getEndTime());
callDetailsResponseBean.setStartTime(callEntity.getStartTime());
callDetailsResponseBean.setPhoneNumber(callEntity.getPhoneNumber());
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
return callDetailsResponseBean;

View File

@@ -8,6 +8,7 @@ import lombok.Builder;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
@Entity
@Table(name = "CALL")
@@ -68,5 +69,20 @@ public class CallEntity extends BaseEntity {
@Column(name="FINAL_FORM")
private Long finalForm;
@Column(name = "AMOUNT_MIN")
private BigDecimal amountMin;
@Column(name="EMAIL")
private String email;
@Column(name = "PHONE_NUMBER")
private String phoneNumber;
@Column(name = "START_TIME")
private LocalTime startTime;
@Column(name = "END_TIME")
private LocalTime endTime;
}

View File

@@ -2,7 +2,9 @@ package net.gepafin.tendermanagement.model.request;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import lombok.Data;
@Data
@@ -26,6 +28,16 @@ public class CreateCallRequestStep1 {
private String documentationRequested;
private BigDecimal amountMin;
private String email;
private String phoneNumber;
private String startTime;
private String endTime;
private Boolean confidi;
private List<FaqReq> faq;

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.request;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import lombok.Data;
@@ -25,6 +26,16 @@ public class UpdateCallRequestStep1 {
private String documentationRequested;
private BigDecimal amountMin;
private String email;
private String phoneNumber;
private String startTime;
private String endTime;
private Boolean confidi;
private List<FaqReq> faq;

View File

@@ -5,6 +5,7 @@ import net.gepafin.tendermanagement.enums.CallStatusEnum;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
@Data
public class CallDetailsResponseBean {
@@ -37,6 +38,16 @@ public class CallDetailsResponseBean {
private String documentationRequested;
private BigDecimal amountMin;
private String email;
private String phoneNumber;
private LocalTime startTime;
private LocalTime endTime;
private LocalDateTime createdDate;
private LocalDateTime updatedDate;

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.model.response;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import lombok.Data;
@@ -40,6 +41,16 @@ public class CallResponse {
private Boolean confidi;
private BigDecimal amountMin;
private String email;
private String phoneNumber;
private LocalTime startTime;
private LocalTime endTime;
private LocalDateTime createdDate;
private LocalDateTime updatedDate;

View File

@@ -10,6 +10,7 @@ import net.gepafin.tendermanagement.model.response.CallResponse;
import net.gepafin.tendermanagement.model.response.FlowResponseBean;
import net.gepafin.tendermanagement.model.response.FormResponseBean;
import net.gepafin.tendermanagement.util.FieldValidator;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@@ -28,6 +29,10 @@ public class CallValidatorServiceImpl {
.notNull(response.getAmount(), "amount")
.notNull(response.getAmountMax(), "amountMax")
.notNull(response.getThreshold(), "threshold")
.notNull(response.getEmail(),"email")
.notNull(response.getAmountMin(),"amountMin")
.notNull(response.getStartTime(),"startTime")
.notNull(response.getEndTime(),"endTime")
.notNull(response.getDocumentationRequested(), "documentationRequested")
.notEmpty(response.getAimedTo(), "aimedTo")
.notEmpty(response.getCriteria(), "criteria")

View File

@@ -1,16 +1,29 @@
package net.gepafin.tendermanagement.util;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;
@Component
public class DateTimeUtil {
private static final Pattern TIME_PATTERN = Pattern.compile(
"^((([01]?\\d|2[0-3]):([0-5]\\d)(:[0-5]\\d)?(\\s?[AP]M)?)|((0?[1-9]|1[0-2]):([0-5]\\d)(:[0-5]\\d)?\\s?[AP]M))$");
public static LocalDateTime DateServerToUTC(LocalDateTime systemDate) {
@@ -50,4 +63,27 @@ public class DateTimeUtil {
.from(localDateTime.atZone(ZoneId.systemDefault())
.toInstant());
}
public static LocalTime parseTime(String timeString) throws DateTimeParseException {
DateTimeFormatter formatter;
if(timeString==null) {
return null;
}
if (!TIME_PATTERN.matcher(timeString).matches()) {
throw new CustomValidationException(Status.BAD_REQUEST,"Invalid time format: " + timeString);
}
// Try to parse using default formats if no format is provided
String[] defaultFormats = {"HH:mm:ss", "HH:mm", "HH:mm:ss a", "hh:mm a"};
for (String defaultFormat : defaultFormats) {
formatter = DateTimeFormatter.ofPattern(defaultFormat);
try {
return LocalTime.parse(timeString, formatter);
} catch (DateTimeParseException e) {
// Continue to the next format
}
}
// If all parsing attempts fail, throw an exception
throw new CustomValidationException(Status.BAD_REQUEST,"Failed to parse time: " + timeString);
}
}