Skip to content

Commit

Permalink
Merge branch 'informatici:develop' into integrations/orthanc
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 authored Dec 10, 2024
2 parents 0b4611b + 4377475 commit b92bc7b
Show file tree
Hide file tree
Showing 32 changed files with 213 additions and 224 deletions.
2 changes: 2 additions & 0 deletions rsc/application.properties.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ server.servlet.session.cookie.http-only=true
#server.servlet.session.cookie.secure=true # only over HTTPS
spring.pid.fail-on-write-error=true
spring.pid.file=OH_API_PID
spring.mustache.check-template-location=false
spring.jpa.open-in-view=false

### In production change to http://<domain>
cors.allowed.origins=http://API_HOST:API_PORT,http://UI_HOST:UI_PORT
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/org/isf/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
Expand All @@ -56,9 +54,6 @@
@EnableWebSecurity
public class SecurityConfig {

@Autowired
private UserDetailsService userDetailsService;

private final TokenProvider tokenProvider;

@Autowired
Expand All @@ -75,14 +70,6 @@ public SecurityConfig(TokenProvider tokenProvider, PermissionManager permissionM
@Autowired
private CustomLogoutHandler customLogoutHandler;

@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(encoder());
return authProvider;
}

@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/org/isf/security/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class TokenProvider implements Serializable {
@PostConstruct
public void init() {
String secret = env.getProperty("jwt.token.secret");
LOGGER.info("Initializing JWT key with secret: {}", secret);
LOGGER.debug("Initializing JWT key with secret: {}", secret);
byte[] keyBytes = secret.getBytes(StandardCharsets.UTF_8);
this.key = Keys.hmacShaKeyFor(keyBytes);

Expand Down Expand Up @@ -131,8 +131,8 @@ public Boolean isTokenExpired(String token) {

public String generateJwtToken(Authentication authentication, boolean rememberMe) {
final String authorities = authentication.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
.collect(Collectors.joining(","));
.map(GrantedAuthority::getAuthority)
.collect(Collectors.joining(","));

long now = System.currentTimeMillis();
Date validity;
Expand All @@ -143,21 +143,21 @@ public String generateJwtToken(Authentication authentication, boolean rememberMe
}

return Jwts.builder()
.setSubject(authentication.getName())
.claim(AUTHORITIES_KEY, authorities)
.setIssuedAt(new Date())
.signWith(key, SignatureAlgorithm.HS512)
.setExpiration(validity)
.compact();
.setSubject(authentication.getName())
.claim(AUTHORITIES_KEY, authorities)
.setIssuedAt(new Date())
.signWith(key, SignatureAlgorithm.HS512)
.setExpiration(validity)
.compact();
}

public String generateRefreshToken(Authentication authentication) {
return Jwts.builder()
.setSubject(authentication.getName())
.setIssuedAt(new Date())
.signWith(key, SignatureAlgorithm.HS512)
.setExpiration(new Date(System.currentTimeMillis() + this.tokenValidityInMillisecondsForRememberMe))
.compact();
.setSubject(authentication.getName())
.setIssuedAt(new Date())
.signWith(key, SignatureAlgorithm.HS512)
.setExpiration(new Date(System.currentTimeMillis() + this.tokenValidityInMillisecondsForRememberMe))
.compact();
}

public Authentication getAuthentication(String token) {
Expand All @@ -173,8 +173,8 @@ public Authentication getAuthentication(String token) {
}

final Collection< ? extends GrantedAuthority> authorities = Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());

User principal = new User(claims.getSubject(), "", authorities);

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/isf/OpenHospitalApiApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class OpenHospitalApiApplicationTests {
class OpenHospitalApiApplicationTests {

// @Test
// public void contextLoads() {
// void contextLoads() {
// /*
// * Context loading is working correctly. However, since this test does not provide any additional value and may actually slow down the tests execution,
// * it's recommended to remove it. The loading context is implicitly tested by other tests that run as SpringBootTest.
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/org/isf/accounting/rest/BillControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
/**
* @author Emerson Castaneda
*/
public class BillControllerTest extends ControllerBaseTest {
class BillControllerTest extends ControllerBaseTest {

private static final Logger LOGGER = LoggerFactory.getLogger(BillControllerTest.class);

Expand All @@ -122,7 +122,7 @@ public class BillControllerTest extends ControllerBaseTest {
private AutoCloseable closeable;

@BeforeEach
public void setup() {
void setup() {
closeable = MockitoAnnotations.openMocks(this);
this.mockMvc = MockMvcBuilders
.standaloneSetup(new BillController(billManagerMock, priceListManagerMock, patientManagerMock, billMapper, billItemsMapper, billPaymentsMapper))
Expand All @@ -147,7 +147,7 @@ void closeService() throws Exception {
}

@Test
public void when_post_bills_is_call_without_contentType_header_then_HttpMediaTypeNotSupportedException() throws Exception {
void when_post_bills_is_call_without_contentType_header_then_HttpMediaTypeNotSupportedException() throws Exception {
String request = "/bills";

MvcResult result = this.mockMvc
Expand All @@ -167,7 +167,7 @@ public void when_post_bills_is_call_without_contentType_header_then_HttpMediaTyp
}

@Test
public void when_post_bills_is_call_with_empty_body_then_BadRequest_HttpMessageNotReadableException() throws Exception {
void when_post_bills_is_call_with_empty_body_then_BadRequest_HttpMessageNotReadableException() throws Exception {
String request = "/bills";
String empty_body = "";

Expand All @@ -191,7 +191,7 @@ public void when_post_bills_is_call_with_empty_body_then_BadRequest_HttpMessageN
}

@Test
public void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception {
void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception {
String request = "/bills";
FullBillDTO newFullBillDTO = FullBillDTOHelper.setup(patientMapper, billItemsMapper, billPaymentsMapper);
Integer id = 0;
Expand Down Expand Up @@ -223,7 +223,7 @@ public void when_post_patients_PatientBrowserManager_getPatient_returns_null_the
}

@Test
public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception {
void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception {
Integer id = 123;
String request = "/bills/{id}";

Expand Down Expand Up @@ -256,7 +256,7 @@ public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OH
}

@Test
public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OK() throws Exception {
void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OK() throws Exception {
Integer id = 123;
String request = "/bills/{id}";
FullBillDTO newFullBillDTO = FullBillDTOHelper.setup(patientMapper, billItemsMapper, billPaymentsMapper);
Expand Down Expand Up @@ -309,7 +309,7 @@ public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OK
}

@Test
public void when_get_items_with_existent_id_then_getItems_returns_items_and_OK() throws Exception {
void when_get_items_with_existent_id_then_getItems_returns_items_and_OK() throws Exception {
Integer id = 123;
String request = "/bills/items/{bill_id}";

Expand All @@ -332,7 +332,7 @@ public void when_get_items_with_existent_id_then_getItems_returns_items_and_OK()
}

@Test
public void when_get_items_with_existent_id_then_getItems_is_empty_and_isNoContent() throws Exception {
void when_get_items_with_existent_id_then_getItems_is_empty_and_isNoContent() throws Exception {
Integer id = 123;
String request = "/bills/items/{bill_id}";

Expand All @@ -346,7 +346,7 @@ public void when_get_items_with_existent_id_then_getItems_is_empty_and_isNoConte
}

@Test
public void when_get_bill_with_existent_id_then_response_BillDTO_and_OK() throws Exception {
void when_get_bill_with_existent_id_then_response_BillDTO_and_OK() throws Exception {
int id = 123;
String request = "/bills/{id}";

Expand All @@ -367,7 +367,7 @@ public void when_get_bill_with_existent_id_then_response_BillDTO_and_OK() throws
}

@Test
public void when_delete_bill_with_existent_id_then_response_true_and_OK() throws Exception {
void when_delete_bill_with_existent_id_then_response_true_and_OK() throws Exception {
int id = 123;
String request = "/bills/{id}";

Expand All @@ -386,7 +386,7 @@ public void when_delete_bill_with_existent_id_then_response_true_and_OK() throws
}

@Test
public void when_get_bill_pending_affiliate_with_existent_patient_code_then_response_List_of_BillDTO_and_OK() throws Exception {
void when_get_bill_pending_affiliate_with_existent_patient_code_then_response_List_of_BillDTO_and_OK() throws Exception {
int code = 123;
String request = "/bills/pending/affiliate?patient_code={code}";

Expand All @@ -409,7 +409,7 @@ public void when_get_bill_pending_affiliate_with_existent_patient_code_then_resp
}

@Test
public void when_post_searchBillsByPayments_with_a_list_of_existent_billsPaymentsDTO_then_response_List_of_BillDTO_and_OK() throws Exception {
void when_post_searchBillsByPayments_with_a_list_of_existent_billsPaymentsDTO_then_response_List_of_BillDTO_and_OK() throws Exception {
String request = "/bills/search/by/payments";

List<BillPayments> billsPaymentsList = BillPaymentsDTOHelper.genListModel(2, billPaymentsMapper);
Expand All @@ -435,7 +435,7 @@ public void when_post_searchBillsByPayments_with_a_list_of_existent_billsPayment
}

@Test
public void when_get_pendingBills_with_existent_patient_code_then_response_List_of_BillDTO_and_OK() throws Exception {
void when_get_pendingBills_with_existent_patient_code_then_response_List_of_BillDTO_and_OK() throws Exception {
int code = 123;
String request = "/bills/pending?patient_code={code}";

Expand All @@ -461,7 +461,7 @@ public void when_get_pendingBills_with_existent_patient_code_then_response_List_
}

@Test
public void when_post_searchBillsByItem_with_valid_dates_and_billItemsDTO_content_and_PatientBrowserManager_getBills_returns_billList_then_OK()
void when_post_searchBillsByItem_with_valid_dates_and_billItemsDTO_content_and_PatientBrowserManager_getBills_returns_billList_then_OK()
throws Exception {
String request = "/bills/search/by/item?datefrom={dateFrom}&dateto={dateTo}";
String dateFrom = LocalDateTime.now().format(DateTimeFormatter.ofPattern(Constants.DATE_FORMAT_YYYY_MM_DD_T_HH_MM_SS_SSS_Z));
Expand Down Expand Up @@ -494,7 +494,7 @@ public void when_post_searchBillsByItem_with_valid_dates_and_billItemsDTO_conten
}

@Test
public void when_get_searchBills_with_valid_dates_and_valid_patient_code_and_PatientBrowserManager_getBills_returns_billList_then_OK() throws Exception {
void when_get_searchBills_with_valid_dates_and_valid_patient_code_and_PatientBrowserManager_getBills_returns_billList_then_OK() throws Exception {
String request = "/bills?datefrom={dateFrom}&dateto={dateTo}&patient_code={patient_code}";
String dateFrom = LocalDateTime.now().format(DateTimeFormatter.ofPattern(Constants.DATE_FORMAT_YYYY_MM_DD_T_HH_MM_SS_SSS_Z));
String dateTo = LocalDateTime.now().format(DateTimeFormatter.ofPattern(Constants.DATE_FORMAT_YYYY_MM_DD_T_HH_MM_SS_SSS_Z));
Expand Down Expand Up @@ -524,7 +524,7 @@ public void when_get_searchBills_with_valid_dates_and_valid_patient_code_and_Pat
}

@Test
public void when_get_getDistinctItems_BillBrowserManager_getDistinctItems_returns_BillItemsDTOList_then_OK() throws Exception {
void when_get_getDistinctItems_BillBrowserManager_getDistinctItems_returns_BillItemsDTOList_then_OK() throws Exception {
String request = "/bills/items";

//TODO move to a Helper once it duplicates somewhere else
Expand Down Expand Up @@ -553,7 +553,7 @@ public void when_get_getDistinctItems_BillBrowserManager_getDistinctItems_return
}

@Test
public void when_get_getPaymentsByBillId_with_valid_bill_id_and_BillBrowserManager_getPayments_returns_BillPaymentsList_then_OK() throws Exception {
void when_get_getPaymentsByBillId_with_valid_bill_id_and_BillBrowserManager_getPayments_returns_BillPaymentsList_then_OK() throws Exception {
String request = "/bills/payments/{bill_id}";

int billId = 123;
Expand Down
Loading

0 comments on commit b92bc7b

Please sign in to comment.