1 7 package org.exoplatform.services.portletcontainer.test.portlet; 8 9 import java.io.IOException ; 10 import java.io.PrintWriter ; 11 import java.security.Principal ; 12 import java.util.Enumeration ; 13 14 import javax.portlet.ActionRequest; 15 import javax.portlet.ActionResponse; 16 import javax.portlet.GenericPortlet; 17 import javax.portlet.PortletConfig; 18 import javax.portlet.PortletException; 19 import javax.portlet.PortletRequest; 20 import javax.portlet.RenderRequest; 21 import javax.portlet.RenderResponse; 22 23 27 public class PortletToTestSecurityInfoFromRequest extends GenericPortlet { 28 29 private static String [] arrayOfHeaders = {"header1", "header2", "header3"}; 30 31 public void init(PortletConfig portletConfig) throws PortletException { 32 } 33 34 public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) 35 throws PortletException, IOException { 36 String auth = actionRequest.getAuthType(); 37 38 if(!(PortletRequest.BASIC_AUTH.equals(auth) || PortletRequest.CLIENT_CERT_AUTH.equals(auth) || 39 PortletRequest.DIGEST_AUTH.equals(auth) || PortletRequest.FORM_AUTH.equals(auth))) 40 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 41 42 String remoteUserName = actionRequest.getRemoteUser(); 43 if(!"REMOTE USER FROM MOCK".equals(remoteUserName)) 44 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 45 46 Principal p = actionRequest.getUserPrincipal(); 47 if(!"PrincipalMackName".equals(p.getName())) 48 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 49 50 boolean test = actionRequest.isUserInRole("auth-user"); 51 if(!test) 52 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 53 54 test = actionRequest.isUserInRole("testRole2"); 55 if(test) 56 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 57 58 test = actionRequest.isSecure(); 59 if(!test) 60 throw new PortletException("exception in processAction of PortletToTestSecurityInfoFromRequest"); 61 62 actionResponse.setRenderParameter("status", "Everything is ok"); 63 } 64 65 public void render(RenderRequest renderRequest, RenderResponse renderResponse) 66 throws PortletException, IOException { 67 renderResponse.setContentType("text/html"); 68 PrintWriter w = renderResponse.getWriter(); 69 w.println("Everything is ok"); 70 } 71 72 public void destroy() { 73 } 74 } | Popular Tags |