Author: chris.laprun(a)jboss.com
Date: 2010-04-14 16:16:55 -0400 (Wed, 14 Apr 2010)
New Revision: 2642
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
Log:
- GTNWSRP-26: Perform minimal sanitization of consumer name before it's transformed
into an id.
- Added RegistrationPolicyWrapper so that minimal sanitization is performed even on
non-controlled RegistrationPolicy implementations.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2010-04-14
15:35:52 UTC (rev 2641)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2010-04-14
20:16:55 UTC (rev 2642)
@@ -107,7 +107,7 @@
// check with policy if we allow the consumer
policy.validateConsumerName(name);
- String identity = policy.getConsumerIdFrom(name, Collections.EMPTY_MAP);
+ String identity = policy.getConsumerIdFrom(name, Collections.<QName,
Object>emptyMap());
Consumer consumer = persistenceManager.createConsumer(identity, name);
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2010-04-14
15:35:52 UTC (rev 2641)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2010-04-14
20:16:55 UTC (rev 2642)
@@ -162,11 +162,10 @@
return null;
}
- /** Simply returns the given consumer name, trusted (!) to be unique. */
+ /** Compute a simple, safe id based on the provided consumer name trusted (!) to be
unique. */
public String getConsumerIdFrom(String consumerName, Map<QName, Object>
registrationProperties) throws IllegalArgumentException, InvalidConsumerDataException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
- return consumerName;
+ return RegistrationPolicyWrapper.sanitizeConsumerName(consumerName);
}
/** Rejects registration if a Consumer with the specified name already exists. */
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java 2010-04-14
20:16:55 UTC (rev 2642)
@@ -0,0 +1,110 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, 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.gatein.registration.policies;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.registration.InvalidConsumerDataException;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.wsrp.registration.PropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class RegistrationPolicyWrapper implements RegistrationPolicy
+{
+ private final RegistrationPolicy delegate;
+
+ public RegistrationPolicyWrapper(RegistrationPolicy delegate)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(delegate,
"Delegate");
+ this.delegate = delegate;
+ }
+
+ public void validateRegistrationDataFor(Map<QName, Object>
registrationProperties, String consumerIdentity)
+ throws IllegalArgumentException, RegistrationException
+ {
+ delegate.validateRegistrationDataFor(registrationProperties, consumerIdentity);
+ }
+
+ public String createRegistrationHandleFor(String registrationId)
+ throws IllegalArgumentException
+ {
+ return delegate.createRegistrationHandleFor(registrationId);
+ }
+
+ public String getAutomaticGroupNameFor(String consumerName)
+ throws IllegalArgumentException
+ {
+ return delegate.getAutomaticGroupNameFor(consumerName);
+ }
+
+ public String getConsumerIdFrom(String consumerName, Map<QName, Object>
registrationProperties)
+ throws IllegalArgumentException, InvalidConsumerDataException
+ {
+ return delegate.getConsumerIdFrom(sanitizeConsumerName(consumerName),
registrationProperties);
+ }
+
+ public void validateConsumerName(String consumerName)
+ throws IllegalArgumentException, RegistrationException
+ {
+ delegate.validateConsumerName(consumerName);
+ }
+
+ public void validateConsumerGroupName(String groupName)
+ throws IllegalArgumentException, RegistrationException
+ {
+ delegate.validateConsumerGroupName(groupName);
+ }
+
+ public RegistrationManager getManager()
+ {
+ return delegate.getManager();
+ }
+
+ public void setManager(RegistrationManager manager)
+ {
+ delegate.setManager(manager);
+ }
+
+ public void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions)
+ {
+ delegate.setExpectations(registrationPropertyDescriptions);
+ }
+
+ static String sanitizeConsumerName(String consumerName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
+ consumerName = consumerName.trim();
+ consumerName = consumerName.replaceAll(",", "_");
+ consumerName = consumerName.replaceAll(" ", "_");
+ consumerName = consumerName.replaceAll("/", "_");
+
+ return consumerName;
+ }
+}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2010-04-14
15:35:52 UTC (rev 2641)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2010-04-14
20:16:55 UTC (rev 2642)
@@ -29,6 +29,7 @@
import org.gatein.registration.RegistrationPropertyChangeListener;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
import org.gatein.registration.policies.DefaultRegistrationPropertyValidator;
+import org.gatein.registration.policies.RegistrationPolicyWrapper;
import org.gatein.registration.policies.RegistrationPropertyValidator;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
@@ -301,7 +302,11 @@
throw new IllegalArgumentException("Policy class does not implement
RegistrationPolicy!");
}
RegistrationPolicy policy = (RegistrationPolicy)policyClass.newInstance();
- setPolicy(policy);
+
+ // wrap policy so that we can perform minimal sanitization of values
+ RegistrationPolicyWrapper wrapper = new RegistrationPolicyWrapper(policy);
+
+ setPolicy(wrapper);
}
catch (ClassNotFoundException e)
{