package org.javaee7.jaspic.registersession.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author Arjan Tijms * */ @WebServlet(urlPatterns = "/public/servlet") public class PublicServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("This is a public servlet \n"); String webName = null; if (request.getUserPrincipal() != null) { webName = request.getUserPrincipal().getName(); } response.getWriter().write("web username: " + webName + "\n"); boolean webHasRole = request.isUserInRole("architect"); response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n"); } }