Skip to content

Commit

Permalink
Added config to run towards mock
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhaugsdal committed Aug 18, 2024
1 parent ab4a3dd commit ea312df
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 182 deletions.
4 changes: 3 additions & 1 deletion mock-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@
<configuration>
<image>
<name>${project.artifactId}:latest</name>
<!-- <network>host</network>-->
<builder>paketobuildpacks/builder-jammy-tiny:latest</builder>
<runImage>paketobuildpacks/run-jammy-tiny:latest</runImage>
<env>
<BP_JVM_VERSION>21</BP_JVM_VERSION>
</env>
</image>
<docker>
<host>//./pipe/dockerDesktopLinuxEngine</host>
</docker>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,133 +26,140 @@
@Profile("default")
public class RestTestConfiguration {

static {
System.setProperty("rest.na.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort() + "/v2");
System.setProperty("rest.rekvirent.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort()+ "/v2");
System.setProperty("rest.utleverer.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort()+ "/v2");
}

@Value("${rest.na.address}")
String naAddress;

@Value("${rest.rekvirent.address}")
String rekvirentAddress;

@Value("${rest.utleverer.address}")
String utlevererAddress;

@Value("${use.jwk}")
String jwk;


@Bean
public Server naServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(NaWebServiceImpl.class);
serverFactoryBean.setAddress(naAddress + "/" + "NA");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}
@TestConfiguration
@Profile("default")
public static class DefaultConfiguration {
static {
System.setProperty("rest.na.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort() + "/v2");
System.setProperty("rest.rekvirent.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort()+ "/v2");
System.setProperty("rest.utleverer.address", "http://localhost:" + TestSocketUtils.findAvailableTcpPort()+ "/v2");
}

@Bean
public Server utlevererServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(UtlevererWebServiceImpl.class);
serverFactoryBean.setAddress(utlevererAddress + "/" + "Utleverer");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}
@Value("${rest.na.address}")
String naAddress;

@Value("${rest.rekvirent.address}")
String rekvirentAddress;

@Bean
public Server rekvirentServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(RekvirentWebServiceImpl.class);
serverFactoryBean.setAddress(rekvirentAddress + "/" + "Rekvirent");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}
@Value("${rest.utleverer.address}")
String utlevererAddress;

private static void commonSetup(JAXRSServerFactoryBean serverFactoryBean, String jwk) {
var loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
serverFactoryBean.getFeatures().add(loggingFeature);
@Value("${use.jwk}")
String jwk;

List<Object> providers = new LinkedList<>();
providers.add("com.fasterxml.jackson.jaxrs.xml.JacksonJaxbXMLProvider");

var jweContainerRequestFilter = new JweContainerRequestFilter();
var jwsContainerRequestFilter = new JwsContainerRequestFilter();
@Bean
public Server naServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(NaWebServiceImpl.class);
serverFactoryBean.setAddress(naAddress + "/" + "NA");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}

Properties properties = new Properties();
try {
properties.load(RestTestConfiguration.class.getClassLoader().getResourceAsStream("server/server.properties"));
} catch (IOException e) {
e.printStackTrace();
@Bean
public Server utlevererServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(UtlevererWebServiceImpl.class);
serverFactoryBean.setAddress(utlevererAddress + "/" + "Utleverer");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}

var jweWriterInterceptor = new JweWriterInterceptor();
jweWriterInterceptor.setUseJweOutputStream(true);

var jwsWriterInterceptor = new JwsWriterInterceptor();
jwsWriterInterceptor.setUseJwsOutputStream(true);

providers.add(jweContainerRequestFilter);
providers.add(jwsContainerRequestFilter);
providers.add(jweWriterInterceptor);
providers.add(jwsWriterInterceptor);

serverFactoryBean.setProviders(providers);

if (Boolean.parseBoolean(jwk)) {
//ENCRYPTION properties
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.in.properties",
"server/jwk/server.properties"
);
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.out.properties",
"server/jwk/server-out.properties"
);
//SIGNATURE IN
serverFactoryBean.getProperties(true).put(
"rs.security.signature.in.properties",
"server/jwk/server-sign.properties"
);
//SIGNATURE OUT
serverFactoryBean.getProperties(true).put(
"rs.security.signature.out.properties",
"server/jwk/server-out-sign.properties"
);

serverFactoryBean.getProperties(true).put("rs.security.accept.public.key", "true");
serverFactoryBean.getProperties(true).put("rs.security.signature.include.public.key", "true");
} else {
//ENCRYPTION properties
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.in.properties",
"server/server.properties"
);
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.out.properties",
"server/server-out.properties"
);
//SIGNATURE IN
serverFactoryBean.getProperties(true).put(
"rs.security.signature.in.properties",
"server/server-sign.properties"
);
//SIGNATURE OUT
serverFactoryBean.getProperties(true).put(
"rs.security.signature.out.properties",
"server/server-out-sign.properties"
);
serverFactoryBean.getProperties(true).put("rs.security.signature.include.cert", "true");

@Bean
public Server rekvirentServer() {
var serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setServiceClass(RekvirentWebServiceImpl.class);
serverFactoryBean.setAddress(rekvirentAddress + "/" + "Rekvirent");
commonSetup(serverFactoryBean, jwk);
return serverFactoryBean.create();
}

serverFactoryBean.getProperties(true).put("jose.debug", true);
private static void commonSetup(JAXRSServerFactoryBean serverFactoryBean, String jwk) {
var loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
serverFactoryBean.getFeatures().add(loggingFeature);

List<Object> providers = new LinkedList<>();
providers.add("com.fasterxml.jackson.jaxrs.xml.JacksonJaxbXMLProvider");

var jweContainerRequestFilter = new JweContainerRequestFilter();
var jwsContainerRequestFilter = new JwsContainerRequestFilter();

Properties properties = new Properties();
try {
properties.load(RestTestConfiguration.class.getClassLoader().getResourceAsStream("server/server.properties"));
} catch (IOException e) {
e.printStackTrace();
}

var jweWriterInterceptor = new JweWriterInterceptor();
jweWriterInterceptor.setUseJweOutputStream(true);

var jwsWriterInterceptor = new JwsWriterInterceptor();
jwsWriterInterceptor.setUseJwsOutputStream(true);

providers.add(jweContainerRequestFilter);
providers.add(jwsContainerRequestFilter);
providers.add(jweWriterInterceptor);
providers.add(jwsWriterInterceptor);

serverFactoryBean.setProviders(providers);

if (Boolean.parseBoolean(jwk)) {
//ENCRYPTION properties
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.in.properties",
"server/jwk/server.properties"
);
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.out.properties",
"server/jwk/server-out.properties"
);
//SIGNATURE IN
serverFactoryBean.getProperties(true).put(
"rs.security.signature.in.properties",
"server/jwk/server-sign.properties"
);
//SIGNATURE OUT
serverFactoryBean.getProperties(true).put(
"rs.security.signature.out.properties",
"server/jwk/server-out-sign.properties"
);

serverFactoryBean.getProperties(true).put("rs.security.accept.public.key", "true");
serverFactoryBean.getProperties(true).put("rs.security.signature.include.public.key", "true");
} else {
//ENCRYPTION properties
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.in.properties",
"server/server.properties"
);
serverFactoryBean.getProperties(true).put(
"rs.security.encryption.out.properties",
"server/server-out.properties"
);
//SIGNATURE IN
serverFactoryBean.getProperties(true).put(
"rs.security.signature.in.properties",
"server/server-sign.properties"
);
//SIGNATURE OUT
serverFactoryBean.getProperties(true).put(
"rs.security.signature.out.properties",
"server/server-out-sign.properties"
);
serverFactoryBean.getProperties(true).put("rs.security.signature.include.cert", "true");
}

serverFactoryBean.getProperties(true).put("jose.debug", true);

}
}
@TestConfiguration
@Profile("local")
public static class LocalConfiguration {


}
}
Loading

0 comments on commit ea312df

Please sign in to comment.