-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3ffb45
commit 7c63d0a
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...c/main/java/org/opendatadiscovery/oddplatform/auth/logout/ODDIAMLogoutSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.opendatadiscovery.oddplatform.auth.logout; | ||
|
||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.auth.ODDOAuth2Properties; | ||
import org.opendatadiscovery.oddplatform.auth.Provider; | ||
import org.opendatadiscovery.oddplatform.auth.condition.ODDIAMCondition; | ||
import org.opendatadiscovery.oddplatform.auth.util.UriUtils; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.server.reactive.ServerHttpResponse; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.server.WebFilterExchange; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.server.WebSession; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
@Conditional(ODDIAMCondition.class) | ||
@RequiredArgsConstructor | ||
public class ODDIAMLogoutSuccessHandler implements LogoutSuccessHandler { | ||
@Override | ||
public boolean shouldHandle(final String provider) { | ||
return provider.equalsIgnoreCase(Provider.ODD_IAM.name()); | ||
} | ||
|
||
@Override | ||
public Mono<Void> handle(final WebFilterExchange exchange, | ||
final Authentication authentication, | ||
final ODDOAuth2Properties.OAuth2Provider provider) { | ||
final ServerHttpResponse response = exchange.getExchange().getResponse(); | ||
response.setStatusCode(HttpStatus.FOUND); | ||
final var requestUri = exchange.getExchange().getRequest().getURI(); | ||
|
||
final var uri = UriComponentsBuilder | ||
.fromUri(URI.create(String.format("%s/oauth2/logout", provider.getIssuerUri()))) | ||
.queryParam("logout_uri", UriUtils.getBaseUri(requestUri)) | ||
.encode(StandardCharsets.UTF_8) | ||
.build() | ||
.toUri(); | ||
|
||
response.getHeaders().setLocation(uri); | ||
return exchange.getExchange().getSession().flatMap(WebSession::invalidate); | ||
} | ||
} |