Author: richard.opalka(a)jboss.com
Date: 2009-09-25 05:54:36 -0400 (Fri, 25 Sep 2009)
New Revision: 10776
Added:
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/security/
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/security/DefaultSecurityAdapterFactory.java
Modified:
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java
Log:
[JBWS-2773] providing default SecurityAdaptorFactory
Modified:
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java
===================================================================
---
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java 2009-09-25
09:52:25 UTC (rev 10775)
+++
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java 2009-09-25
09:54:36 UTC (rev 10776)
@@ -28,6 +28,7 @@
import org.jboss.wsf.framework.http.DefaultHttpServerFactory;
import org.jboss.wsf.framework.invocation.DefaultResourceInjectorFactory;
import org.jboss.wsf.framework.management.DefaultEndpointMetricsFactory;
+import org.jboss.wsf.framework.security.DefaultSecurityAdapterFactory;
import org.jboss.wsf.framework.serviceref.DefaultServiceRefHandlerFactory;
import org.jboss.wsf.framework.serviceref.DefaultServiceRefMetaDataParserFactory;
import org.jboss.wsf.spi.SPIProvider;
@@ -37,24 +38,16 @@
import org.jboss.wsf.spi.deployment.LifecycleHandlerFactory;
import org.jboss.wsf.spi.http.HttpContextFactory;
import org.jboss.wsf.spi.http.HttpServerFactory;
-import org.jboss.wsf.spi.invocation.InvocationHandlerFactory;
-import org.jboss.wsf.spi.invocation.RequestHandlerFactory;
import org.jboss.wsf.spi.invocation.ResourceInjectorFactory;
import org.jboss.wsf.spi.invocation.SecurityAdaptorFactory;
-import org.jboss.wsf.spi.invocation.WebServiceContextFactory;
-import org.jboss.wsf.spi.ioc.IoCContainerProxyFactory;
import org.jboss.wsf.spi.management.EndpointMetricsFactory;
-import org.jboss.wsf.spi.management.EndpointRegistryFactory;
-import org.jboss.wsf.spi.management.ServerConfigFactory;
-import org.jboss.wsf.spi.management.StackConfigFactory;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.ServiceRefMetaDataParserFactory;
-import org.jboss.wsf.spi.serviceref.ServiceRefBinderFactory;
import org.jboss.wsf.spi.serviceref.ServiceRefHandlerFactory;
import org.jboss.wsf.spi.util.ServiceLoader;
/**
- * @author Thomas.Diesler(a)jboss.com
- * @since 13-Aug-2007
+ * @author <a href="mailto:tdiesler@redhat.com">Thomas Diesler</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
class DefaultSPIProvider extends SPIProvider
{
@@ -66,83 +59,52 @@
{
T returnType = null;
- // SPI provided by framework, default that can be overridden
-
+ // SPIs provided by framework, defaults can be overridden
if (DeploymentAspectManagerFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultDeploymentAspectManagerFactory.class.getName());
+ returnType = loadService(spiType, DefaultDeploymentAspectManagerFactory.class);
}
if (DeploymentModelFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultDeploymentModelFactory.class.getName());
+ returnType = loadService(spiType, DefaultDeploymentModelFactory.class);
}
else if (EndpointMetricsFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultEndpointMetricsFactory.class.getName());
+ returnType = loadService(spiType, DefaultEndpointMetricsFactory.class);
}
else if (HttpContextFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultHttpContextFactory.class.getName());
+ returnType = loadService(spiType, DefaultHttpContextFactory.class);
}
else if (HttpServerFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType, DefaultHttpServerFactory.class.getName());
+ returnType = loadService(spiType, DefaultHttpServerFactory.class);
}
else if (LifecycleHandlerFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultLifecycleHandlerFactory.class.getName());
+ returnType = loadService(spiType, DefaultLifecycleHandlerFactory.class);
}
else if (ResourceInjectorFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultResourceInjectorFactory.class.getName());
+ returnType = loadService(spiType, DefaultResourceInjectorFactory.class);
}
else if (ServiceRefHandlerFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultServiceRefHandlerFactory.class.getName());
+ returnType = loadService(spiType, DefaultServiceRefHandlerFactory.class);
}
else if (ServiceRefMetaDataParserFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType,
DefaultServiceRefMetaDataParserFactory.class.getName());
+ returnType = loadService(spiType,
DefaultServiceRefMetaDataParserFactory.class);
}
-
- // SPI provided by either container or stack integration
-
- else if (StackConfigFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
- else if (ServerConfigFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
- else if (EndpointRegistryFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
- else if (InvocationHandlerFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
- else if (RequestHandlerFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
else if (SecurityAdaptorFactory.class.equals(spiType))
{
- returnType = (T)loadService(spiType, null);
+ returnType = loadService(spiType, DefaultSecurityAdapterFactory.class);
}
- else if (ServiceRefBinderFactory.class.equals(spiType))
+ else
{
+ // SPI provided by either container or stack integration that has no default
implementation
returnType = (T)loadService(spiType, null);
}
- else if (WebServiceContextFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
- else if (IoCContainerProxyFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
if (returnType == null)
throw new WSFException("Failed to provide SPI '" + spiType +
"'");
@@ -151,8 +113,11 @@
}
// Load SPI implementation through ServiceLoader
- private <T> T loadService(Class<T> spiType, String defaultImpl)
+ @SuppressWarnings("unchecked")
+ private <T> T loadService(Class<T> spiType, Class<?> defaultImpl)
{
- return (T)ServiceLoader.loadService(spiType.getName(), defaultImpl);
+ final String defaultImplName = defaultImpl != null ? defaultImpl.getName() : null;
+ return (T)ServiceLoader.loadService(spiType.getName(), defaultImplName);
}
+
}
Modified:
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java
===================================================================
---
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java 2009-09-25
09:52:25 UTC (rev 10775)
+++
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java 2009-09-25
09:54:36 UTC (rev 10776)
@@ -25,13 +25,24 @@
import org.jboss.wsf.spi.SPIProviderResolver;
/**
- * @author Heiko.Braun(a)jboss.com
- * Created: Jul 18, 2007
+ * TODO: javadoc
+ *
+ * @author <a href="mailto:hbraun@redhat.com">Heiko Braun</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
-public class DefaultSPIProviderResolver extends SPIProviderResolver
+public final class DefaultSPIProviderResolver extends SPIProviderResolver
{
+
+ private static final SPIProvider SPI_PROVIDER = new DefaultSPIProvider();
+
+ public DefaultSPIProviderResolver()
+ {
+ super();
+ }
+
public SPIProvider getProvider()
{
- return new DefaultSPIProvider();
+ return DefaultSPIProviderResolver.SPI_PROVIDER;
}
+
}
Added:
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/security/DefaultSecurityAdapterFactory.java
===================================================================
---
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/security/DefaultSecurityAdapterFactory.java
(rev 0)
+++
framework/branches/ropalka/src/main/java/org/jboss/wsf/framework/security/DefaultSecurityAdapterFactory.java 2009-09-25
09:54:36 UTC (rev 10776)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.wsf.framework.security;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.jboss.wsf.spi.invocation.SecurityAdaptor;
+import org.jboss.wsf.spi.invocation.SecurityAdaptorFactory;
+
+/**
+ * TODO: javadoc
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+public final class DefaultSecurityAdapterFactory extends SecurityAdaptorFactory
+{
+
+ private static SecurityAdaptor SECURITY_ADAPTOR = new DefaultSecurityAdaptor();
+
+ /**
+ * Constructor.
+ */
+ public DefaultSecurityAdapterFactory()
+ {
+ super();
+ }
+
+ /**
+ * Creates new security adapter instance.
+ *
+ * @return security adapter
+ */
+ public SecurityAdaptor newSecurityAdapter()
+ {
+ return DefaultSecurityAdapterFactory.SECURITY_ADAPTOR;
+ }
+
+ private static class DefaultSecurityAdaptor implements SecurityAdaptor
+ {
+
+ private static ThreadLocal<Principal> principal = new
ThreadLocal<Principal>();
+ private static ThreadLocal<Object> credential = new
ThreadLocal<Object>();
+
+ public Object getCredential()
+ {
+ return DefaultSecurityAdaptor.credential.get();
+ }
+
+ public Principal getPrincipal()
+ {
+ return DefaultSecurityAdaptor.principal.get();
+ }
+
+ public void pushSubjectContext(Subject subject, Principal principal, Object
credential)
+ {
+ // does nothing
+ }
+
+ public void setCredential(Object credential)
+ {
+ DefaultSecurityAdaptor.credential.set(credential);
+ }
+
+ public void setPrincipal(Principal principal)
+ {
+ DefaultSecurityAdaptor.principal.set(principal);
+ }
+
+ }
+
+}