Skip to content

Commit

Permalink
MOSIP-32842 build issue fixed
Browse files Browse the repository at this point in the history
Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr committed May 7, 2024
1 parent c8fe75a commit 350c64f
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ public class PartnerServiceResponseExceptionHandler extends ResponseEntityExcept
String msg = "mosip.partnermanagement";
String version = "1.0";

@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
HttpHeaders headers, HttpStatus status, WebRequest request) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("id", null);
body.put("version", null);
body.put("metadata", null);
body.put("response", null);
body.put("responsetime", LocalDateTime.now(ZoneId.of("UTC")));
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
FieldError fieldError = fieldErrors.get(0);
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorCode(ErrorCode.MISSING_PARTNER_INPUT_PARAMETER.getErrorCode());
errorResponse.setMessage("Invalid request parameter - " + fieldError.getDefaultMessage() + " :" + fieldError.getField());
List<ErrorResponse> errors = new ArrayList<>();
errors.add(errorResponse);
body.put("errors", errors);
return new ResponseEntity<>(body, headers, HttpStatus.OK);
}
// @Override
// protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
// HttpHeaders headers, HttpStatus status, WebRequest request) {
// Map<String, Object> body = new LinkedHashMap<>();
// body.put("id", null);
// body.put("version", null);
// body.put("metadata", null);
// body.put("response", null);
// body.put("responsetime", LocalDateTime.now(ZoneId.of("UTC")));
// List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
// FieldError fieldError = fieldErrors.get(0);
//
// ErrorResponse errorResponse = new ErrorResponse();
// errorResponse.setErrorCode(ErrorCode.MISSING_PARTNER_INPUT_PARAMETER.getErrorCode());
// errorResponse.setMessage("Invalid request parameter - " + fieldError.getDefaultMessage() + " :" + fieldError.getField());
// List<ErrorResponse> errors = new ArrayList<>();
// errors.add(errorResponse);
// body.put("errors", errors);
// return new ResponseEntity<>(body, headers, HttpStatus.OK);
// }

@ExceptionHandler(MISPServiceException.class)
public ResponseEntity<ResponseWrapper<ErrorResponse>> getExcepionMassages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.net.ssl.SSLContext;

import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
Expand All @@ -33,7 +34,7 @@ public RestTemplate restTemplateConfig()
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
requestFactory.setHttpClient((HttpClient) httpClient);
return new RestTemplate(requestFactory);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -24,33 +21,33 @@
import org.springframework.security.web.firewall.HttpFirewall;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class TestSecurityConfig extends WebSecurityConfigurerAdapter {
@EnableMethodSecurity
public class TestSecurityConfig {


@Bean
public HttpFirewall defaultHttpFirewall() {
return new DefaultHttpFirewall();
}

@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers(allowedEndPoints());
super.configure(webSecurity);
@Bean
public WebSecurity configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().requestMatchers(allowedEndPoints());
webSecurity.httpFirewall(defaultHttpFirewall());
return webSecurity;
}

private String[] allowedEndPoints() {
return new String[] { "*","/swagger-ui.html" };
}

@Override
protected void configure(final HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable();
httpSecurity.httpBasic().and().authorizeRequests().anyRequest().authenticated().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
.authenticationEntryPoint(unauthorizedEntryPoint());
}
// @Bean
// protected void configure(final HttpSecurity httpSecurity) throws Exception {
// httpSecurity.csrf(httpEntry -> httpEntry.disable());
// httpSecurity.httpBasic().and().authorizeRequests().anyRequest().authenticated().and().sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
// .authenticationEntryPoint(unauthorizedEntryPoint());
// }

@Bean
public AuthenticationEntryPoint unauthorizedEntryPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import java.util.stream.Collectors;

import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import java.util.*;
import java.util.stream.Collectors;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import io.mosip.kernel.core.exception.ServiceError;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public RestTemplate getRestTemplate() throws KeyManagementException, NoSuchAlgor
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setHttpClient((org.apache.hc.client5.http.classic.HttpClient) httpClient);
return new RestTemplate(requestFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
@Autowired
private ObjectMapper objectMapper;

/**
* Exception to be thrown when validation on an argument annotated with {@code @Valid} fails.
*
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers,
HttpStatus status, WebRequest request) {
ExceptionUtils.logRootCause(ex);
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
FieldError fieldError = fieldErrors.get(0);
ServiceError serviceError = new ServiceError(ErrorMessages.MISSING_INPUT_PARAMETER.getErrorCode(),
"Invalid request parameter - " + fieldError.getDefaultMessage() + " :" + fieldError.getField());
ResponseWrapper<ServiceError> errorResponse = null;
try {
errorResponse = setErrors(request);
errorResponse.getErrors().add(serviceError);
} catch (IOException e) {
//
}
return new ResponseEntity<>(errorResponse, HttpStatus.OK);
}
// /**
// * Exception to be thrown when validation on an argument annotated with {@code @Valid} fails.
// *
// */
// @Override
// protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers,
// HttpStatus status, WebRequest request) {
// ExceptionUtils.logRootCause(ex);
// List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
// FieldError fieldError = fieldErrors.get(0);
// ServiceError serviceError = new ServiceError(ErrorMessages.MISSING_INPUT_PARAMETER.getErrorCode(),
// "Invalid request parameter - " + fieldError.getDefaultMessage() + " :" + fieldError.getField());
// ResponseWrapper<ServiceError> errorResponse = null;
// try {
// errorResponse = setErrors(request);
// errorResponse.getErrors().add(serviceError);
// } catch (IOException e) {
// //
// }
// return new ResponseEntity<>(errorResponse, HttpStatus.OK);
// }

/**
* Exception to be thrown when misp application validations failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -25,32 +22,32 @@

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class TestSecurityConfig extends WebSecurityConfigurerAdapter {
@EnableMethodSecurity
public class TestSecurityConfig {

@Bean
public HttpFirewall defaultHttpFirewall() {
return new DefaultHttpFirewall();
}

@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers(allowedEndPoints());
super.configure(webSecurity);
@Bean
public WebSecurity configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().requestMatchers(allowedEndPoints());
webSecurity.httpFirewall(defaultHttpFirewall());
return webSecurity;
}

private String[] allowedEndPoints() {
return new String[] { "/policies/**/**","**","/swagger-ui.html" };
}

@Override
protected void configure(final HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable();
httpSecurity.httpBasic().and().authorizeRequests().anyRequest().authenticated().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
.authenticationEntryPoint(unauthorizedEntryPoint());
}
// @Bean
// protected SecurityFilterChain configure(final HttpSecurity httpSecurity) throws Exception {
// httpSecurity.csrf(httpEntry -> httpEntry.disable();
// httpSecurity.httpBasic().and().authorizeRequests().anyRequest().authenticated().and().sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
// .authenticationEntryPoint(unauthorizedEntryPoint());
// }

@Bean
public AuthenticationEntryPoint unauthorizedEntryPoint() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.mosip.pms.policy.validator.constants;

import lombok.Getter;

@Getter
public enum PolicyValidatorErrorConstant {
SCHEMA_IO_EXCEPTION("PMS_PV_001", "Failed to read schema"),

Expand All @@ -13,9 +16,21 @@ public enum PolicyValidatorErrorConstant {

MISSING_INPUT_PARAMETER("PMS_PV_006", "Missing input parameter - %s in policy data");

private final String errorCode;

private final String message;
/**
* -- GETTER --
* Gets the error code.
*
* @return the error code
*/
private final String errorCode;

/**
* -- GETTER --
* Gets the message.
*
* @return the message
*/
private final String message;

/**
* Instantiates a new json validator error constant.
Expand All @@ -28,22 +43,4 @@ public enum PolicyValidatorErrorConstant {
this.message = message;
}

/**
* Gets the error code.
*
* @return the error code
*/
public String getErrorCode() {
return errorCode;
}

/**
* Gets the message.
*
* @return the message
*/
public String getMessage() {
return message;
}

}
4 changes: 2 additions & 2 deletions partner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
<maven.war.plugin.version>3.1.0</maven.war.plugin.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.version>3.9.6</maven.compiler.version>
<maven.compiler.version>3.13.0</maven.compiler.version>
<junit.version>4.12</junit.version>
<lombok.version>1.18.8</lombok.version>
<lombok.version>1.18.32</lombok.version>
<doclint>none</doclint>
<maven.surefire.plugin.version>2.22.0</maven.surefire.plugin.version>
<maven.jacoco.version>0.8.5</maven.jacoco.version>
Expand Down

0 comments on commit 350c64f

Please sign in to comment.