1 23 package com.sun.enterprise.webservice; 24 25 import java.util.logging.*; 26 import java.security.PrivilegedActionException ; 27 import java.security.PrivilegedExceptionAction ; 28 29 import java.lang.reflect.Method ; 30 31 import javax.xml.soap.SOAPMessage ; 32 33 import javax.security.auth.Subject ; 34 35 import com.sun.enterprise.security.jauth.*; 36 37 import com.sun.xml.rpc.spi.runtime.Implementor; 38 import com.sun.xml.rpc.spi.runtime.SOAPMessageContext; 39 import com.sun.xml.rpc.spi.runtime.StreamingHandler; 40 import com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate; 41 import com.sun.xml.rpc.spi.runtime.Tie; 42 43 45 import com.sun.enterprise.security.SecurityContext; 46 import com.sun.enterprise.security.jauth.ServerAuthConfig; 47 import com.sun.enterprise.security.wss.WebServiceSecurity; 48 49 import com.sun.logging.*; 50 51 import com.sun.enterprise.util.i18n.StringManager; 52 53 63 64 public class ServletSystemHandlerDelegate implements SystemHandlerDelegate { 65 66 protected static Logger _logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 67 68 private static final String IMPLEMENTOR = 69 "com.sun.xml.rpc.server.http.Implementor"; 70 private static final String SERVER_AUTH_CONTEXT = 71 "com.sun.enterprise.security.jauth.ServerAuthContext"; 72 73 private static StringManager localStrings = StringManager.getManager(ServletSystemHandlerDelegate.class); 75 76 ServerAuthConfig config_; 77 78 public ServletSystemHandlerDelegate(ServerAuthConfig config) { 79 config_ = config; 80 } 81 82 126 public boolean processRequest(SOAPMessageContext messageContext) { 127 128 if(_logger.isLoggable(Level.FINE)){ 129 _logger.fine("ws.processRequest"); 130 } 131 132 final SOAPMessageContext finalMC = messageContext; 133 Implementor implementor = (Implementor) messageContext.getProperty( IMPLEMENTOR ); 134 final Tie tie = implementor.getTie(); 135 StreamingHandler handler = (StreamingHandler) implementor.getTie(); 136 SOAPMessage request = finalMC.getMessage(); 137 final ServerAuthContext sAC = config_.getAuthContext(handler,request); 138 139 boolean status = true; 140 try { 141 if (sAC != null) { 142 status = false; 143 status = WebServiceSecurity.validateRequest(finalMC,sAC); 145 146 if (status) { 147 messageContext.setProperty(SERVER_AUTH_CONTEXT, sAC); 148 } 149 } 150 } catch (AuthException ae) { 151 _logger.log(Level.SEVERE, "ws.error_validate_request", ae); 152 throw new RuntimeException (ae); 153 } finally { 154 WebServiceSecurity.auditInvocation(messageContext,status); 155 } 156 157 if (status) { 158 159 161 if (System.getSecurityManager() != null) { 162 163 168 status = false; 169 170 try { 171 172 Subject.doAsPrivileged 173 (SecurityContext.getCurrent().getSubject(), 174 new PrivilegedExceptionAction () { 175 public Object run() throws Exception { 176 tie.handle(finalMC); 177 processResponse(finalMC); 178 return null; 179 } 180 }, null); 181 182 } catch (PrivilegedActionException pae) { 183 Throwable cause = pae.getCause(); 184 if (cause instanceof AuthException){ 185 _logger.log(Level.SEVERE, "ws.error_secure_response", cause); 186 } 187 RuntimeException re = null; 188 if (cause instanceof RuntimeException ) { 189 re = (RuntimeException ) cause; 190 } else { 191 re = new RuntimeException (cause); 192 } 193 throw re; 194 } 195 } 196 } 197 return status; 198 } 199 200 216 public void processResponse(SOAPMessageContext messageContext) { 217 218 if(_logger.isLoggable(Level.FINE)){ 219 _logger.fine("ws.processResponse"); 220 } 221 222 ServerAuthContext sAC = 223 (ServerAuthContext) messageContext.getProperty( SERVER_AUTH_CONTEXT ); 224 225 if (sAC == null) { 226 return; 227 } 228 229 try { 230 WebServiceSecurity.secureResponse(messageContext,sAC); 231 } catch (AuthException ae) { 232 _logger.log(Level.SEVERE, "ws.error_secure_response", ae); 233 throw new RuntimeException (ae); 234 } 235 } 236 } 237 238 239 | Popular Tags |