1 23 package org.infoglue.deliver.applications.filters; 24 25 import java.security.Principal ; 26 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.Collections ; 29 import java.util.Enumeration ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletRequestWrapper ; 36 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 import org.infoglue.cms.security.InfoGluePrincipal; 40 import org.infoglue.cms.security.InfoGlueRole; 41 import org.infoglue.deliver.portal.PathParser; 42 import org.infoglue.deliver.portal.PortalControlURL; 43 44 public class PortalServletRequest extends HttpServletRequestWrapper 45 { 46 private static final Log log = LogFactory.getLog(PortalServletRequest.class); 47 48 public static final String MULTI_VALUE = PathParser.MULTI_VALUE; 49 50 private Map paramMap; 51 private Principal principal = null; 52 53 56 57 public PortalServletRequest(HttpServletRequest req) 58 { 59 super(req); 60 paramMap = PathParser.copyParameters(req.getParameterMap()); 61 62 paramMap.putAll(PathParser.parsePathParameters(PortalControlURL.IG, req.getServletPath(), false)); 65 66 if (log.isDebugEnabled()) 67 { 68 StringBuffer str = new StringBuffer (); 69 for (Iterator it = paramMap.keySet().iterator(); it.hasNext();) 70 { 71 String name = (String ) it.next(); 72 str.append(name); 73 str.append(": "); 74 str.append(Arrays.asList((String []) paramMap.get(name))); 75 if (it.hasNext()) 76 str.append(", "); 77 } 78 log.debug("Available params: " + str); 79 } 80 81 this.principal = (InfoGluePrincipal)req.getSession().getAttribute("infogluePrincipal"); 82 if(req.getUserPrincipal() != null) 83 this.principal = req.getUserPrincipal(); 84 } 85 86 87 88 91 92 public Map getParameterMap() 93 { 94 return paramMap; 95 } 96 97 100 101 public String getParameter(String name) 102 { 103 String [] values = (String []) paramMap.get(name); 104 if (values != null && values.length > 0) 105 { 106 return values[0]; 107 } 108 109 return null; 110 } 111 112 115 116 public Enumeration getParameterNames() 117 { 118 return Collections.enumeration(paramMap.keySet()); 119 } 120 121 124 125 public String [] getParameterValues(String name) 126 { 127 return (String []) paramMap.get(name); 128 } 129 130 public String getRemoteUser() 131 { 132 return (this.principal == null ? null : this.principal.getName()); 133 } 134 135 public boolean isUserInRole(String role) 136 { 137 boolean isUserInRole = false; 138 139 if(this.principal != null) 140 { 141 if(this.principal instanceof InfoGluePrincipal) 142 { 143 List roles = ((InfoGluePrincipal)this.principal).getRoles(); 144 Iterator i = roles.iterator(); 145 146 while(i.hasNext()) 147 { 148 InfoGlueRole currentRole = (InfoGlueRole)i.next(); 149 if(currentRole.getName().equals(role)) 150 { 151 isUserInRole = true; 152 break; 153 } 154 } 155 } 156 else 157 { 158 isUserInRole = super.isUserInRole(role); 159 } 160 } 161 162 return isUserInRole; 163 } 164 165 public Principal getUserPrincipal() 166 { 167 return this.principal; 168 } 169 } | Popular Tags |