1 22 package org.jboss.test.security.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.security.Principal ; 27 import javax.servlet.http.HttpServlet ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.ServletException ; 31 32 36 public class CustomPrincipalServlet extends HttpServlet 37 { 38 protected void doGet(HttpServletRequest request, HttpServletResponse response) 39 throws ServletException , IOException 40 { 41 String type = request.getParameter("type"); 42 Principal caller = request.getUserPrincipal(); 43 Class callerClass = caller.getClass(); 44 if( type.equals(callerClass.getName()) == false ) 45 { 46 throw new ServletException ("UserPrincipal type: "+callerClass.getName() 47 +" != "+type); 48 } 49 PrintWriter pw = response.getWriter(); 50 pw.write("<html>Saw expected UserPrincipal type</html>"); 51 } 52 } 53 | Popular Tags |