title: How to get logged in user stateless bean
body: <p>I am confused on how I should validate a logged-in user. I was thinking about calling stateful bean from stateless bean but I read this topic <a href="https://stackoverflow.com/questions/9384368/access-existing-instance-stateful-inside-stateless-java-ee-6">access existing instance stateful inside stateless, java ee 6</a></p>
  
  <p>Here is my idea.</p>
  
  <p><strong>ProductBean.java</strong></p>
  
  <pre><code>@Stateless
  @LocalBean
  public class ProductBean {
      @EJB private UserBean userBean; // UserBean is SFSB
      public Product addProduct(Product product) {
          if(userBean == null || userBean.getLoggedInUser() == null) {
              // throw an exception
          }
          // persist 
      }
  }
  </code></pre>
  
  <p><strong>ProductController.java</strong></p>
  
  <pre><code>@ManagedBean
  @RequestScope
  public class ProductController {
      @EJB private ProductBean productBean;
      private Product product;
      public void addProduct() {
          Object result = productBean.addProduct(productBean);
      }
  }
  </code></pre>
  
  <p>Thank you in advance. :)</p>