-
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.
- Loading branch information
1 parent
4b2a4b4
commit 0ec6217
Showing
9 changed files
with
333 additions
and
8 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
151 changes: 151 additions & 0 deletions
151
...ecurity/deployment/src/test/java/io/quarkus/security/test/BasicAuthJdbcRealmTestCase.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,151 @@ | ||
package io.quarkus.security.test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Tests of BASIC authentication mechanism with an Database Identity store | ||
*/ | ||
public class BasicAuthJdbcRealmTestCase { | ||
static Class[] testClasses = { | ||
TestSecureServlet.class, TestApplication.class, RolesEndpointClassLevel.class, | ||
ParametrizedPathsResource.class, SubjectExposingResource.class | ||
}; | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClasses) | ||
.addAsResource("application-jdbc-single-query-no-attribues.properties")); | ||
|
||
// Basic @ServletSecurity tests | ||
@Test() | ||
public void testSecureAccessFailure() { | ||
RestAssured.when().get("/secure-test").then() | ||
.statusCode(401); | ||
} | ||
|
||
@Test() | ||
public void testSecureRoleFailure() { | ||
RestAssured.given().auth().preemptive().basic("jdoe", "p4ssw0rd") | ||
.when().get("/secure-test").then() | ||
.statusCode(403); | ||
} | ||
|
||
@Test() | ||
public void testSecureAccessSuccess() { | ||
RestAssured.given().auth().preemptive().basic("stuart", "test") | ||
.when().get("/secure-test").then() | ||
.statusCode(200); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource without any authentication. should see 401 error code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetFailure() { | ||
RestAssured.when().get("/jaxrs-secured/rolesClass").then() | ||
.statusCode(401); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource with authentication, but no authorization. should see 403 error code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetRoleFailure() { | ||
RestAssured.given().auth().preemptive().basic("jdoe", "p4ssw0rd") | ||
.when().get("/jaxrs-secured/rolesClass").then() | ||
.statusCode(403); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource with authentication, and authorization. should see 200 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetRoleSuccess() { | ||
RestAssured.given().auth().preemptive().basic("scott", "jb0ss") | ||
.when().get("/jaxrs-secured/rolesClass").then() | ||
.statusCode(200); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource with authentication, and authorization. should see 200 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsPathAdminRoleSuccess() { | ||
RestAssured.given().auth().preemptive().basic("scott", "jb0ss") | ||
.when().get("/jaxrs-secured/parameterized-paths/my/banking/admin").then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void testJaxrsPathAdminRoleFailure() { | ||
RestAssured.given().auth().preemptive().basic("noadmin", "n0Adm1n") | ||
.when().get("/jaxrs-secured/parameterized-paths/my/banking/admin").then() | ||
.statusCode(403); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource with authentication, and authorization. should see 200 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsPathUserRoleSuccess() { | ||
RestAssured.given().auth().preemptive().basic("stuart", "test") | ||
.when().get("/jaxrs-secured/parameterized-paths/my/banking/view").then() | ||
.statusCode(200); | ||
} | ||
|
||
/** | ||
* Test access a secured jaxrs resource with authentication, and authorization. should see 200 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsUserRoleSuccess() { | ||
RestAssured.given().auth().preemptive().basic("scott", "jb0ss") | ||
.when().get("/jaxrs-secured/subject/secured").then() | ||
.statusCode(200) | ||
.body(equalTo("scott")); | ||
} | ||
|
||
@Test | ||
public void testJaxrsInjectedPrincipalSuccess() { | ||
RestAssured.given().auth().preemptive().basic("scott", "jb0ss") | ||
.when().get("/jaxrs-secured/subject/principalSecured").then() | ||
.statusCode(200) | ||
.body(equalTo("scott")); | ||
} | ||
|
||
/** | ||
* Test access a @PermitAll secured jaxrs resource without any authentication. should see a 200 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetPermitAll() { | ||
RestAssured.when().get("/jaxrs-secured/subject/unsecured").then() | ||
.statusCode(200) | ||
.body(equalTo("anonymous")); | ||
} | ||
|
||
/** | ||
* Test access a @DenyAll secured jaxrs resource without authentication. should see a 401 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetDenyAllWithoutAuth() { | ||
RestAssured.when().get("/jaxrs-secured/subject/denied").then() | ||
.statusCode(401); | ||
} | ||
|
||
/** | ||
* Test access a @DenyAll secured jaxrs resource with authentication. should see a 403 success code. | ||
*/ | ||
@Test | ||
public void testJaxrsGetDenyAllWithAuth() { | ||
RestAssured.given().auth().preemptive().basic("scott", "jb0ss") | ||
.when().get("/jaxrs-secured/subject/denied").then() | ||
.statusCode(403); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...urity/deployment/src/test/resources/application-jdbc-single-query-no-attribues.properties
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,7 @@ | ||
quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:default | ||
quarkus.datasource.driver=org.h2.Driver | ||
quarkus.datasource.username=username-default | ||
|
||
quarkus.security.jdbc.enabled=true | ||
quarkus.security.jdbc.principal-query.sql= | ||
quarkus.security.jdbc.principal-query.datasource=default |
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
89 changes: 89 additions & 0 deletions
89
...n-security/runtime/src/main/java/io/quarkus/elytron/security/runtime/JdbcRealmConfig.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,89 @@ | ||
package io.quarkus.elytron.security.runtime; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
/** | ||
* A configuration object for a jdbc based realm configuration, | ||
* {@linkplain org.wildfly.security.auth.realm.LegacyPropertiesSecurityRealm} | ||
*/ | ||
@ConfigGroup | ||
public class JdbcRealmConfig { | ||
|
||
/** | ||
* The authentication mechanism | ||
*/ | ||
@ConfigItem(defaultValue = "BASIC") | ||
public String authMechanism; | ||
|
||
/** | ||
* The authentication mechanism | ||
*/ | ||
@ConfigItem(defaultValue = "Quarkus") | ||
public String realmName; | ||
|
||
/** | ||
* If the properties store is enabled. | ||
*/ | ||
@ConfigItem | ||
public boolean enabled; | ||
|
||
/** | ||
* The principal-query config | ||
*/ | ||
@ConfigItem | ||
public PrincipalQueryConfig principalQuery; | ||
// https://github.com/wildfly/wildfly-core/blob/master/elytron/src/test/resources/org/wildfly/extension/elytron/security-realms.xml#L18 | ||
|
||
public String getAuthMechanism() { | ||
return authMechanism; | ||
} | ||
|
||
public void setAuthMechanism(String authMechanism) { | ||
this.authMechanism = authMechanism; | ||
} | ||
|
||
public String getRealmName() { | ||
return realmName; | ||
} | ||
|
||
public void setRealmName(String realmName) { | ||
this.realmName = realmName; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public PrincipalQueryConfig getPrincipalQuery() { | ||
return principalQuery; | ||
} | ||
|
||
public void setPrincipalQuery(PrincipalQueryConfig principalQuery) { | ||
this.principalQuery = principalQuery; | ||
} | ||
|
||
/** | ||
* Used to access what should be a parent class, but parsing of the MP config properties is not working | ||
* from parent to child | ||
* | ||
* @return AuthConfig information | ||
*/ | ||
public AuthConfig getAuthConfig() { | ||
return new AuthConfig(authMechanism, realmName, getClass()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JdbcRealmConfig{" + | ||
"authMechanism='" + authMechanism + '\'' + | ||
", realmName='" + realmName + '\'' + | ||
", enabled=" + enabled + | ||
", principalQuery=" + principalQuery + | ||
'}'; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...urity/runtime/src/main/java/io/quarkus/elytron/security/runtime/PrincipalQueryConfig.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,20 @@ | ||
package io.quarkus.elytron.security.runtime; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class PrincipalQueryConfig { | ||
|
||
/** | ||
* The sql query to find the password | ||
*/ | ||
@ConfigItem(defaultValue = "SELECT password FROM users WHERE username=?") | ||
public String sql; | ||
|
||
/** | ||
* The data source to use | ||
*/ | ||
@ConfigItem(defaultValue = "default") | ||
public String datasource; | ||
} |
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