forked from pac4j/jax-rs-pac4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and examples for accessing SecurityContext
Related to pac4j#32
- Loading branch information
1 parent
a5be901
commit 62ac935
Showing
9 changed files
with
141 additions
and
2 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
33 changes: 33 additions & 0 deletions
33
src/test/java/org/pac4j/jax/rs/resources/JerseyResource.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,33 @@ | ||
package org.pac4j.jax.rs.resources; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.core.SecurityContext; | ||
|
||
import org.pac4j.core.context.DefaultAuthorizers; | ||
import org.pac4j.jax.rs.annotations.Pac4JSecurity; | ||
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext; | ||
|
||
@Path("/containerSpecific") | ||
public class JerseyResource { | ||
|
||
@Inject ContainerRequestContext requestContext; | ||
|
||
@POST | ||
@Path("/context") | ||
@Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED) | ||
public String directContext() { | ||
SecurityContext context = requestContext.getSecurityContext(); | ||
if (context != null) { | ||
if (context instanceof Pac4JSecurityContext) { | ||
return "ok"; | ||
} else { | ||
return "fail"; | ||
} | ||
} else { | ||
return "error"; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/org/pac4j/jax/rs/resources/RestEasyResource.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,30 @@ | ||
package org.pac4j.jax.rs.resources; | ||
|
||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.SecurityContext; | ||
|
||
import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
import org.pac4j.core.context.DefaultAuthorizers; | ||
import org.pac4j.jax.rs.annotations.Pac4JSecurity; | ||
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext; | ||
|
||
@Path("/containerSpecific") | ||
public class RestEasyResource { | ||
|
||
@POST | ||
@Path("/context") | ||
@Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED) | ||
public String directContext() { | ||
SecurityContext context = ResteasyProviderFactory.getContextData(SecurityContext.class); | ||
if (context != null) { | ||
if (context instanceof Pac4JSecurityContext) { | ||
return "ok"; | ||
} else { | ||
return "fail"; | ||
} | ||
} else { | ||
return "error"; | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.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
12 changes: 11 additions & 1 deletion
12
src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyServletRule.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
10 changes: 10 additions & 0 deletions
10
src/test/java/org/pac4j/jax/rs/rules/JerseyInMemoryRule.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
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