Skip to content

Commit

Permalink
MOSIP-32842 updated config
Browse files Browse the repository at this point in the history
Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr committed May 13, 2024
1 parent 4c5d00e commit 4542769
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

import io.mosip.pms.test.config.TestConfig;
import io.mosip.pms.test.config.TestSecurityConfig;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

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;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;

@Configuration
public class TestConfig {
Expand All @@ -26,15 +26,20 @@ public RestTemplate restTemplateConfig()

TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(acceptingTrustStrategy)
.build();

SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
var connnectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
connnectionManagerBuilder.setSSLSocketFactory(csf);
var connectionManager = connnectionManagerBuilder.build();
HttpClientBuilder httpClientBuilder = HttpClients.custom()
.setConnectionManager(connectionManager);

requestFactory.setHttpClient((HttpClient) httpClient);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClientBuilder.build());
return new RestTemplate(requestFactory);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand All @@ -17,6 +18,7 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.firewall.DefaultHttpFirewall;
import org.springframework.security.web.firewall.HttpFirewall;
@Configuration
Expand All @@ -30,11 +32,16 @@ public HttpFirewall defaultHttpFirewall() {
return new DefaultHttpFirewall();
}

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

@Bean
public WebSecurity configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().requestMatchers(allowedEndPoints());
webSecurity.httpFirewall(defaultHttpFirewall());
return webSecurity;
protected SecurityFilterChain configure(final HttpSecurity httpSecurity) throws Exception {
return httpSecurity.build();
}

private String[] allowedEndPoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package io.mosip.pms.policy.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.context.annotation.Import;

import io.mosip.pms.common.helper.FilterHelper;
Expand All @@ -20,7 +22,9 @@
*
*/
@Import(value = {WebSubPublisher.class,RestUtil.class,SearchHelper.class,FilterHelper.class,PageUtils.class,FilterColumnValidator.class,RestUtil.class})
@SpringBootApplication(scanBasePackages = { "io.mosip.pms.policy.*","io.mosip.pms.common.*"},exclude={DataSourceAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = { "io.mosip.*"},exclude={DataSourceAutoConfiguration.class})
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class })
public class PolicyServiceTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand All @@ -17,6 +18,7 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.firewall.DefaultHttpFirewall;
import org.springframework.security.web.firewall.HttpFirewall;

Expand All @@ -30,11 +32,16 @@ public HttpFirewall defaultHttpFirewall() {
return new DefaultHttpFirewall();
}

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

@Bean
public WebSecurity configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().requestMatchers(allowedEndPoints());
webSecurity.httpFirewall(defaultHttpFirewall());
return webSecurity;
protected SecurityFilterChain configure(final HttpSecurity httpSecurity) throws Exception {
return httpSecurity.build();
}

private String[] allowedEndPoints() {
Expand Down
5 changes: 5 additions & 0 deletions partner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down

0 comments on commit 4542769

Please sign in to comment.