Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JSP: Display links/apps based on case-by-case users

    Hello,

    I am developing a Java (Spring/MVC framework) web-app that needs to allow for users to have a certain set of applications from their computer (client), and only those. For example, User 1 is only allowed to access Microsoft Word, Firefox, and VLC. User 2 can only access Firefox. The filepaths are stored in an SQL database. I know how to set user permissions simply, using:
    Code:
    <!-- Access links for admin -->
    <%if(cur.getAccessLevel()==User.ADMIN)  {%>
    <tr> <td id="links"><a href="<%=request.getContextPath() %>/jsp/index.jsp"> Home </a></td></tr>
    <tr> <td id="links"><a href="<%=request.getContextPath() %>/jsp/applicationSelector.jsp">Use Applications</a></td></tr>			
    <tr> <td id="links"><a href="<%=request.getContextPath() %>/jsp/addapplication.jsp">Add Application</a></td></tr>
    <tr> <td id="links"><a href="<%=request.getContextPath() %>/jsp/editapplication.jsp">Edit Application</a></td></tr>
    <tr> <td id="links" ><a href="<%=request.getContextPath() %>/jsp/removeapplication.jsp">Remove Application</a></td></tr>
    <tr> <td id="links"><a href="<%=request.getContextPath() %>/jsp/viewapplication.jsp">View Application</a></td></tr>
    from the login.jsp

    But now I need a way to say something like, if the user has access to this application, display it on their Use Applications list (as they would currently be logged in). Right now the apps are listed using this:
    Code:
    <!-- For loop of all applications -->
    <%
    for (Application a : list ) {
    %>
    <div class="list" name="<%=a.getId()%>" style="background-color: gray;">
    
    <br>
    <%=a.getName()%>
    
    </div>
    <% } %>
    in the applicationSelector.jsp
    I have a table set up in the DB containing a user id and an application id, so I can grab both of those easily enough; and a user can have access to any or all applications, and each user could have different needs. So unfortunately it's not as simple as "if user access level is Firefox, display that."

    Any ideas? Let me know if you need more information.
    We're using SQL as the DB and phpmyadmin, on Tomcat 6.0.1.6.

    Thanks a million!
    Last edited by freefallenigma; 12-14-2008 at 07:37 AM.

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update

    Okay. Well, this is where I'm at right now in the jsp code:
    Code:
    <!-- For loop of all listed applications -->
    
    <%
    for (Application a : list ) {
    %>
         <% if (apps.contains(a)) { %>
           <div class="list" name="<%=a.getId()%>" style="background-color: gray;">
    
              <%=a.getName()%>
    
          </div>
    <%} } %>
    where apps is a LinkedList<Integer> of the user's applications (ids), a.getId() returns the app's id, and a.getName() returns the application's name, to display on the list.

    Which now leaves me with a NullPointerException when I try to access that page. I reviewed and revised the class that connects to the DB, a DAO, and it looks like I am connecting correctly. For example, the method that adds a user to the table:
    Code:
    public void addUser(User u) throws Exception
    	{
    Connection conn = ds.getConnection();
    		Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    		ResultSet rs = stmt.executeQuery("select * from at_core_user");
    		rs.moveToInsertRow();
            rs.updateString("fname",u.getFName());
            rs.updateString("mname",u.getMName());
            rs.updateString("lname",u.getLName());
            rs.updateInt("access_level",u.getAccessLevel());
            rs.updateString("u_password",u.getPassword());
            rs.updateInt("image", u.getImage().getId());
            rs.updateString("unique_user",u.getUName());
            rs.insertRow();
            int id = rs.getInt("id");
    		stmt.close();
    		LinkedList<Integer> app_ids = u.getApps();
    		for(Integer a:app_ids)
    		{
    			stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    			rs = stmt.executeQuery("select * from at_core_user_apps");
    			rs.moveToInsertRow();
    			rs.updateInt(2, u.getId());
    			rs.updateInt(3, a.intValue());
    			rs.insertRow();
    
    		stmt.close();
    		}
    		conn.close();
    	}
    And for now I have 2 data sets in the DB: u_id 2, app_id 1; u_id 2, app_id 2

    For starters, does anyone suggest a way to check if the file is actually able to access that table in the DB?

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, nevermind. I figured it out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •