-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Showing
13 changed files
with
829 additions
and
606 deletions.
There are no files selected for viewing
593 changes: 303 additions & 290 deletions
593
..._soft/springaddons/security/oidc/starter/properties/SpringAddonsOidcClientProperties.java
Large diffs are not rendered by default.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...rity/oidc/starter/properties/condition/bean/DefaultAuthenticationEntryPointCondition.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,21 @@ | ||
package com.c4_soft.springaddons.security.oidc.starter.properties.condition.bean; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.NoneNestedConditions; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.security.web.server.ServerAuthenticationEntryPoint; | ||
|
||
public class DefaultAuthenticationEntryPointCondition extends NoneNestedConditions { | ||
|
||
public DefaultAuthenticationEntryPointCondition() { | ||
super(ConfigurationPhase.REGISTER_BEAN); | ||
} | ||
|
||
@ConditionalOnBean(AuthenticationEntryPoint.class) | ||
static class AuthenticationEntryPointCondition { | ||
} | ||
|
||
@ConditionalOnBean(ServerAuthenticationEntryPoint.class) | ||
static class ServerAuthenticationEntryPointCondition { | ||
} | ||
} |
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
177 changes: 90 additions & 87 deletions
177
...s/security/oidc/starter/reactive/client/ReactiveSpringAddonsOidcClientWithLoginBeans.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
42 changes: 42 additions & 0 deletions
42
...ons/security/oidc/starter/reactive/client/SpringAddonsServerAuthenticationEntryPoint.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,42 @@ | ||
package com.c4_soft.springaddons.security.oidc.starter.reactive.client; | ||
|
||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.server.ServerAuthenticationEntryPoint; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import com.c4_soft.springaddons.security.oidc.starter.properties.SpringAddonsOidcClientProperties; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Slf4j | ||
public class SpringAddonsServerAuthenticationEntryPoint implements ServerAuthenticationEntryPoint { | ||
private final SpringAddonsOidcClientProperties clientProperties; | ||
|
||
public SpringAddonsServerAuthenticationEntryPoint(SpringAddonsOidcClientProperties addonsProperties) { | ||
this.clientProperties = addonsProperties; | ||
} | ||
|
||
@Override | ||
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) { | ||
final var location = clientProperties.getLoginUri().orElse( | ||
UriComponentsBuilder.fromUri(clientProperties.getClientUri()).pathSegment(clientProperties.getClientUri().getPath(), "/login").build().toUri()) | ||
.toString(); | ||
log.debug("Status: {}, location: {}", clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().value(), location); | ||
|
||
final var response = exchange.getResponse(); | ||
response.setStatusCode(clientProperties.getOauth2Redirections().getAuthenticationEntryPoint()); | ||
response.getHeaders().add(HttpHeaders.LOCATION, location.toString()); | ||
|
||
if (clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().is4xxClientError() | ||
|| clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().is5xxServerError()) { | ||
final var buffer = response.bufferFactory().wrap("Unauthorized. Please authenticate at %s".formatted(location.toString()).getBytes()); | ||
return response.writeWith(Flux.just(buffer)); | ||
} | ||
|
||
return response.setComplete(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ddons/security/oidc/starter/synchronised/client/SpringAddonsAuthenticationEntryPoint.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,43 @@ | ||
package com.c4_soft.springaddons.security.oidc.starter.synchronised.client; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import com.c4_soft.springaddons.security.oidc.starter.properties.SpringAddonsOidcClientProperties; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class SpringAddonsAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
private final SpringAddonsOidcClientProperties clientProperties; | ||
|
||
public SpringAddonsAuthenticationEntryPoint(SpringAddonsOidcClientProperties addonsProperties) { | ||
this.clientProperties = addonsProperties; | ||
} | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { | ||
final var location = clientProperties.getLoginUri().orElse( | ||
UriComponentsBuilder.fromUri(clientProperties.getClientUri()).pathSegment(clientProperties.getClientUri().getPath(), "/login").build().toUri()) | ||
.toString(); | ||
log.debug("Status: {}, location: {}", clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().value(), location); | ||
|
||
response.setStatus(clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().value()); | ||
response.setHeader(HttpHeaders.LOCATION, location.toString()); | ||
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "OAuth realm=\"Restricted Content\""); | ||
|
||
if (clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().is4xxClientError() | ||
|| clientProperties.getOauth2Redirections().getAuthenticationEntryPoint().is5xxServerError()) { | ||
response.getOutputStream().write("Unauthorized. Please authenticate at %s".formatted(location.toString()).getBytes()); | ||
} | ||
|
||
response.flushBuffer(); | ||
} | ||
} |
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
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
Oops, something went wrong.