I´m trying to load after successful authentication from Keycloak (AUTH provider) some information and store in my @SessionScoped Bean and set it in the Session Attribute from Omnifaces.
In shiro.ini I defined this line:
roleAdminAuthGenerator = de.dpunkt.myaktion.util.Pac4jRoleAdminAuthGenerator
oidcClient.authorizationGenerator = $roleAdminAuthGenerator
This is my Pac4jRoleAdminAuthGenerator class:
import org.apache.commons.lang.exception.ExceptionUtils;
import org.omnifaces.util.Beans;
import org.pac4j.core.authorization.generator.AuthorizationGenerator;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.context.session.SessionStore;
import org.pac4j.core.profile.UserProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.dpunkt.myaktion.user.controller.login.LoginBean;
import java.util.Optional;
public class Pac4jRoleAdminAuthGenerator implements AuthorizationGenerator {
private final Logger LOGGER = LoggerFactory.getLogger(Pac4jRoleAdminAuthGenerator.class);
public Pac4jRoleAdminAuthGenerator() {
}
@Override
public Optional<UserProfile> generate(final WebContext context, final SessionStore sessionStore,
final UserProfile profile) {
try {
final LoginBean loginBean = Beans.getReference(LoginBean.class);
String username = profile.getUsername();
loginBean.submitPac4j(username);
}
catch (Exception e) {
LOGGER.error(ExceptionUtils.getFullStackTrace(e));
}
return Optional.of(profile);
}
}
Using CDI is working via:
Beans.getReference(LoginBean.class)
In my LoginBean I got always a NPE for:
public void submitPac4j(String username) {
Faces.setSessionAttribute("myuser", new Object());
}
Because the Faces Context is NULL.
-> In Omnifaces class "FacesLocal" this "context" is NULL

How can I fix this?