Skip to content

Commit

Permalink
pac4j: Make user profile available in request registry both as concre…
Browse files Browse the repository at this point in the history
…te type and `UserProfile` (#307)
  • Loading branch information
davidmc24 committed Apr 15, 2014
1 parent c8c3c31 commit 15daa5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Expand Up @@ -66,6 +66,7 @@ public void handle(final Context context) throws Exception {
} else {
if (userProfile != null) {
context.getRequest().register(userProfile);
context.getRequest().register(UserProfile.class, userProfile);
authorizer.handleAuthorization(context, userProfile);
} else {
context.next();
Expand Down
Expand Up @@ -99,7 +99,7 @@ class OpenIdRpSpec extends Specification {
def response = client.get("noauth")

then: "the page is returned without any redirects, and without authentication"
response.asString() == "noauth:null"
response.asString() == "noauth:null:null"

where:
aut << [autConstructed, autInjected]
Expand Down Expand Up @@ -136,13 +136,13 @@ class OpenIdRpSpec extends Specification {
def response4 = client.createRequest().cookies(response1.cookies).get(response3.header(LOCATION))

then: "the original page is returned"
response4.asString() == "auth:${EMAIL}"
response4.asString() == "auth:${EMAIL}:${EMAIL}"

when: "request a page that doesn't require authentication after authenticating"
def response5 = client.createRequest().cookies(response1.cookies).get("noauth")

then: "authentication information is still available"
response5.asString() == "noauth:${EMAIL}"
response5.asString() == "noauth:${EMAIL}:${EMAIL}"

where:
aut << [autConstructed, autInjected]
Expand Down
Expand Up @@ -17,6 +17,7 @@
package ratpack.pac4j.openid

import com.google.inject.Module
import org.pac4j.core.profile.UserProfile
import org.pac4j.openid.profile.google.GoogleOpenIdProfile
import ratpack.groovy.test.embed.ClosureBackedEmbeddedApplication
import ratpack.session.SessionModule
Expand All @@ -39,12 +40,14 @@ class RatpackOpenIdTestApplication extends ClosureBackedEmbeddedApplication {
}
handlers {
get("noauth") {
def userProfile = request.maybeGet(GoogleOpenIdProfile)
response.send "noauth:${userProfile?.email}"
def typedUserProfile = request.maybeGet(GoogleOpenIdProfile)
def genericUserProfile = request.maybeGet(UserProfile)
response.send "noauth:${typedUserProfile?.email}:${genericUserProfile?.attributes?.email}"
}
get("auth") {
def userProfile = request.maybeGet(GoogleOpenIdProfile)
response.send "auth:${userProfile.email}"
def typedUserProfile = request.maybeGet(GoogleOpenIdProfile)
def genericUserProfile = request.maybeGet(UserProfile)
response.send "auth:${typedUserProfile.email}:${genericUserProfile?.attributes?.email}"
}
get("error") {
response.send "An error was encountered."
Expand Down

0 comments on commit 15daa5e

Please sign in to comment.