HttpServletRequest: isUserInRole(String arg0) : HttpServletRequest « javax.servlet.http « Java by API






HttpServletRequest: isUserInRole(String arg0)

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthenticationSnoop extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    out.println("<HTML><BODY>");

    out.println("<H1>This is a password protected resource</H1>");
    out.println("<PRE>");
    out.println("User Name: " + req.getRemoteUser());
    String name = (req.getUserPrincipal() == null) ? null : req.getUserPrincipal().getName();
    out.println("Principal Name: " + name);
    out.println("Authentication Type: " + req.getAuthType());
    out.println("Is a Manager: " + req.isUserInRole("manager"));
    out.println("</PRE>");
    out.println("</BODY></HTML>");
  }
}

           
       








Related examples in the same category

1.HttpServletRequest: getAuthType()
2.HttpServletRequest: getCookies()
3.HttpServletRequest: getHeaders(String name)
4.HttpServletRequest: getHeader( ) by Accept-Language
5.HttpServletRequest: getHeader( ) by Accept-Charset
6.HttpServletRequest: getRequestURI()
7.ServletRequest: getReader()
8.ServletRequest: getRequestDispatcher(String arg0)
9.HttpServletRequest: getHeaderNames()
10.HttpServletRequest: getPathInfo()
11.HttpServletRequest: getPathTranslated()
12.HttpServletRequest: getQueryString()
13.HttpServletRequest: getRemoteUser()
14.HttpServletRequest: getSession()
15.HttpServletRequest: getUserPrincipal()
16.HttpServletRequest: isRequestedSessionIdFromCookie()
17.HttpServletRequest: isRequestedSessionIdFromURL()
18.HttpServletRequest: isRequestedSessionIdValid()