Author: alessio.soldano(a)jboss.com
Date: 2008-03-14 09:55:13 -0400 (Fri, 14 Mar 2008)
New Revision: 5980
Removed:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/MessageContextConfigSelector.java
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxrpc/WSSecurityHandler.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxws/WSSecurityHandler.java
Log:
[JBWS-2022] better implementation, no changes to the interface
Deleted:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/MessageContextConfigSelector.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/MessageContextConfigSelector.java 2008-03-14
11:21:10 UTC (rev 5979)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/MessageContextConfigSelector.java 2008-03-14
13:55:13 UTC (rev 5980)
@@ -1,182 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ws.extensions.security;
-
-//$Id$
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPException;
-import javax.xml.ws.WebServiceException;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.CommonMessageContext;
-import org.jboss.ws.core.soap.SOAPMessageImpl;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.OperationMetaData;
-import org.jboss.ws.metadata.wsse.Config;
-import org.jboss.ws.metadata.wsse.Encrypt;
-import org.jboss.ws.metadata.wsse.Operation;
-import org.jboss.ws.metadata.wsse.Port;
-import org.jboss.ws.metadata.wsse.Requires;
-import org.jboss.ws.metadata.wsse.Sign;
-import org.jboss.ws.metadata.wsse.Timestamp;
-import org.jboss.ws.metadata.wsse.Username;
-import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
-
-/**
- * A Config whose attributes are derived from the specified message context.
- * This is useful to provide the WSSecurityDispatcher with the right config
- * according to the operation/port the current message is related to.
- *
- * @author alessio.soldano(a)jboss.com
- * @since 06-Mar-2008
- */
-public class MessageContextConfigSelector extends Config
-{
- private static Logger log = Logger.getLogger(MessageContextConfigSelector.class);
- private CommonMessageContext ctx;
- private WSSecurityConfiguration configuration;
- private Config config;
- private QName opName;
-
- public MessageContextConfigSelector(CommonMessageContext ctx)
- {
- this.ctx = ctx;
- this.configuration =
ctx.getEndpointMetaData().getServiceMetaData().getSecurityConfiguration();
- if (configuration == null)
- throw new WSException("Cannot obtain security configuration from message
context");
- this.config = new Config(); //empty config, no wsse requirements / processing
- }
-
- public Encrypt getEncrypt()
- {
- readConfig();
- return config.getEncrypt();
- }
-
- public Requires getRequires()
- {
- readConfig();
- return config.getRequires();
- }
-
- public Sign getSign()
- {
- readConfig();
- return config.getSign();
- }
-
- public Timestamp getTimestamp()
- {
- readConfig();
- return config.getTimestamp();
- }
-
- public Username getUsername()
- {
- readConfig();
- return config.getUsername();
- }
-
- /**
- * Gets the operation & port the current message is headed to and
- * use them to get the right config to use.
- *
- */
- private void readConfig()
- {
- //once the operation name is known the specific config
- //is not going to change
- if (opName == null)
- {
- EndpointMetaData epMetaData = ctx.getEndpointMetaData();
- QName port = epMetaData.getPortName();
-
- OperationMetaData opMetaData = ctx.getOperationMetaData();
- if (opMetaData == null)
- {
- // Get the operation meta data from the soap message
- // for the server side inbound message.
- SOAPMessageImpl soapMessage = (SOAPMessageImpl)ctx.getSOAPMessage();
- try
- {
- opMetaData = soapMessage.getOperationMetaData(epMetaData);
- }
- catch (SOAPException e)
- {
- throw new WebServiceException("Error while looking for the operation
meta data: " + e);
- }
- }
- if (opMetaData != null)
- opName = opMetaData.getQName();
-
- Config opConfig = getConfig(port, opName);
- log.debug("WS-Security config: " + opConfig);
- if (opConfig != null)
- this.config = opConfig;
- }
- }
-
- private Config getConfig(QName portName, QName opName)
- {
- Port port = configuration.getPorts().get(portName != null ? portName.getLocalPart()
: null);
- if (port == null)
- return configuration.getDefaultConfig();
-
- Operation operation = port.getOperations().get(opName != null ? opName.toString() :
null);
- if (operation == null)
- {
- //if the operation name was not available or didn't match any wsse
configured operation,
- //we fall back to the port wsse config (if available) or the default config.
- Config portConfig = port.getDefaultConfig();
- return (portConfig == null) ? configuration.getDefaultConfig() : portConfig;
-
- }
- return operation.getConfig();
- }
-
- public void setEncrypt(Encrypt encrypt)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setSign(Sign sign)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setTimestamp(Timestamp timestamp)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setUsername(Username username)
- {
- throw new UnsupportedOperationException();
- }
-
- public void setRequires(Requires requires)
- {
- throw new UnsupportedOperationException();
- }
-}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2008-03-14
11:21:10 UTC (rev 5979)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2008-03-14
13:55:13 UTC (rev 5980)
@@ -30,16 +30,19 @@
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.WebServiceException;
import org.jboss.logging.Logger;
+import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.CommonSOAPFaultException;
+import org.jboss.ws.core.soap.MessageContextAssociation;
+import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.extensions.security.exception.InvalidSecurityHeaderException;
import org.jboss.ws.extensions.security.exception.WSSecurityException;
import org.jboss.ws.extensions.security.nonce.DefaultNonceFactory;
import org.jboss.ws.extensions.security.nonce.NonceFactory;
import org.jboss.ws.extensions.security.operation.EncodingOperation;
import org.jboss.ws.extensions.security.operation.EncryptionOperation;
-//import org.jboss.ws.extensions.security.operation.OperationDescription;
import org.jboss.ws.extensions.security.operation.RequireEncryptionOperation;
import org.jboss.ws.extensions.security.operation.RequireOperation;
import org.jboss.ws.extensions.security.operation.RequireSignatureOperation;
@@ -47,8 +50,12 @@
import org.jboss.ws.extensions.security.operation.SendUsernameOperation;
import org.jboss.ws.extensions.security.operation.SignatureOperation;
import org.jboss.ws.extensions.security.operation.TimestampOperation;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.ws.metadata.wsse.Config;
import org.jboss.ws.metadata.wsse.Encrypt;
+import org.jboss.ws.metadata.wsse.Operation;
+import org.jboss.ws.metadata.wsse.Port;
import org.jboss.ws.metadata.wsse.RequireEncryption;
import org.jboss.ws.metadata.wsse.RequireSignature;
import org.jboss.ws.metadata.wsse.RequireTimestamp;
@@ -126,10 +133,58 @@
private static Config getActualConfig(WSSecurityConfiguration configuration, Config
operationConfig)
{
+ if (operationConfig == null)
+ {
+ //if no configuration override, we try getting the right operation config
+ //according to the invoked operation that can be found using the context
+ CommonMessageContext ctx = MessageContextAssociation.peekMessageContext();
+ if (ctx != null)
+ {
+ EndpointMetaData epMetaData = ctx.getEndpointMetaData();
+ QName port = epMetaData.getPortName();
+
+ OperationMetaData opMetaData = ctx.getOperationMetaData();
+ if (opMetaData == null)
+ {
+ // Get the operation meta data from the soap message
+ // for the server side inbound message.
+ SOAPMessageImpl soapMessage = (SOAPMessageImpl)ctx.getSOAPMessage();
+ try
+ {
+ opMetaData = soapMessage.getOperationMetaData(epMetaData);
+ }
+ catch (SOAPException e)
+ {
+ throw new WebServiceException("Error while looking for the
operation meta data: " + e);
+ }
+ }
+ if (opMetaData != null)
+ operationConfig = selectOperationConfig(configuration, port,
opMetaData.getQName());
+ }
+ }
//null operationConfig means default behavior
return operationConfig != null ? operationConfig :
configuration.getDefaultConfig();
}
+ private static Config selectOperationConfig(WSSecurityConfiguration configuration,
QName portName, QName opName)
+ {
+ Port port = configuration.getPorts().get(portName != null ? portName.getLocalPart()
: null);
+ if (port == null)
+ return configuration.getDefaultConfig();
+
+ Operation operation = port.getOperations().get(opName != null ? opName.toString() :
null);
+ if (operation == null)
+ {
+ //if the operation name was not available or didn't match any wsse
configured operation,
+ //we fall back to the port wsse config (if available) or the default config.
+ Config portConfig = port.getDefaultConfig();
+ return (portConfig == null) ? configuration.getDefaultConfig() : portConfig;
+
+ }
+ return operation.getConfig();
+ }
+
+
private static boolean hasRequirements(Config config)
{
return config != null && config.getRequires() != null;
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxrpc/WSSecurityHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxrpc/WSSecurityHandler.java 2008-03-14
11:21:10 UTC (rev 5979)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxrpc/WSSecurityHandler.java 2008-03-14
13:55:13 UTC (rev 5980)
@@ -36,7 +36,6 @@
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.extensions.security.Constants;
-import org.jboss.ws.extensions.security.MessageContextConfigSelector;
import org.jboss.ws.extensions.security.WSSecurityDispatcher;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ServiceMetaData;
@@ -70,7 +69,7 @@
CommonMessageContext ctx = (CommonMessageContext)msgContext;
SOAPMessageImpl soapMessage = (SOAPMessageImpl)ctx.getSOAPMessage();
- new WSSecurityDispatcher().decodeMessage(configuration, soapMessage, new
MessageContextConfigSelector(ctx));
+ new WSSecurityDispatcher().decodeMessage(configuration, soapMessage, null);
}
}
catch (SOAPException ex)
@@ -93,7 +92,7 @@
String user = (String)ctx.get(Stub.USERNAME_PROPERTY);
String pass = (String)ctx.get(Stub.PASSWORD_PROPERTY);
- new WSSecurityDispatcher().encodeMessage(configuration, soapMessage, new
MessageContextConfigSelector(ctx), user, pass);
+ new WSSecurityDispatcher().encodeMessage(configuration, soapMessage, null,
user, pass);
}
}
catch (SOAPException ex)
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxws/WSSecurityHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxws/WSSecurityHandler.java 2008-03-14
11:21:10 UTC (rev 5979)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/jaxws/WSSecurityHandler.java 2008-03-14
13:55:13 UTC (rev 5980)
@@ -39,7 +39,6 @@
import org.jboss.ws.core.jaxws.handler.GenericSOAPHandler;
import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.extensions.security.Constants;
-import org.jboss.ws.extensions.security.MessageContextConfigSelector;
import org.jboss.ws.extensions.security.WSSecurityDispatcher;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ServiceMetaData;
@@ -81,8 +80,7 @@
{
CommonMessageContext ctx = (CommonMessageContext)msgContext;
SOAPMessageImpl soapMessage = (SOAPMessageImpl)ctx.getSOAPMessage();
-
- new WSSecurityDispatcher().decodeMessage(configuration, soapMessage, new
MessageContextConfigSelector(ctx));
+ new WSSecurityDispatcher().decodeMessage(configuration, soapMessage, null);
}
}
catch (SOAPException ex)
@@ -105,7 +103,7 @@
String user = (String)ctx.get(BindingProvider.USERNAME_PROPERTY);
String pass = (String)ctx.get(BindingProvider.PASSWORD_PROPERTY);
- new WSSecurityDispatcher().encodeMessage(configuration, soapMessage, new
MessageContextConfigSelector(ctx), user, pass);
+ new WSSecurityDispatcher().encodeMessage(configuration, soapMessage, null,
user, pass);
}
}
catch (SOAPException ex)