-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix AuthenticationRedirectEx. handling with disabled proactive security
- Loading branch information
1 parent
6ae8ff8
commit f5a6fa4
Showing
11 changed files
with
226 additions
and
96 deletions.
There are no files selected for viewing
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
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
97 changes: 97 additions & 0 deletions
97
...kus/resteasy/reactive/server/test/security/AuthenticationRedirectExceptionMapperTest.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,97 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import static org.jboss.resteasy.reactive.RestResponse.StatusCode.FOUND; | ||
|
||
import java.util.Set; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.AuthenticationRedirectException; | ||
import io.quarkus.security.identity.AuthenticationRequestContext; | ||
import io.quarkus.security.identity.IdentityProvider; | ||
import io.quarkus.security.identity.IdentityProviderManager; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.quarkus.security.identity.request.AuthenticationRequest; | ||
import io.quarkus.security.identity.request.BaseAuthenticationRequest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.http.runtime.security.ChallengeData; | ||
import io.quarkus.vertx.http.runtime.security.HttpAuthenticationMechanism; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class AuthenticationRedirectExceptionMapperTest { | ||
|
||
private static final int EXPECTED_STATUS = 409; | ||
private static final String APP_PROPS = "" + | ||
"quarkus.http.auth.proactive=false\n" + | ||
"quarkus.http.auth.permission.default.paths=/*\n" + | ||
"quarkus.http.auth.permission.default.policy=authenticated"; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset(APP_PROPS), "application.properties")); | ||
|
||
@Test | ||
public void testAuthenticationRedirectExceptionMapper() { | ||
RestAssured | ||
.given() | ||
.redirects() | ||
.follow(false) | ||
.when() | ||
.get("/secured-route") | ||
.then() | ||
.statusCode(EXPECTED_STATUS); | ||
} | ||
|
||
public static final class AuthenticationRedirectExceptionMapper { | ||
|
||
@ServerExceptionMapper(AuthenticationRedirectException.class) | ||
public Response authenticationRedirectException() { | ||
return Response.status(EXPECTED_STATUS).build(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class RedirectingAuthenticator implements HttpAuthenticationMechanism { | ||
|
||
@Override | ||
public Uni<SecurityIdentity> authenticate(RoutingContext context, IdentityProviderManager identityProviderManager) { | ||
throw new AuthenticationRedirectException(FOUND, "https://quarkus.io/"); | ||
} | ||
|
||
@Override | ||
public Set<Class<? extends AuthenticationRequest>> getCredentialTypes() { | ||
return Set.of(BaseAuthenticationRequest.class); | ||
} | ||
|
||
@Override | ||
public Uni<ChallengeData> getChallenge(RoutingContext context) { | ||
return Uni.createFrom().item(new ChallengeData(FOUND, "header-name", "header-value")); | ||
} | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class BasicIdentityProvider implements IdentityProvider<BaseAuthenticationRequest> { | ||
|
||
@Override | ||
public Class<BaseAuthenticationRequest> getRequestType() { | ||
return BaseAuthenticationRequest.class; | ||
} | ||
|
||
@Override | ||
public Uni<SecurityIdentity> authenticate( | ||
BaseAuthenticationRequest simpleAuthenticationRequest, | ||
AuthenticationRequestContext authenticationRequestContext) { | ||
return Uni.createFrom().nothing(); | ||
} | ||
} | ||
} |
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.