-
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.
Merge pull request #26792 from sberyozkin/test_security_principal
Add TestPrincipalProducer
- Loading branch information
Showing
7 changed files
with
54 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ public class TestSecurityLazyAuthTest { | |
@TestSecurity(user = "user1", roles = "viewer") | ||
public void testWithDummyUser() { | ||
RestAssured.when().get("test-security").then() | ||
.body(is("user1")); | ||
.body(is("user1:user1:user1")); | ||
} | ||
|
||
@Test | ||
|
@@ -35,7 +35,7 @@ public void testWithDummyUser() { | |
}) | ||
public void testJwtWithDummyUser() { | ||
RestAssured.when().get("test-security-oidc").then() | ||
.body(is("userOidc:viewer:[email protected]:subject:aud")); | ||
.body(is("userOidc:userOidc:userOidc:viewer:[email protected]:subject:aud")); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ public class TestSecurityLazyAuthTest { | |
@TestSecurity(user = "user1", roles = "viewer") | ||
public void testWithDummyUser() { | ||
RestAssured.when().get("test-security").then() | ||
.body(is("user1")); | ||
.body(is("user1:user1:user1")); | ||
} | ||
|
||
@Test | ||
|
@@ -50,7 +50,7 @@ public void testPostWithDummyUserForbidden() { | |
}) | ||
public void testJwtGetWithDummyUser() { | ||
RestAssured.when().get("test-security-jwt").then() | ||
.body(is("userJwt:viewer:[email protected]")); | ||
.body(is("userJwt:userJwt:userJwt:viewer:[email protected]")); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
test-framework/security/src/main/java/io/quarkus/test/security/TestPrincipalProducer.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,28 @@ | ||
package io.quarkus.test.security; | ||
|
||
import java.security.Principal; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
import javax.interceptor.Interceptor; | ||
|
||
import io.quarkus.security.identity.SecurityIdentity; | ||
|
||
@Alternative | ||
@Priority(Interceptor.Priority.LIBRARY_AFTER) | ||
@ApplicationScoped | ||
public class TestPrincipalProducer { | ||
|
||
@Inject | ||
SecurityIdentity testIdentity; | ||
|
||
@Produces | ||
@RequestScoped | ||
public Principal getTestIdentity() { | ||
return testIdentity.getPrincipal(); | ||
} | ||
} |