-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pac4jModule: a way to omit /logout and /callback
- turn off by default or force them with Pac4jOptions - fix #3328
- Loading branch information
Edgar Espina
committed
Feb 25, 2024
1 parent
c8cdbc2
commit 7c45e8e
Showing
3 changed files
with
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.UUID; | ||
|
||
import org.pac4j.core.credentials.TokenCredentials; | ||
import org.pac4j.core.profile.BasicUserProfile; | ||
import org.pac4j.http.client.direct.HeaderClient; | ||
|
||
import io.jooby.junit.ServerTest; | ||
import io.jooby.junit.ServerTestRunner; | ||
import io.jooby.pac4j.Pac4jModule; | ||
import io.jooby.pac4j.Pac4jOptions; | ||
import okhttp3.Response; | ||
|
||
public class Issue3328 { | ||
|
||
@ServerTest | ||
public void pac4jShouldWorkWithSignedSession(ServerTestRunner runner) { | ||
runner | ||
.define( | ||
app -> { | ||
app.install( | ||
new Pac4jModule(new Pac4jOptions()) | ||
.client( | ||
conf -> | ||
new HeaderClient( | ||
"user-id", | ||
(credentials, context, sessionStore) -> { | ||
var profile = new BasicUserProfile(); | ||
profile.setId(((TokenCredentials) credentials).getToken()); | ||
credentials.setUserProfile(profile); | ||
}))); | ||
|
||
app.get("/i3328", ctx -> ((BasicUserProfile) ctx.getUser()).getId()); | ||
}) | ||
.ready( | ||
http -> { | ||
var userid = UUID.randomUUID().toString(); | ||
http.header("user-id", userid) | ||
.get( | ||
"/i3328", | ||
rsp -> { | ||
assertEquals(userid, rsp.body().string()); | ||
}); | ||
}); | ||
} | ||
|
||
private String cleanCookie(Response response) { | ||
String value = | ||
response.headers("Set-Cookie").stream() | ||
.filter(it -> it.startsWith("Test=")) | ||
.findFirst() | ||
.get(); | ||
int i = value.indexOf(";Path"); | ||
return i > 0 ? value.substring(0, i) : value; | ||
} | ||
} |