|
@@ -1,14 +1,13 @@
|
|
|
package es.uv.garcosda.gateway.security;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
|
|
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
-import org.springframework.web.reactive.function.client.WebClientResponseException;
|
|
|
|
|
|
import com.google.common.net.HttpHeaders;
|
|
|
|
|
@@ -20,6 +19,9 @@ public class AuthFilter extends AbstractGatewayFilterFactory<AuthFilter.Config>
|
|
|
@Autowired
|
|
|
private WebClient.Builder client;
|
|
|
|
|
|
+ @Value("${mailer.auth.url}")
|
|
|
+ private String auth_url;
|
|
|
+
|
|
|
public AuthFilter() {
|
|
|
super(Config.class);
|
|
|
}
|
|
@@ -46,7 +48,7 @@ public class AuthFilter extends AbstractGatewayFilterFactory<AuthFilter.Config>
|
|
|
try {
|
|
|
return client.build()
|
|
|
.get()
|
|
|
- .uri("http://auth-service/auth/authorize")
|
|
|
+ .uri(auth_url+"/auth/authorize")
|
|
|
.header(HttpHeaders.AUTHORIZATION, authHeader)
|
|
|
.retrieve()
|
|
|
.onStatus(httpStatus -> httpStatus.value() != HttpStatus.ACCEPTED.value(),
|
|
@@ -56,7 +58,10 @@ public class AuthFilter extends AbstractGatewayFilterFactory<AuthFilter.Config>
|
|
|
if(entity.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
|
|
|
response.setStatusCode(HttpStatus.UNAUTHORIZED);
|
|
|
return response.setComplete();
|
|
|
- }
|
|
|
+ }
|
|
|
+ exchange.getRequest()
|
|
|
+ .mutate()
|
|
|
+ .header("x-auth-user-id", entity.getBody());
|
|
|
return chain.filter(exchange);
|
|
|
});
|
|
|
}
|