After authorizing my user, I want to put the link in the session to the current registered user.
This is how I do it in the setCurrentUser
method:
FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true); session.setAttribute("CURRENT_USER", currentUser);
Unfortunately, the session
link is always null!
Alternatively I tried using sessionMap
FacesContext facesContext = FacesContext.getCurrentInstance(); Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); sessionMap.put("CURRENT_USER", currentUser);
This is a terrible failure with this exception:
java.lang.UnsupportedOperationException at java.util.AbstractMap.put(AbstractMap.java:186) (...)
What am I doing wrong?
The full code of my controller
UserController.java
public class UserController implements Filter { private FilterConfig fc; private static final String CURRENT_USER = "CURRENT_USER"; public void init(FilterConfig filterConfig) throws ServletException { fc = filterConfig; log(">> Filter initialized"); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Jsf 2.0
JBoss 5.1.0.GA
source share