1 4 package com.tc.weblogic; 5 6 import weblogic.management.descriptors.webapp.FilterMBean; 7 import weblogic.management.descriptors.webapp.FilterMappingMBean; 8 import weblogic.management.descriptors.webapp.ParameterMBean; 9 import weblogic.management.descriptors.webapp.ServletMBean; 10 import weblogic.management.descriptors.webapp.UIMBean; 11 import weblogic.servlet.internal.WebAppServletContext; 12 13 import com.tc.aspectwerkz.joinpoint.StaticJoinPoint; 14 import com.tc.object.bytecode.hook.impl.ClassProcessorHelper; 15 import com.terracotta.session.SessionFilter; 16 17 public class SessionAspect { 18 19 private final ThreadLocal dsoFilter = new ThreadLocal (); 20 21 public Object addFilterIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.WebAppServletContext context) 22 throws Throwable { 23 FilterMBean[] filters = (FilterMBean[]) jp.proceed(); 24 if (filters == null) { 25 filters = new FilterMBean[] {}; 26 } 27 28 if (isDSOSesisons(context)) { 29 FilterMBean filter = new DSOFilterMBean(); 30 setFilterInstance(context, filter); 31 32 FilterMBean[] withDSO = new FilterMBean[filters.length + 1]; 33 System.arraycopy(filters, 0, withDSO, 1, filters.length); 34 withDSO[0] = filter; 35 filters = withDSO; 36 } 37 return filters; 38 } 39 40 public Object addFilterMappingIfNeeded(StaticJoinPoint jp, weblogic.servlet.internal.WebAppServletContext context) 41 throws Throwable { 42 FilterMappingMBean[] mappings = (FilterMappingMBean[]) jp.proceed(); 43 if (mappings == null) { 44 mappings = new FilterMappingMBean[] {}; 45 } 46 47 if (isDSOSesisons(context)) { 48 FilterMappingMBean[] withDSO = new FilterMappingMBean[mappings.length + 1]; 49 System.arraycopy(mappings, 0, withDSO, 1, mappings.length); 50 withDSO[0] = new DSOFilterMappingMBean(getFilterInstance(context)); 51 mappings = withDSO; 52 } 53 return mappings; 54 } 55 56 private FilterMBean getFilterInstance(WebAppServletContext context) { 57 FilterMBean filter = (FilterMBean) dsoFilter.get(); 58 if (filter == null) { throw new AssertionError ("No filter found for " + context.getName()); } 59 dsoFilter.set(null); 60 return filter; 61 } 62 63 private void setFilterInstance(WebAppServletContext context, FilterMBean filter) { 64 if (dsoFilter.get() != null) { throw new AssertionError ("Filter already present for " + context.getName()); } 65 dsoFilter.set(filter); 66 } 67 68 private static boolean isDSOSesisons(WebAppServletContext context) { 69 String appName = context.getName(); 70 boolean rv = ClassProcessorHelper.isDSOSessions(appName); 71 return rv; 72 } 73 74 private static class DSOFilterMappingMBean implements FilterMappingMBean { 75 76 private final FilterMBean filter; 77 78 public DSOFilterMappingMBean(FilterMBean filter) { 79 this.filter = filter; 80 } 81 82 public FilterMBean getFilter() { 83 return filter; 84 } 85 86 public ServletMBean getServlet() { 87 return null; 88 } 89 90 public String getUrlPattern() { 91 return "/*"; 92 } 93 94 public void setFilter(FilterMBean filtermbean) { 95 throw new AssertionError (); 96 } 97 98 public void setServlet(ServletMBean servletmbean) { 99 throw new AssertionError (); 100 } 101 102 public void setUrlPattern(String s) { 103 throw new AssertionError (); 104 } 105 106 public void addDescriptorError(String s) { 107 throw new AssertionError (); 108 } 109 110 public String [] getDescriptorErrors() { 111 throw new AssertionError (); 112 } 113 114 public boolean isValid() { 115 throw new AssertionError (); 116 } 117 118 public void removeDescriptorError(String s) { 119 throw new AssertionError (); 120 } 121 122 public void setDescriptorErrors(String [] as) { 123 throw new AssertionError (); 124 } 125 126 public String getName() { 127 throw new AssertionError (); 128 } 129 130 public void register() { 131 throw new AssertionError (); 132 } 133 134 public void setName(String s) { 135 throw new AssertionError (); 136 } 137 138 public String toXML(int i) { 139 throw new AssertionError (); 140 } 141 142 public void unregister() { 143 throw new AssertionError (); 144 } 145 146 } 147 148 private static class DSOFilterMBean implements FilterMBean { 149 150 public void addInitParam(ParameterMBean parametermbean) { 151 } 153 154 public String getFilterClass() { 155 return SessionFilter.FILTER_CLASS; 156 } 157 158 public String getFilterName() { 159 return SessionFilter.FILTER_NAME; 160 } 161 162 public ParameterMBean[] getInitParams() { 163 return new ParameterMBean[] {}; 164 } 165 166 public UIMBean getUIData() { 167 throw new AssertionError (); 168 } 169 170 public void removeInitParam(ParameterMBean parametermbean) { 171 throw new AssertionError (); 172 } 173 174 public void setFilterClass(String s) { 175 throw new AssertionError (); 176 } 177 178 public void setFilterName(String s) { 179 throw new AssertionError (); 180 } 181 182 public void setInitParams(ParameterMBean[] aparametermbean) { 183 throw new AssertionError (); 184 } 185 186 public void setUIData(UIMBean uimbean) { 187 throw new AssertionError (); 188 } 189 190 public void addDescriptorError(String s) { 191 throw new AssertionError (); 192 } 193 194 public String [] getDescriptorErrors() { 195 throw new AssertionError (); 196 } 197 198 public boolean isValid() { 199 throw new AssertionError (); 200 } 201 202 public void removeDescriptorError(String s) { 203 throw new AssertionError (); 204 } 205 206 public void setDescriptorErrors(String [] as) { 207 throw new AssertionError (); 208 } 209 210 public String getName() { 211 throw new AssertionError (); 212 } 213 214 public void register() { 215 throw new AssertionError (); 216 } 217 218 public void setName(String s) { 219 throw new AssertionError (); 220 } 221 222 public String toXML(int i) { 223 throw new AssertionError (); 224 } 225 226 public void unregister() { 227 throw new AssertionError (); 228 } 229 230 } 231 232 } 233 | Popular Tags |