Skip to content

Commit

Permalink
Deployed to Demo - Release-1.1.1 (#193)
Browse files Browse the repository at this point in the history
* chore(deps): update all dependencies (#159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* RET-2643 (#185)

* chore(deps): update all dependencies (#159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* RET-2643

* RET-2643

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Harpreet Jhita <harpreet.jhita@justice.gov.uk>

* caseTypeId removed from log as it is null (#186)

* Added pound symbol and line seperators (#188)

* RET-2792 (#192)

* RET-2792 - revert changes (#197)

* RET-2792 (#196)

* RET-2731: Mock out ACAS Service tests and improve logging in et-sya-api (#190)

* RET-2731: Mock AcasService tests

* RET-2731: Add logs to AcasService attemptWithRetriesToFetchAcasCertificates()

* RET-2731: change acas apie key to dummy

* RET-2731: Checkstyle fixes

* RET-2731: Remove disabled annotation

Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>

* Ret 2800 (#195)

* RET-2800: Supporting Document not present in documentCollection

* RET-2800: Fixed pmd

* moved method to CaseDocumentService

* Ret 2783 Welsh translation content - Generate Welsh pdf claim form (#191)

* RET-2783: Added welsh PDF case file generation if the user has selected to be contacted in welsh

* Fix broken unit tests

* added welsh tests

* fixed welsh tests to work with differant language generations

* minor review comments

* fixed breaking change, changing pdf document name

* fixed build issues

Co-authored-by: Jack Brogan <jack.brogan@hmcts.net>
Co-authored-by: paul.peasegood <paul.peasegood@version1.com>

* Ret 2800 2 (#198)

* RET-2800: Supporting Document not present in documentCollection

* RET-2800: Fixed pmd

* moved method to CaseDocumentService

* RET-2800: Added test coverage

* Ret 2792 new (#200)

* Ret 2792 new (#201)

* Ret 2846 (#202)

* Updates for PDF Creation

* Updates for PDF Creation

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Removed suppressed vulnerability and changed spring-cloud-starter-openfeign version from 3.1.2 to 3.1.5

* Removed suppressed vulnerability

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.13.4.1' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding   implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Ret 2864 postcode and test updates - javadoc Implementation (#205)

* Updates for PDF Creation

* Updates for PDF Creation

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Removed suppressed vulnerability and changed spring-cloud-starter-openfeign version from 3.1.2 to 3.1.5

* Removed suppressed vulnerability

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.13.4.1' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding   implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Updated tests added new postcode formatter to PdfMapperUtil

* Updated tests added new postcode formatter to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Changed convertFirstCharactersToCapitalCase method name to convertFirstCharactersOfWordsToCapitalCase

* Updates for country list of UK. (#206)

* Handling null values (#204)

* Fixed missing imports

* Refactored test

* Merge1.1.0.2 into welsh (#208)

* RET-2643 (#185)

* chore(deps): update all dependencies (#159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* RET-2643

* RET-2643

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Harpreet Jhita <harpreet.jhita@justice.gov.uk>

* caseTypeId removed from log as it is null (#186)

* Added pound symbol and line seperators (#188)

* RET-2792 (#192)

* RET-2792 - revert changes (#197)

* RET-2731: Mock out ACAS Service tests and improve logging in et-sya-api (#190)

* RET-2731: Mock AcasService tests

* RET-2731: Add logs to AcasService attemptWithRetriesToFetchAcasCertificates()

* RET-2731: change acas apie key to dummy

* RET-2731: Checkstyle fixes

* RET-2731: Remove disabled annotation

Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>

* Ret 2800 (#195)

* RET-2800: Supporting Document not present in documentCollection

* RET-2800: Fixed pmd

* moved method to CaseDocumentService

* Ret 2800 2 (#198)

* RET-2800: Supporting Document not present in documentCollection

* RET-2800: Fixed pmd

* moved method to CaseDocumentService

* RET-2800: Added test coverage

* Ret 2846 (#202)

* Updates for PDF Creation

* Updates for PDF Creation

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Removed suppressed vulnerability and changed spring-cloud-starter-openfeign version from 3.1.2 to 3.1.5

* Removed suppressed vulnerability

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.13.4.1' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding   implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Ret 2864 postcode and test updates - javadoc Implementation (#205)

* Updates for PDF Creation

* Updates for PDF Creation

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Suppressed jackson core - jackson databind@2.13.4
NOTE: this is a new vulnerability defined on 17/NOV/2022 details are defined in the url https://nvd.nist.gov/vuln/detail/CVE-2022-42003

* Removed suppressed vulnerability and changed spring-cloud-starter-openfeign version from 3.1.2 to 3.1.5

* Removed suppressed vulnerability

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.13.4.1' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Vulnerability CVE-2022-42003 is resolved by adding   implementation group: 'com.fasterxml.jackson.core', name:  'jackson-databind', version: '2.14.0' to the dependencies section of build.gradle at line 220. Besides upgraded depreciated main definition on line 326

* Updated tests added new postcode formatter to PdfMapperUtil

* Updated tests added new postcode formatter to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Added Javadocs to PdfMapperUtil

* Changed convertFirstCharactersToCapitalCase method name to convertFirstCharactersOfWordsToCapitalCase

* Updates for country list of UK. (#206)

* Update CaseService.java

Update CaseService.java

* Refactored test

* Checkstyle

Co-authored-by: GauravChawlaMOJ <58194626+GauravChawlaMOJ@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: ikirsanov <105438011+ikirsanov@users.noreply.github.com>
Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>
Co-authored-by: robin-ieong <101253854+robin-ieong@users.noreply.github.com>
Co-authored-by: Mehmet Tahir Dede <105645217+JustMehmet@users.noreply.github.com>

* Test fix

* Test fix

Test fix

* RET-2750: Add functional tests to controllers classes (#203)

* RET-2750: Add DocumentUpload functional test

* RET-2750: Chekstyle fix

* RET-2750: Chekstyle fix

* RET-2750: Add vulnerability issue fix

* RET-2750: Change multipart params

* RET-2750: CheckStyle

* RET-2750: multipart content type

* RET-2750: Add functional tests to DocumentUploadController

* RET-2750: Add functional tests for DocumentController

* RET-2750: Fix DocumentControllerFunctionalTest

* RET-2750: Add AcasControllerFunctionalTest

Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>

* RET-2574: Add manageOffice assignment before case submitted (#178)

* chore(deps): update all dependencies (#159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* RET-2574: Add manageOffice assignment before case submitted

* RET-2574: Rename case assignment to local office service and move it to service package

* RET-2574: checkStyle test fixes

* RET-2574: checkStyle test fixes

* RET-2574: Fix assigning case to local office logic, remove unused imports

* RET-2574: Add suppressions for spring security and tomcat

* RET-2574: Set @disable to AcasService tests

* RET-2574: Add in convertCaseRequestToCaseDataWithTribunalOffice managingOffice assignment to caseRequest

* RET-2574: getManagingOffice returns Unassigned if invalidPostcodeException thrown

* RET-2574: checkstyle fix

* RET-2574: Remove suppressions

* RET-2574: AcasServiceTest fix

* RET-2574: AcasServiceTest fix

* RET-2574: Refactor condition in assingCaseToLocalOfficeService

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>
Co-authored-by: Harpreet Jhita <harpreet.jhita@justice.gov.uk>

* Fix disability claim (#209)

* claimantInd null values (#214)

* Keeping sonar happy (#215)

* claimantInd null values

* sonar checks

* sonar checks

* RET-2877 - Null check for contact language (#212)

* Null check for contact language

* Refactor notification service

* Use Welsh language constant

* RET-2871 fix (#217)

* RET-2818. Update et-data-model version to add hearing language preference. (#211)

* cve (#220)

* cve

* cve suppressions

* cve suppressions

* cve suppressions

* RET-2848 (#219)

* Et data model update (#225)

* Ret 2864 add java docs to public/protected elements (#224)

* 2864: add javadocs to classes

* 2864: add jdocs

* 2864: add more jdocs

* 2864: add jdocs and fix issues

* 2864: fix merge and pmd

* Release 1.1.0.2 (#207) (#226)

All code merged for Release 1.1.0.2.

- Referral Enhancements
- Initial Consideration Enhancements
- Bug Fixes
- ECM fixes/enhancements

Co-authored-by: Harpreet Jhita <harpreet.jhita@justice.gov.uk>
Co-authored-by: Marc Judge <marc.judge@version1.com>

* Add file extension (#227)

* Add file extension

* Fix checkstyle

* Bump spring boot

Co-authored-by: Marc Judge <marc.judge@version1.com>

* Acas cert logging removed (#232)

* welsh doc template updated (#233)

* Allow all test responses (#239)

Co-authored-by: Marc Judge <marc.judge@version1.com>

* RET-3045: Fix for respondent details being reset (#238)

* RET-3045: Fix for respondent details being reset

* Fix for CVEs

* Fix for CVEs

* Fix for checkstyle

* Refactered to not use var type

* Update Welsh email template to prod (#259)

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: GauravChawlaMOJ <58194626+GauravChawlaMOJ@users.noreply.github.com>
Co-authored-by: Harpreet Jhita <harpreet.jhita@justice.gov.uk>
Co-authored-by: ikirsanov <105438011+ikirsanov@users.noreply.github.com>
Co-authored-by: KirsanovI <ivan.kirsanov@hmcts.net>
Co-authored-by: robin-ieong <101253854+robin-ieong@users.noreply.github.com>
Co-authored-by: paul-peasegood <116294451+paul-peasegood@users.noreply.github.com>
Co-authored-by: Jack Brogan <jack.brogan@hmcts.net>
Co-authored-by: paul.peasegood <paul.peasegood@version1.com>
Co-authored-by: Mehmet Tahir Dede <105645217+JustMehmet@users.noreply.github.com>
Co-authored-by: Itay-Kirsh <Itayk747@gmail.com>
Co-authored-by: Daryl Boam <104851463+DarylBoam@users.noreply.github.com>
Co-authored-by: Marc Judge <marc.judge@version1.com>
  • Loading branch information
14 people authored Feb 16, 2023
1 parent c5c1a5f commit 9087423
Show file tree
Hide file tree
Showing 45 changed files with 706 additions and 239 deletions.
1 change: 1 addition & 0 deletions charts/et-sya-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ java:
CASE_DOCUMENT_AM_URL: "http://ccd-case-document-am-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal"
CITIZEN_PORTAL_LINK: "https://et-sya.{{ .Values.global.environment }}.platform.hmcts.net/citizen-hub/"
SUBMIT_CASE_EMAIL_TEMPLATE_ID: "4f4b378e-238a-46ed-ae1c-26b8038192f0"
CY_SUBMIT_CASE_EMAIL_TEMPLATE_ID: "970257cd-3464-4ec9-bbb8-45fd9128001c"
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void setUpBeforeEach() {
@DisplayName("Should get single case details")
@Test
void caseDetailsEndpoint() throws Exception {
when(ccdApiClient.getCase(any(),any(),any())).thenReturn(caseDetailsResponse);
when(ccdApiClient.getCase(any(), any(), any())).thenReturn(caseDetailsResponse);
CaseRequest caseRequest = CaseRequest.builder()
.caseId("1646").build();

Expand All @@ -100,7 +100,7 @@ void caseDetailsEndpoint() throws Exception {
@DisplayName("Should get all case details list by user")
@Test
void returnCasesByUserEndpoint() throws Exception {
when(ccdApiClient.searchForCitizen(any(),any(),any(),any(),any(),any()))
when(ccdApiClient.searchForCitizen(any(), any(), any(), any(), any(), any()))
.thenReturn(Collections.singletonList(caseDetailsResponse));

mockMvc.perform(get("/cases/user-cases").header(HttpHeaders.AUTHORIZATION, AUTH_TOKEN))
Expand All @@ -114,17 +114,17 @@ void createCaseEndpoint() throws Exception {
CaseRequest caseRequest = CaseRequest.builder()
.build();

when(ccdApiClient.startForCitizen(any(),any(),any(),any(),any(),any()))
when(ccdApiClient.startForCitizen(any(), any(), any(), any(), any(), any()))
.thenReturn(startEventResponse);

when(ccdApiClient.submitForCitizen(any(),any(),any(),any(),any(),anyBoolean(),any()))
when(ccdApiClient.submitForCitizen(any(), any(), any(), any(), any(), anyBoolean(), any()))
.thenReturn(caseDetailsResponse);

mockMvc.perform(
post("/cases/initiate-case")
.header(HttpHeaders.AUTHORIZATION, AUTH_TOKEN)
.contentType(MediaType.APPLICATION_JSON)
.content(resourceLoader.toJson(caseRequest)))
post("/cases/initiate-case")
.header(HttpHeaders.AUTHORIZATION, AUTH_TOKEN)
.contentType(MediaType.APPLICATION_JSON)
.content(resourceLoader.toJson(caseRequest)))
.andExpect(status().isOk())
.andExpect(content().json(getSerialisedMessage(CASE_DETAILS_JSON)));
}
Expand All @@ -137,9 +137,9 @@ void updateDraftCaseEndpoint() throws Exception {
.caseId("12")
.build();

when(ccdApiClient.startEventForCitizen(any(),any(),any(),any(),any(),any(),any()))
when(ccdApiClient.startEventForCitizen(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(startEventResponse);
when(ccdApiClient.submitEventForCitizen(any(),any(),any(),any(),any(),any(),anyBoolean(),any()))
when(ccdApiClient.submitEventForCitizen(any(), any(), any(), any(), any(), any(), anyBoolean(), any()))
.thenReturn(caseDetailsResponse);

mockMvc.perform(
Expand All @@ -159,9 +159,9 @@ void submitCaseEndpoint() throws Exception {
.caseId("12")
.build();

when(ccdApiClient.startEventForCitizen(any(),any(),any(),any(),any(),any(),any()))
when(ccdApiClient.startEventForCitizen(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(startEventResponse);
when(ccdApiClient.submitEventForCitizen(any(),any(),any(),any(),any(),any(),anyBoolean(),any()))
when(ccdApiClient.submitEventForCitizen(any(), any(), any(), any(), any(), any(), anyBoolean(), any()))
.thenReturn(caseDetailsResponse);

mockMvc.perform(
Expand All @@ -181,9 +181,9 @@ void updateSubmittedCaseEndpoint() throws Exception {
.caseId("12")
.build();

when(ccdApiClient.startEventForCitizen(any(),any(),any(),any(),any(),any(),any()))
when(ccdApiClient.startEventForCitizen(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(startEventResponse);
when(ccdApiClient.submitEventForCitizen(any(),any(),any(),any(),any(),any(),anyBoolean(),any()))
when(ccdApiClient.submitEventForCitizen(any(), any(), any(), any(), any(), any(), anyBoolean(), any()))
.thenReturn(caseDetailsResponse);

mockMvc.perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@
import uk.gov.hmcts.reform.authorisation.validators.AuthTokenValidator;
import uk.gov.hmcts.reform.authorisation.validators.ServiceAuthTokenValidator;

/**
* sets the configuration for {@link AuthTokenGeneratorFactory}.
* This relies upon the following configurations to be set at an environment level:
* <ul>
* <li>IDAM_S2S_AUTH_SECRET</li>
* <li>MICRO_SERVICE</li>
* </ul>
*/
@Configuration
@Lazy
public class AuthConfiguration {

/**
* Creates a new auth token generator with the relevent attributes for sending request from this service.
* @param secret service to service secret api key
* @param microService name of the service using this generator
* @param serviceAuthorisationApi API used to manage the created token
* @return {@link AuthTokenGenerator} used to generate jwt for service calls
*/
@Bean
public AuthTokenGenerator serviceAuthTokenGenerator(
@Value("${idam.s2s-auth.secret}") final String secret,
Expand All @@ -23,6 +38,11 @@ public AuthTokenGenerator serviceAuthTokenGenerator(
return AuthTokenGeneratorFactory.createDefaultGenerator(secret, microService, serviceAuthorisationApi);
}

/**
* Returns validator used to validate incoming jwts.
* @param s2sApi authorization api for the jwt
* @return {@link AuthTokenValidator} to validate the jwt
*/
@Bean
public AuthTokenValidator tokenValidator(ServiceAuthorisationApi s2sApi) {
return new ServiceAuthTokenValidator(s2sApi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;

/**
* Creates a handler that will handle specific exceptions that occur anywhere in the API.
*/
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

/**
* Intercepts any {@link InvalidTokenException} occurances within the api and builds an appropriate response.
* @param exception that just occured
* @return {@link ErrorResponse} with the Unauthorised (401) response
*/
@ExceptionHandler(InvalidTokenException.class)
public ResponseEntity<ErrorResponse> handleInvalidTokenException(InvalidTokenException exception) {
log.error(exception.getMessage(), exception);
Expand All @@ -31,6 +39,11 @@ public ResponseEntity<ErrorResponse> handleInvalidTokenException(InvalidTokenExc
);
}

/**
* Intercepts any {@link UnAuthorisedServiceException} occurances within the api and builds an appropriate response.
* @param unAuthorisedServiceException that just occured
* @return {@link ErrorResponse} with the Forbidden response
*/
@ExceptionHandler(UnAuthorisedServiceException.class)
public ResponseEntity<ErrorResponse> handleUnAuthorisedServiceException(
UnAuthorisedServiceException unAuthorisedServiceException
Expand All @@ -44,6 +57,11 @@ public ResponseEntity<ErrorResponse> handleUnAuthorisedServiceException(
);
}

/**
* Intercepts any {@link FeignException} occurances within the api and builds an appropriate response.
* @param exception that just occured
* @return {@link ErrorResponse} with the exception details
*/
@ExceptionHandler(FeignException.class)
ResponseEntity<ErrorResponse> handleFeignException(FeignException exception) {
log.error(exception.getMessage(), exception);
Expand All @@ -56,6 +74,11 @@ ResponseEntity<ErrorResponse> handleFeignException(FeignException exception) {
);
}

/**
* Intercepts any {@link ResponseStatusException} occurances within the api and builds an appropriate response.
* @param exception that just occured
* @return {@link ErrorResponse} with the exception details
*/
@ExceptionHandler(ResponseStatusException.class)
public ResponseEntity<ErrorResponse> handleResponseStatusException(ResponseStatusException exception) {
log.error(exception.getMessage(), exception);
Expand All @@ -67,6 +90,11 @@ public ResponseEntity<ErrorResponse> handleResponseStatusException(ResponseStatu
);
}

/**
* Intercepts any {@link ResourceNotFoundException} occurances within the api and builds an appropriate response.
* @param exception that just occured
* @return {@link ErrorResponse} with the Not Found (404) response
*/
@ExceptionHandler(ResourceNotFoundException.class)
protected ResponseEntity<Object> handleResourceNotFoundException(final ResourceNotFoundException exception) {
return ResponseEntity.status(NOT_FOUND).body(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
import uk.gov.hmcts.reform.et.syaapi.notification.NotificationsProperties;
import uk.gov.service.notify.NotificationClient;

/**
* Initialize configurations for the notification controller.
*/
@Configuration
public class NotificationsConfiguration {

/**
* Creates an entirely new {@link NotificationsProperties} object.
* @return the new properties object
*/
@Bean
public NotificationsProperties notificationsProperties() {
return new NotificationsProperties();
}

/**
* Creates a new {@link NotificationClient} initialised with the api key.
* @param notificationsProperties current properties in {@link NotificationsProperties} format
* @return a new initialised {@link NotificationClient} object
*/
@Bean
public NotificationClient notificationClient(NotificationsProperties notificationsProperties) {
return new NotificationClient(notificationsProperties.getGovNotifyApiKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

import static uk.gov.hmcts.reform.et.syaapi.constants.EtSyaConstants.REMOTE_REPO;

/**
* Configures the settings for OpenAPI for the project.
*/
@Configuration
public class OpenAPIConfiguration {

/**
* Configures the settings for OpenAPI for the project.
* @return {@link OpenAPI} object with project specific information
*/
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import uk.gov.hmcts.reform.et.syaapi.config.interceptors.RequestInterceptor;

/**
* Configures the API to add intercepters for calls from external sources.
*/
@Component
public class WebConfig implements WebMvcConfigurer {

@Autowired
private RequestInterceptor requestInterceptor;

/**
* This config excludes certain urls to the inteceptor.
* these are endpoints that do not require authentication
* @param registry {@link InterceptorRegistry} in which the exclusions for the inteceptor are added
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestInterceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;

import java.io.IOException;
import java.util.Objects;
import java.util.Properties;

/**
* Factory to enable YAML files to be used with {@link PropertySource}.
*
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {

/**
* Creates the property source.
* @param name the name of the property source.
* (can be {@code null} in which case the factory implementation
* will have to generate a name based on the given resource)
* @param resource the resource (potentially encoded) to wrap
* @return a new {@link PropertySource}
*/
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
public PropertySource<?> createPropertySource(String name, EncodedResource resource) {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(resource.getResource());

Properties properties = factory.getObject();

return new PropertiesPropertySource(resource.getResource().getFilename(), properties);
return new PropertiesPropertySource(Objects.requireNonNull(resource.getResource().getFilename()),
Objects.requireNonNull(properties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import static org.springframework.http.HttpHeaders.AUTHORIZATION;

/**
* Intercepts any call to the et-sya-api and validates the token.
*/
@Slf4j
@Component
public class RequestInterceptor implements HandlerInterceptor {
Expand All @@ -20,6 +23,13 @@ public class RequestInterceptor implements HandlerInterceptor {
@Autowired
VerifyTokenService verifyTokenService;

/**
* Intercepts any incoming calls and throws exception if token is invalid.
* @param requestServlet current HTTP request
* @param responseServlet current HTTP response
* @param handler chosen handler to execute, for type and/or instance evaluation
* @return true if the token is verified
*/
@Override
public boolean preHandle(HttpServletRequest requestServlet, HttpServletResponse responseServlet, Object handler) {
String authorizationHeader = requestServlet.getHeader(AUTHORIZATION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package uk.gov.hmcts.reform.et.syaapi.config.interceptors;

import uk.gov.hmcts.reform.et.syaapi.service.CaseService;

/**
* Called by {@link CaseService} when exception is encountered whilst downloading document resource.
*/
public class ResourceNotFoundException extends RuntimeException {
private static final long serialVersionUID = 4L;

/**
* Throws a {@link ResourceNotFoundException} with a message and a cause.
* @param message exception message
* @param ex exception cause
*/
public ResourceNotFoundException(String message, Throwable ex) {
super(message, ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package uk.gov.hmcts.reform.et.syaapi.config.interceptors;

/**
* called by {@link RequestInterceptor} when token authentication throws an error.
*/
public class UnAuthorisedServiceException extends RuntimeException {
private static final long serialVersionUID = -8778329799233256308L;

/**
* Create an {@link UnAuthorisedServiceException} with a cause and a message.
* @param message exception message
*/
public UnAuthorisedServiceException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import uk.gov.hmcts.ecm.common.model.helper.TribunalOffice;

/**
* Defines attributes used by et-sya-api as constants.
*/
public final class EtSyaConstants {

public static final String REMOTE_REPO = "https://github.com/hmcts/et-sya-api";
Expand All @@ -17,6 +20,10 @@ public final class EtSyaConstants {

public static final String OTHER_TYPE_OF_DOCUMENT = "Other";

public static final String WELSH_LANGUAGE = "Welsh";
public static final String ENGLISH_LANGUAGE = "English";
public static final String WELSH_LANGUAGE_PARAM = "/?lng=cy";

private EtSyaConstants() {
// restrict instantiation
}
Expand Down
Loading

0 comments on commit 9087423

Please sign in to comment.