-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24226 from knutwannheden/23254
Add config quarkus.security.auth.enabled-in-dev-mode
- Loading branch information
Showing
5 changed files
with
89 additions
and
3 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
24 changes: 24 additions & 0 deletions
24
...src/main/java/io/quarkus/security/spi/runtime/DevModeDisabledAuthorizationController.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,24 @@ | ||
package io.quarkus.security.spi.runtime; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.inject.Singleton; | ||
import javax.interceptor.Interceptor; | ||
|
||
import io.quarkus.runtime.LaunchMode; | ||
|
||
/** | ||
* Controller used in dev mode if {@code quarkus.security.auth.enabled-in-dev-mode=false}. | ||
*/ | ||
@Alternative | ||
@Priority(Interceptor.Priority.LIBRARY_AFTER) | ||
@Singleton | ||
public final class DevModeDisabledAuthorizationController extends AuthorizationController { | ||
|
||
public boolean isAuthorizationEnabled() { | ||
if (LaunchMode.current() != LaunchMode.DEVELOPMENT) { | ||
throw new IllegalStateException("This implementation is only available in dev mode"); | ||
} | ||
return false; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ation-tests/devmode/src/test/java/io/quarkus/test/security/DisabledAuthorizationTest.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 io.quarkus.test.security; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import javax.annotation.security.DenyAll; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DisabledAuthorizationTest { | ||
@RegisterExtension | ||
static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(HelloResource.class) | ||
.add(new StringAsset("quarkus.security.auth.enabled-in-dev-mode=false"), "application.properties")); | ||
|
||
@Test | ||
void verifyAuthorizationEnablement() { | ||
RestAssured.given() | ||
.when().get("/") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("hello")); | ||
} | ||
|
||
@ApplicationScoped | ||
@Path("/") | ||
@DenyAll | ||
public static class HelloResource { | ||
@GET | ||
public String hello() { | ||
return "hello"; | ||
} | ||
} | ||
} |