1 23 24 29 30 package com.sun.enterprise.webservice; 31 32 import javax.xml.rpc.handler.Handler ; 33 import javax.xml.rpc.handler.MessageContext ; 34 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 35 import javax.xml.rpc.JAXRPCException ; 36 import javax.xml.namespace.QName ; 37 import javax.xml.soap.SOAPMessage ; 38 import java.util.logging.*; 39 import java.util.Map ; 40 import java.util.HashMap ; 41 42 import com.sun.enterprise.security.jauth.*; 44 import com.sun.enterprise.security.jauth.ClientAuthConfig; 45 import com.sun.enterprise.security.wss.WebServiceSecurity; 46 47 import com.sun.enterprise.Switch; 48 49 import com.sun.logging.*; 50 51 60 public class MessageLayerClientHandler implements Handler { 61 62 private static Logger _logger=null; 63 static { 64 _logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER); 65 } 66 67 public static final String CLIENT_AUTH_CONFIG = 69 "com.sun.enterprise.security.wss.ClientAuthConfig"; 70 71 private static final String CLIENT_AUTH_CONTEXT = 73 "com.sun.enterprise.security.jauth.ClientAuthContext"; 74 75 private static String errMsg = 76 "Client WSS Handler: MessageContext not of type SOAPMessageContext"; 77 78 private ClientAuthConfig config_ = null; 79 80 private QName qname[] = null; 81 82 private boolean isAppclientContainer = false; 83 84 private QName serviceName = null; 85 86 87 public MessageLayerClientHandler() { 88 int containerType = Switch.getSwitch().getContainerType(); 89 if(containerType == Switch.APPCLIENT_CONTAINER){ 90 isAppclientContainer = true; 91 } else{ 92 isAppclientContainer = false; 93 } 94 } 95 96 public boolean handleFault(MessageContext messageContext) { 97 if(_logger.isLoggable(Level.FINE)){ 99 _logger.log(Level.FINE, "wss-auth-client: ClientHandler does not handle" + 100 " SOAP faults"); 101 } 102 return true; 103 } 104 105 public boolean handleRequest(MessageContext messageContext) { 106 boolean retValue; 107 if(!isSoapMessageContext(messageContext)){ 108 throw new JAXRPCException (errMsg); 110 } 111 if (config_ == null) { 112 return true; 113 } 114 115 SOAPMessageContext smc = (SOAPMessageContext ) messageContext; 117 SOAPMessage request = smc.getMessage(); 118 ClientAuthContext cAC = config_.getAuthContext(null,request); 119 if (cAC == null) { 120 return true; 121 } 122 123 smc.setProperty(CLIENT_AUTH_CONTEXT, cAC); 124 smc.setProperty(javax.xml.ws.handler.MessageContext.WSDL_SERVICE, 125 serviceName); 126 127 try{ 128 WebServiceSecurity.secureRequest(smc,cAC,isAppclientContainer); 129 } catch(Exception e){ 130 if (_logger.isLoggable(Level.WARNING)){ 131 _logger.log(Level.WARNING, "ws.error_secure_request", e); 132 } 133 throw new JAXRPCException (e); 134 } 135 return true; 136 } 137 138 public boolean handleResponse(MessageContext messageContext) { 139 boolean retValue; 140 if(!isSoapMessageContext(messageContext)){ 141 throw new JAXRPCException (errMsg); 143 } 144 if (config_ == null) { 145 return true; 146 } 147 148 SOAPMessageContext smc = (SOAPMessageContext ) messageContext; 150 ClientAuthContext cAC = 151 (ClientAuthContext) smc.getProperty(CLIENT_AUTH_CONTEXT); 152 if (cAC == null) { 153 return true; 154 } 155 156 try{ 157 retValue = WebServiceSecurity.validateResponse(smc,cAC); 158 }catch(Exception e){ 159 if (_logger.isLoggable(Level.WARNING)){ 160 _logger.log(Level.WARNING, "ws.error_validate_response", e); 161 } 162 throw new JAXRPCException (e); 163 } 164 165 return retValue; 166 } 167 168 public javax.xml.namespace.QName [] getHeaders() { 172 return qname; 173 } 174 175 public void destroy() { 176 qname = null; 177 } 178 179 public void init(javax.xml.rpc.handler.HandlerInfo info) { 180 qname = info.getHeaders(); 182 config_ = (ClientAuthConfig) info.getHandlerConfig().get(CLIENT_AUTH_CONFIG); 183 serviceName = (QName )info.getHandlerConfig().get(javax.xml.ws.handler.MessageContext.WSDL_SERVICE); 184 } 185 186 189 private boolean isSoapMessageContext(MessageContext mc){ 190 boolean retValue = 191 (mc instanceof SOAPMessageContext )? true: false; 192 if(!retValue && _logger.isLoggable(Level.WARNING)){ 193 _logger.log(Level.WARNING, "ws.error_not_soap"); 194 } 195 return retValue; 196 } 197 198 } 199 | Popular Tags |