title: Show fields in jsp based on user roles(without using spring security)
body: <p>I have a tabs.jsp which has links to other pages. When an admin logs in he must be given 2 extra links to add users and roles. while authenticating im able to validate if user is admin or not. on validation im returning control to a user display page if user exists if not redirecting back to login page. how do i achieve this extra 2 links if user is admin?</p>
  
  <p>My controller</p>
  
  <pre><code>    @RequestMapping(value = "auth", method = RequestMethod.POST)
          public ModelAndView printStringLogin(
                  @ModelAttribute("USERS") Users userAuthentication,
                  HttpSession httpSession, ModelMap model) {
              System.out.println(userAuthentication.getUsers_email());
              System.out.println(userAuthentication.getUsers_password());
              UserAuthentication userAuthentication2 = new UserAuthentication();
              boolean exists = false,admin = false;
              try {
                  exists = userAuthentication2.doesUserExist(
                          userAuthentication.getUsers_email(),
                          userAuthentication.getUsers_password());
              } catch (Exception e) {
                  e.printStackTrace();
              }
              if (exists == true) {
                  System.out.println("user present");
                  httpSession.setAttribute("id", userAuthentication.getUsers_email());
                  System.out.println("Session Attribute: "
                          + httpSession.getAttribute("id"));
                  return new ModelAndView("redirect:employee");
              } else {
                  System.out.println("user not present");
                  return new ModelAndView("loginpage");
              }
      }
  </code></pre>
  
  <p>user authentication</p>
  
  <pre><code>public class UserAuthentication {
      public boolean doesUserExist(String uname, String passwrd) throws Exception {
          GetSession ses = new GetSession();
          Session session = ses.retSession();
          String query = "from Users as u where u.users_email = :sUname and u.users_password = :sPass";
          List list = session.createQuery(query).setString("sUname", uname)
                  .setString("sPass", passwrd).list();
  
          Iterator iterator = list.iterator();
          boolean userExists = false;
          if (iterator.hasNext()) {
              Users obj = (Users) iterator.next();
              System.out.print(obj.getUsers_email() + "\t"
                      + obj.getUsers_password() + "\n");
              System.out.println(obj.getMyRoles());
              System.out.println("Is Admin??? :" +obj.getMyRoles().toString().contains("Admin")); //gives if user is admin or not
              System.out.println(obj.getUser_id());
              userExists = true;
          }
          System.out.println(userExists);
          return userExists;
      }
  }
  </code></pre>
  
  <p>Tabs.jsp</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%&gt;
      &lt;html&gt;
      &lt;body&gt;
          &lt;div id="tabs" style="background-color: #C8C8C8; font-family: fantasy;"&gt;
              &lt;a href="employee"&gt;&amp;nbsp; Employee Details &lt;/a&gt;
              &lt;a href="department"&gt; Departments &lt;/a&gt;
              &lt;a href="designation"&gt; Designation &lt;/a&gt;
              &lt;a href="logout"&gt; Logout &lt;/a&gt;
              &lt;a href="user"&gt; Users &lt;/a&gt;
              &lt;a href="roles"&gt; Roles &lt;/a&gt;
          &lt;/div&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>users and Roles links must be displayed only if user is admin and this tabs.jsp is included in every page of the application.</p>