package org.jboss.test.security.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class CustomPrincipalServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String type = request.getParameter("type");
Principal caller = request.getUserPrincipal();
Class callerClass = caller.getClass();
if( type.equals(callerClass.getName()) == false )
{
throw new ServletException("UserPrincipal type: "+callerClass.getName()
+" != "+type);
}
PrintWriter pw = response.getWriter();
pw.write("<html>Saw expected UserPrincipal type</html>");
}
}