Skip to content

Commit

Permalink
Fix #3425 jooby-pac4j module: set config for ProfileManager in Pac4jC… (
Browse files Browse the repository at this point in the history
#3427)

* Fix #3425 jooby-pac4j module: set config for ProfileManager in Pac4jCurrentUser

* Fix #3425 jooby-pac4j module: add pac4j Config to registry

---------

Co-authored-by: Tomasz Karliński <[email protected]>
  • Loading branch information
tkarlinski and Tomasz Karliński committed May 19, 2024
1 parent 85647ea commit 40876aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
import java.util.function.Function;

import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.config.Config;

import io.jooby.Context;
import io.jooby.pac4j.Pac4jContext;

public class Pac4jCurrentUser implements Function<Context, Object> {

@Override
public Object apply(Context ctx) {
Pac4jContext pac4jContext = Pac4jContext.create(ctx);
ProfileManager pm = new ProfileManager(pac4jContext, pac4jContext.getSessionStore());
pm.setConfig(ctx.require(Config.class));
return pm.getProfile().orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ public void install(@NonNull Jooby application) throws Exception {
options.setDefaultUrl(defaultUrl);
});
}

application.getServices().put(Config.class, pac4j);

/** Set current user provider */
application.setCurrentUser(new Pac4jCurrentUser());
// cleanup
Expand Down

0 comments on commit 40876aa

Please sign in to comment.