spring-cloud-gateway

Getting Access Token with Spring Cloud Gateway and Spring Security with Keycloak

回眸只為那壹抹淺笑 提交于 2021-02-17 05:17:48
问题 I am using Spring cloud Gateway with Spring security and Keycloak for Access management. I am having an issue getting the access token with spring cloud gateway as the token I am getting doesn't have all the parameters like what I get from the token endpoint in keycloak. When I hit the keycloak token endpoint with all the details: http://localhost:8080/auth/realms/myrealm/protocol/openid-connect/token { "exp": 1595310135, "iat": 1595309835, "jti": "0a78d67c-878c-468c-8d03-e003af0350c3", "iss"

Forbid Unauthenticated requests in Spring Cloud Gateway

三世轮回 提交于 2021-02-08 16:37:34
问题 I have implemented custom pre filter in spring cloud gateway which allows authenticated requests to go through the downstream process. What I want is if the request is unauthenticated then return with response of 401 UNAUTHORIZE status and stop the downstream processing. Can I achieve this spring cloud gateway. Please help. My filter code is below public class ValidUserFilter implements GatewayFilterFactory { @Override public GatewayFilter apply(Object config) { return (exchange, chain) -> {

Spring Cloud Gateway - Proxy/Forward the entire sub part of URL

久未见 提交于 2021-02-06 15:15:42
问题 I am using Spring Cloud Gateway 2.0.0.M6 testing a simple gateway. I just want a URL to be forwarded to another URL with ** regex Example 1: /integration/sbl/foo/bar => localhost:4178/a-integration/sbl/foo/bar Example 2: /integration/sbl/baz/bad => localhost:4178/a-integration/sbl/baz/bad So far I have written the following, but it only forwards to http://localhost:4178/a-integration/ @Bean public RouteLocator routeLocator(RouteLocatorBuilder builder) { String test = "http://localhost:4178/a

Read the request body from ServerWebExchange Spring cloud gateway

陌路散爱 提交于 2021-01-29 12:45:15
问题 I am trying to read the request body data from ServerWebExchange in Spring Cloud Gateway. can anyone please help me how to do this. Also why this simple task is so difficult in reactive programming. 回答1: It's the same as reading or modifying the response body. see: ModifyRequestBodyGatewayFilterFactory and ModifyResponseBodyGatewayFilterFactory How to get response body in Spring Gateway 来源: https://stackoverflow.com/questions/64589858/read-the-request-body-from-serverwebexchange-spring-cloud

Spring Cloud Gateway Oauth2Login Return JWT Token Instead of SESSION Cookie Upon Successful Login

試著忘記壹切 提交于 2021-01-28 10:11:42
问题 sorry in advance if the question is previously asked, but I have not been able to find an answer. I am trying to setup Spring Cloud Gateway to act as a OAuth2 client to authenticate/login users via a Keycloak Authentication server. I have been able to achieve this using the following code snipet: Security Config: @Configuration @EnableWebFluxSecurity @EnableReactiveMethodSecurity public class SecurityConfig { private final GatewayAuthenticationSuccessHandler

Spring Cloud Gateway Oauth2Login Return JWT Token Instead of SESSION Cookie Upon Successful Login

自闭症网瘾萝莉.ら 提交于 2021-01-28 10:04:14
问题 sorry in advance if the question is previously asked, but I have not been able to find an answer. I am trying to setup Spring Cloud Gateway to act as a OAuth2 client to authenticate/login users via a Keycloak Authentication server. I have been able to achieve this using the following code snipet: Security Config: @Configuration @EnableWebFluxSecurity @EnableReactiveMethodSecurity public class SecurityConfig { private final GatewayAuthenticationSuccessHandler

Get request body string from ServerHttpRequest / Flux<DataBuffer>

主宰稳场 提交于 2021-01-27 11:46:05
问题 I am using spring boot version - 2.0.6.RELEASE and spring cloud version - Finchley.SR2 and i have created my custom gateway filter to modify the request body. but while converting the request body to string using Flux i am getting a empty string. i need a method to get the string corresponding to my request body. @Override public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = (ServerHttpRequest) exchange.getRequest(); String s =

Get request body string from ServerHttpRequest / Flux<DataBuffer>

纵饮孤独 提交于 2021-01-27 11:45:27
问题 I am using spring boot version - 2.0.6.RELEASE and spring cloud version - Finchley.SR2 and i have created my custom gateway filter to modify the request body. but while converting the request body to string using Flux i am getting a empty string. i need a method to get the string corresponding to my request body. @Override public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = (ServerHttpRequest) exchange.getRequest(); String s =

Spring cloud gateway gives connection closed prematurely

喜夏-厌秋 提交于 2021-01-27 05:45:10
问题 I am using spring cloud gateway as API gateway in my micro service setup with consul as service discovery. In some case when API of some microservice take more then 2 minutes, gateway throws below error: java.io.IOException: Connection closed prematurely at reactor.ipc.netty.http.client.HttpClientOperations.onInboundClose(HttpClientOperations.java:269) at reactor.ipc.netty.channel.ChannelOperationsHandler.channelInactive(ChannelOperationsHandler.java:113) at io.netty.channel

Spring cloud gateway gives connection closed prematurely

匆匆过客 提交于 2021-01-27 05:44:11
问题 I am using spring cloud gateway as API gateway in my micro service setup with consul as service discovery. In some case when API of some microservice take more then 2 minutes, gateway throws below error: java.io.IOException: Connection closed prematurely at reactor.ipc.netty.http.client.HttpClientOperations.onInboundClose(HttpClientOperations.java:269) at reactor.ipc.netty.channel.ChannelOperationsHandler.channelInactive(ChannelOperationsHandler.java:113) at io.netty.channel