-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* config spring security and create endpoint to get csrf token * add unit-test for new endpoint * fix coding style * audit trasaction * fix code smells * resolve comment * remove PropertySource from AuditTransactionRequest.java * add endline in some file * replace url with mosip.api.internal.url in properties file * add auditTransactionHelper to everyendpoint * fix bug * add auditTransactionHelper with GENERATE_CHALLENGE SUCCESS * fix bug with DTO * update test case * resolve comment * rename auditEvent * remove covert request DTO * remove audit transaction * rename some var * add audit transaction in reset password endpoint * move set response time inside try catch --------- Co-authored-by: Mengleang <[email protected]> Signed-off-by: Sreang Rathanak <[email protected]>
- Loading branch information
1 parent
cc26692
commit bd32f9e
Showing
11 changed files
with
293 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
signup-service/src/main/java/io/mosip/signup/dto/AuditRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import io.mosip.esignet.core.util.IdentityProviderUtil; | ||
import io.mosip.signup.util.AuditEventType; | ||
import io.mosip.signup.util.AuditEvent; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class AuditRequest { | ||
|
||
private AuditEventType eventType; | ||
private AuditEvent eventId; | ||
private AuditEvent eventName; | ||
private String actionTimeStamp; | ||
private String hostName; | ||
private String hostIp; | ||
private String applicationId; | ||
private String applicationName; | ||
private String createdBy; | ||
private String sessionUserId; | ||
private String sessionUserName; | ||
private String id; | ||
private String idType; | ||
private String moduleName; | ||
private String moduleId; | ||
private String description; | ||
|
||
public AuditRequest(AuditEvent auditEvent, AuditEventType auditEventType, String applicationName, String sessionUserId, | ||
String id, String moduleName, String description){ | ||
|
||
this.eventId = auditEvent; | ||
this.eventName = auditEvent; | ||
this.eventType = auditEventType; | ||
this.actionTimeStamp = IdentityProviderUtil.getUTCDateTime(); | ||
this.hostName = "localhost"; | ||
this.hostIp = "localhost"; | ||
this.sessionUserId = sessionUserId; | ||
this.sessionUserName = sessionUserId; | ||
this.id = id; | ||
this.idType = "transaction"; | ||
this.moduleName = moduleName; | ||
this.moduleId = moduleName; | ||
this.description = description; | ||
this.applicationId = applicationName; | ||
this.applicationName = applicationName; | ||
this.createdBy = applicationName; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
signup-service/src/main/java/io/mosip/signup/dto/AuditResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.mosip.signup.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class AuditResponse { | ||
|
||
@JsonProperty("status") | ||
private boolean status; | ||
} |
63 changes: 63 additions & 0 deletions
63
signup-service/src/main/java/io/mosip/signup/helper/AuditHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.mosip.signup.helper; | ||
|
||
import io.mosip.signup.dto.AuditRequest; | ||
import io.mosip.signup.dto.AuditResponse; | ||
import io.mosip.signup.dto.RestRequestWrapper; | ||
import io.mosip.signup.dto.RestResponseWrapper; | ||
import io.mosip.signup.exception.SignUpException; | ||
import io.mosip.signup.util.AuditEvent; | ||
import io.mosip.signup.util.AuditEventType; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestClientException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import static io.mosip.esignet.core.util.IdentityProviderUtil.getUTCDateTime; | ||
|
||
@Slf4j | ||
@Component | ||
public class AuditHelper { | ||
|
||
@Autowired | ||
@Qualifier("selfTokenRestTemplate") | ||
private RestTemplate selfTokenRestTemplate; | ||
|
||
@Value("${spring.application.name}") | ||
private String applicationName; | ||
|
||
@Value("${mosip.signup.audit-endpoint}") | ||
String sendAuditTransactionsUrl; | ||
|
||
@Value("${mosip.signup.audit.description.max-length}") | ||
Integer auditDescriptionMaxLength; | ||
|
||
public void sendAuditTransaction(AuditEvent auditEvent, AuditEventType eventType, String transactionId, | ||
SignUpException signUpException){ | ||
|
||
RestRequestWrapper<AuditRequest> restRequestWrapper = new RestRequestWrapper<>(); | ||
restRequestWrapper.setRequesttime(getUTCDateTime()); | ||
|
||
String description = signUpException != null ? | ||
ExceptionUtils.getStackTrace(signUpException) : null; | ||
if (description != null && description.length() > auditDescriptionMaxLength) { | ||
description = description.substring(0, auditDescriptionMaxLength); | ||
} | ||
AuditRequest auditRequest = new AuditRequest(auditEvent, eventType, applicationName, "no-user", | ||
transactionId, "EsignetSignUpService", description); | ||
restRequestWrapper.setRequest(auditRequest); | ||
|
||
try{ | ||
selfTokenRestTemplate.exchange(sendAuditTransactionsUrl, HttpMethod.POST, new HttpEntity<>(restRequestWrapper), | ||
new ParameterizedTypeReference<RestResponseWrapper<AuditResponse>>(){}).getBody(); | ||
}catch (RestClientException restClientException){ | ||
log.error("An error occurred in sendAuditTransaction", restClientException); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
signup-service/src/main/java/io/mosip/signup/util/AuditEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.mosip.signup.util; | ||
|
||
public enum AuditEvent { | ||
|
||
GENERATE_CHALLENGE, | ||
VERIFY_CHALLENGE, | ||
REGISTER, | ||
REGISTER_STATUS_CHECK, | ||
RESET_PASSWORD, | ||
RESET_PASSWORD_STATUS_CHECK | ||
} |
7 changes: 7 additions & 0 deletions
7
signup-service/src/main/java/io/mosip/signup/util/AuditEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.mosip.signup.util; | ||
|
||
public enum AuditEventType { | ||
|
||
SUCCESS, | ||
ERROR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.