Skip to content
Snippets Groups Projects
Commit 7f2aef30 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Fix docker url

parent 988f0306
No related branches found
No related tags found
1 merge request!44fixed ConfidentialClientApplication
Pipeline #
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/confidentialClient-0.0.1-SNAPSHOT.jar /app.jar
ENV DOCKER_RUNNING=true
ENTRYPOINT ["java", "-jar", "/app.jar"]
\ No newline at end of file
package org.fuseri.confidentialclient;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.fuseri.model.dto.user.UserCreateDto;
import org.fuseri.model.dto.user.UserDto;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
......@@ -18,8 +14,8 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
......@@ -30,10 +26,6 @@ public class ConfidentialClientApplication {
SpringApplication.run(ConfidentialClientApplication.class, args);
}
private static String asJsonString(final Object obj) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(obj);
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
......@@ -46,17 +38,15 @@ public class ConfidentialClientApplication {
.oauth2Login(x -> x
// our custom handler for successful logins
.successHandler(authenticationSuccessHandler())
)
;
);
return httpSecurity.build();
}
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
return new SavedRequestAwareAuthenticationSuccessHandler() {
@Override
public void onAuthenticationSuccess(HttpServletRequest req, HttpServletResponse res, Authentication auth) throws ServletException, IOException {
if (auth instanceof OAuth2AuthenticationToken token
&& token.getPrincipal() instanceof OidcUser user) {
var createDto = new UserCreateDto();
......@@ -65,15 +55,13 @@ public class ConfidentialClientApplication {
createDto.setEmail(user.getEmail());
createDto.setUsername(user.getPreferredUsername());
var result = WebClient.builder().baseUrl("http://localhost:8081/users/register").build().post()
.contentType(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(createDto))
.retrieve();
String url = buildRegisterUrl();
RestTemplate userRegisterRestTemplate = new RestTemplate();
try {
result.bodyToMono(UserDto.class).block();
} catch (Exception e) {
System.out.println("unable to save user");
userRegisterRestTemplate.postForObject(url, createDto, UserCreateDto.class);
} catch (RestClientException e) {
throw new ServletException("Unable to register user" + System.getenv("DOCKER_RUNNING"), e);
}
}
super.onAuthenticationSuccess(req, res, auth);
......@@ -81,6 +69,9 @@ public class ConfidentialClientApplication {
};
}
private static String buildRegisterUrl() {
boolean dockerRunning = Boolean.parseBoolean(System.getenv("DOCKER_RUNNING"));
String host = dockerRunning ? "host.docker.internal" : "localhost";
return "http://" + host + ":8081/users/register";
}
}
......@@ -10,6 +10,8 @@ services:
image: xpokorn8/sprachschulsystem:certificate
ports:
- "8082:8082"
environment:
- DOCKER_RUNNING=true
exercise:
build: ./module-exercise
......@@ -17,6 +19,8 @@ services:
image: xpokorn8/sprachschulsystem:exercise
ports:
- "8083:8083"
environment:
- DOCKER_RUNNING=true
language-school:
build: ./module-language-school
......@@ -24,6 +28,8 @@ services:
image: xpokorn8/sprachschulsystem:language-school
ports:
- "8081:8081"
environment:
- DOCKER_RUNNING=true
mail:
build: ./module-mail
......@@ -31,11 +37,15 @@ services:
image: xpokorn8/sprachschulsystem:mail
ports:
- "8084:8084"
environment:
- DOCKER_RUNNING=true
confidential-client:
build: ./confidentialClient
container_name: confidential-client
image: xpokorn8/sprachschulsystem:confidential-client
environment:
- DOCKER_RUNNING=true
ports:
- "8080:8080"
......@@ -45,6 +55,8 @@ services:
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
environment:
- DOCKER_RUNNING=true
expose:
- 9090
ports:
......@@ -56,6 +68,8 @@ services:
image: grafana/grafana:7.5.7
ports:
- "3000:3000"
environment:
- DOCKER_RUNNING=true
restart: unless-stopped
volumes:
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
......
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-certificate-0.0.1-SNAPSHOT.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
ENV DOCKER_RUNNING=true
ENTRYPOINT ["java", "-jar", "/app.jar"]
\ No newline at end of file
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-exercise-0.0.1-SNAPSHOT.jar /app.jar
ENV DOCKER_RUNNING=true
ENTRYPOINT ["java", "-jar", "/app.jar"]
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-language-school-0.0.1-SNAPSHOT.jar /app.jar
ENV DOCKER_RUNNING=true
ENTRYPOINT ["java", "-jar", "/app.jar"]
FROM docker.io/library/eclipse-temurin:17-jre-focal
COPY ./target/module-mail-0.0.1-SNAPSHOT.jar /app.jar
ENV DOCKER_RUNNING=true
ENTRYPOINT ["java", "-jar", "/app.jar"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment