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