Search in sources :

Example 1 with UserInfo

use of ca.bc.gov.hlth.hnweb.security.UserInfo in project moh-hnweb by bcgov.

the class HL7SerializerTest method setUp.

@BeforeAll
static void setUp() throws IOException {
    mockStatic = Mockito.mockStatic(SecurityUtil.class);
    mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "00000010", "hnweb-user"));
}
Also used : SecurityUtil(ca.bc.gov.hlth.hnweb.security.SecurityUtil) UserInfo(ca.bc.gov.hlth.hnweb.security.UserInfo) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with UserInfo

use of ca.bc.gov.hlth.hnweb.security.UserInfo in project moh-hnweb by bcgov.

the class AuditService method createTransaction.

/**
 * Creates a new {@link Transaction}.
 *
 * @param sourceIP Source IP address
 * @param type The type of transaction
 * @return The persisted Transaction
 */
public Transaction createTransaction(String sourceIP, TransactionType type) {
    Transaction transaction = new Transaction();
    UserInfo userInfo = null;
    try {
        // This can throw an exception under certain auth failures
        // E.g. if an empty or invalid token is provided
        userInfo = SecurityUtil.loadUserInfo();
    } catch (Exception e) {
    // Ignore
    }
    transaction.setOrganization(userInfo != null ? userInfo.getOrganization() : null);
    transaction.setServer(getServer());
    transaction.setSessionId(userInfo != null ? userInfo.getSessionState() : null);
    transaction.setSourceIp(sourceIP);
    transaction.setStartTime(new Date());
    transaction.setTransactionId(UUID.randomUUID());
    transaction.setType(type.getValue());
    transaction.setUserId(userInfo != null ? userInfo.getUsername() : null);
    return transactionRepository.save(transaction);
}
Also used : Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) UserInfo(ca.bc.gov.hlth.hnweb.security.UserInfo) UnknownHostException(java.net.UnknownHostException) Date(java.util.Date)

Example 3 with UserInfo

use of ca.bc.gov.hlth.hnweb.security.UserInfo in project moh-hnweb by bcgov.

the class AuditServiceTest method setUp.

@BeforeAll
static void setUp() throws IOException {
    mockStatic = Mockito.mockStatic(SecurityUtil.class);
    mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "00000010", "hnweb-user", UUID.randomUUID().toString()));
}
Also used : SecurityUtil(ca.bc.gov.hlth.hnweb.security.SecurityUtil) UserInfo(ca.bc.gov.hlth.hnweb.security.UserInfo) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with UserInfo

use of ca.bc.gov.hlth.hnweb.security.UserInfo in project moh-hnweb by bcgov.

the class BaseControllerTest method setUp.

@BeforeAll
static void setUp() throws IOException {
    mockBackEnd = new MockWebServer();
    mockBackEnd.start(0);
    mockStatic = Mockito.mockStatic(SecurityUtil.class);
    mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "00000010", "hnweb-user", UUID.randomUUID().toString()));
}
Also used : MockWebServer(okhttp3.mockwebserver.MockWebServer) SecurityUtil(ca.bc.gov.hlth.hnweb.security.SecurityUtil) UserInfo(ca.bc.gov.hlth.hnweb.security.UserInfo) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with UserInfo

use of ca.bc.gov.hlth.hnweb.security.UserInfo in project moh-hnweb by bcgov.

the class EnrollmentService method getDemographics.

/**
 * Gets the demographic details by sending a V3 message to external endpoint.
 * Calls HL7Serializer api to serialize and deserialize request/response
 * @param demographicsRequest
 * @param transaction
 * @return
 * @throws HNWebException
 */
public GetDemographicsResponse getDemographics(GetDemographicsRequest demographicsRequest, Transaction transaction) throws HNWebException {
    HL7Serializer hl7Serializer = new HL7Serializer(new HL7Config());
    UserInfo userInfo = SecurityUtil.loadUserInfo();
    MessageMetaData mmd = new MessageMetaData(userInfo.getUsername(), SOURCE_SYSTEM_OVERRIDE, ORGANIZATION, transaction.getTransactionId().toString());
    // Serialize request object
    Object formattedRequest = hl7Serializer.toXml(demographicsRequest, mmd);
    // Create soap wrapper
    String xmlString = V3MessageUtil.wrap(formattedRequest.toString());
    logger.debug("Get Demographics wrapped xml request[{}]", xmlString);
    messageSent(transaction, mmd.getMessageIdExt());
    ResponseEntity<String> response = postHcimRequest(xmlString, transaction.getTransactionId().toString());
    logger.debug("Response Status: {} ; Message:\n{}", response.getStatusCode(), response.getBody());
    if (response.getStatusCode() != HttpStatus.OK) {
        logger.error("Could not connect to downstream service. Service returned {}", response.getStatusCode());
        throw new HNWebException(ExceptionType.DOWNSTREAM_FAILURE);
    }
    // De-Serialize demographics response
    GetDemographicsResponse getDemographicsResponse = hl7Serializer.fromXml(response.getBody(), GetDemographicsResponse.class);
    messageReceived(transaction, getDemographicsResponse.getMessageIdExtension());
    return getDemographicsResponse;
}
Also used : MessageMetaData(ca.bc.gov.hlth.hnweb.model.v3.MessageMetaData) HL7Serializer(ca.bc.gov.hlth.hnweb.serialization.HL7Serializer) HNWebException(ca.bc.gov.hlth.hnweb.exception.HNWebException) HL7Config(ca.bc.gov.hlth.hnweb.serialization.HL7Config) GetDemographicsResponse(ca.bc.gov.hlth.hnweb.model.v3.GetDemographicsResponse) UserInfo(ca.bc.gov.hlth.hnweb.security.UserInfo)

Aggregations

UserInfo (ca.bc.gov.hlth.hnweb.security.UserInfo)6 SecurityUtil (ca.bc.gov.hlth.hnweb.security.SecurityUtil)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 HNWebException (ca.bc.gov.hlth.hnweb.exception.HNWebException)2 MessageMetaData (ca.bc.gov.hlth.hnweb.model.v3.MessageMetaData)2 HL7Config (ca.bc.gov.hlth.hnweb.serialization.HL7Config)2 HL7Serializer (ca.bc.gov.hlth.hnweb.serialization.HL7Serializer)2 FindCandidatesResponse (ca.bc.gov.hlth.hnweb.model.v3.FindCandidatesResponse)1 GetDemographicsResponse (ca.bc.gov.hlth.hnweb.model.v3.GetDemographicsResponse)1 Transaction (ca.bc.gov.hlth.hnweb.persistence.entity.Transaction)1 UnknownHostException (java.net.UnknownHostException)1 Date (java.util.Date)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1