Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. public class SessionUtils {
  2. public static HttpSession getSession() {
  3. return (HttpSession) FacesContext.getCurrentInstance()
  4. .getExternalContext().getSession(false);
  5. }
  6.  
  7. public static HttpServletRequest getRequest() {
  8. return (HttpServletRequest) FacesContext.getCurrentInstance()
  9. .getExternalContext().getRequest();
  10. }
  11.  
  12. public static String getUserEmail() {
  13. HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
  14. .getExternalContext().getSession(false);
  15. return session.getAttribute("email").toString();
  16.  
  17. }
  18.  
  19. public static String getUserId() {
  20. HttpSession session = getSession();
  21. if (session != null)
  22. return (String) session.getAttribute("userid");
  23. else
  24. return null;
  25. }
  26. }
  27.  
  28. a part of index.xhtml
  29.  
  30.  
  31.  
  32. <c:if test='#{authenticateBean.GetSession() ne null}'>
  33. <c:if test='#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}'>
  34. <ul class="links">
  35. <li >
  36. <h:link value="add" outcome="GoodBasket" />
  37. </li>
  38. </ul>
  39. </c:if>
  40. </c:if>
  41.  
  42. @Override
  43. public void doFilter(ServletRequest request, ServletResponse response,
  44. FilterChain chain) throws IOException, ServletException {
  45.  
  46. HttpServletRequest reqt = (HttpServletRequest) request;
  47. HttpServletResponse resp = (HttpServletResponse) response;
  48. HttpSession ses = reqt.getSession(false);
  49.  
  50. String reqURI = reqt.getRequestURI();
  51.  
  52. if ((reqURI.indexOf("/index.xhtml") >= 0))
  53. chain.doFilter(request, response);
  54. else
  55. resp.sendRedirect(reqt.getContextPath() + "/JSFViews/Login.xhtml");
  56. }
  57.  
  58. public String Login(){
  59. UsersModel user= userServices.Login(email,password);
  60. if (user!=null) {
  61. HttpSession session = SessionUtils.getSession();
  62. session.setAttribute("email", email);
  63. return "ProductRegisteration";
  64. } else {
  65. FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
  66. "Incorrect Username and Passowrd", "Please enter correct username and Password"));
  67. return "Login";
  68. }
  69.  
  70. }
  71. public String GetUserEmail()
  72. {
  73. return SessionUtils.getUserEmail();
  74. }
  75. public HttpSession GetSession()
  76. {
  77. return SessionUtils.getSession();
  78. }
  79.  
  80. javax.servlet.ServletException: /JSFViews/index.xhtml @109,86 test="#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}" /JSFViews/index.xhtml @109,86 test="#{authenticateBean.GetUserEmail() ne "admin@gmail.com"}": java.lang.NullPointerException
  81. javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
  82. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  83. ir.navayemehr.util.AuthorizationFilter.doFilter(AuthorizationFilter.java:55)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement