Dr3ko
Dr3ko

Reputation: 313

Spring Security handle different users with only one path

I've a problem and I were looking to solve it with Spring Security, I'm using Java 1.7, Spring MVC 4.3, Tiles 3, Eclipse Neon and CSS.

I don't want to make different context for each user (/admin /normaluser or /dba) I want only /myPanel to everyone but when someone log in depend on his role only to show him different menus.

Also I've my menu on a tiles fragment is this possible?

I would appreciate your help.

Note.- I'm quit new on front, used to develop back end.

Upvotes: 0

Views: 131

Answers (1)

A Sdi
A Sdi

Reputation: 665

You can use Spring security taglib to render view accordingly. You do it like this:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <ul >
            <sec:authorize access="authenticated" var="authenticated"/>
            <c:choose>
                <c:when test="${authenticated}">
                    <li>
                        <a href="<spring:url value="/test1/"/>">menu1</a>
                    </li>
                </c:when>
                <c:otherwise>
                    <li><a href="<spring:url value="/test2/"/>">menu2</a></li>
                </c:otherwise>
            </c:choose>
   </ul>

Both authenticated and guest user will use the same URL but the content will differ depending on their authentication status

Upvotes: 2

Related Questions