jay electricity
jay electricity

Reputation: 309

Show or hide parts of an HTML page based on user credentials in Servlets/Spring MVC

I am working on a web tool which uses Java servlets and Spring MVC framework. Currently every user who is properly authenticated and authorized (i.e. part of certain LDAP groups) can view the home page of the tool. If a user is not authenticated or authorized, he/she will get a 401 error. This is accomplished by using a filter which gets the user credentials and matches them against the list of allowed groups. I want to modify this functionality such that every authenticated user (i.e. he/she provides correct username and password) can view the home page. On the home page itself, there are two sections that I want to show or hide based on certain conditions. The first section is shown/hidden based on whether or not a user is part of a certain LDAP group. To show/hide the second section I will need to query a database and see if the user exists in that database. I am not sure about how to implement this. Should I still be using a filter? Is there a way I can leverage Spring framework here? Any help would be appreciated.

Upvotes: 1

Views: 589

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44824

try using core taglib

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<c:if test="${sessionScope.LOGGEDINUSER.groupname == 'admin'}">  // or whatever your object is called
    <!-- show it -->
<c:if>

Upvotes: 1

Related Questions