Author: thomas.diesler(a)jboss.com
Date: 2007-01-21 13:51:37 -0500 (Sun, 21 Jan 2007)
New Revision: 2018
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWebServiceContext.java
Removed:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextImpl.java
Modified:
trunk/build/version.properties
trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextInjector.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvokerJSE.java
trunk/jbossws-tests/src/main/resources/jaxws/context/WEB-INF/jboss-web.xml
Log:
Implement WebServiceContext.getUserPrincipal(), isUserInRole() for JSE
Modified: trunk/build/version.properties
===================================================================
--- trunk/build/version.properties 2007-01-21 17:53:05 UTC (rev 2017)
+++ trunk/build/version.properties 2007-01-21 18:51:37 UTC (rev 2018)
@@ -6,7 +6,7 @@
specification.version=jbossws-2.0
version.id=1.2.0.CR3
-repository.id=1.2.0.CR3
+repository.id=snapshot
implementation.title=JBoss Web Services (JBossWS)
implementation.url=http://www.jboss.org/products/jbossws
Modified:
trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java
===================================================================
---
trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java 2007-01-21
17:53:05 UTC (rev 2017)
+++
trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointInvokerEJB3.java 2007-01-21
18:51:37 UTC (rev 2018)
@@ -44,7 +44,7 @@
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.EndpointInvocation;
import org.jboss.ws.core.jaxrpc.handler.SOAPMessageContextJAXRPC;
-import org.jboss.ws.core.jaxws.WebServiceContextImpl;
+import org.jboss.ws.core.jaxws.AbstractWebServiceContext;
import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
import org.jboss.ws.core.server.AbstractServiceEndpointInvoker;
import org.jboss.ws.core.server.ServiceEndpointInfo;
@@ -173,7 +173,7 @@
if (beanProp != null)
{
EJBContext ejbCtx = beanCtx.getEJBContext();
- beanProp.set(beanCtx.getInstance(), new
EJB3WebServiceContextImpl(jaxwsMessageContext, ejbCtx));
+ beanProp.set(beanCtx.getInstance(), new
WebServiceContextEJB(jaxwsMessageContext, ejbCtx));
}
}
@@ -190,11 +190,11 @@
/** Delegate to EJBContext
*/
- class EJB3WebServiceContextImpl extends WebServiceContextImpl
+ class WebServiceContextEJB extends AbstractWebServiceContext
{
private EJBContext ejbContext;
- public EJB3WebServiceContextImpl(MessageContext messageContext, EJBContext
ejbContext)
+ public WebServiceContextEJB(MessageContext messageContext, EJBContext ejbContext)
{
super(messageContext);
this.ejbContext = ejbContext;
Copied:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWebServiceContext.java
(from rev 2015,
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextImpl.java)
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWebServiceContext.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWebServiceContext.java 2007-01-21
18:51:37 UTC (rev 2018)
@@ -0,0 +1,69 @@
+/*
+ * 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.core.jaxws;
+
+import java.security.Principal;
+
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.util.NotImplementedException;
+import org.w3c.dom.Element;
+
+/**
+ * A WebServiceContext makes it possible for a web service endpoint implementation
+ * class to access message context and security information relative to a request
+ * being served. Typically a WebServiceContext is injected into an endpoint
implementation
+ * class using the Resource annotation.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 03-May-2006
+ */
+public abstract class AbstractWebServiceContext implements WebServiceContext
+{
+ private MessageContext messageContext;
+
+ public AbstractWebServiceContext(MessageContext messageContext)
+ {
+ this.messageContext = messageContext;
+ }
+
+ public MessageContext getMessageContext()
+ {
+ return messageContext;
+ }
+
+ public abstract Principal getUserPrincipal();
+
+ public abstract boolean isUserInRole(String role);
+
+ public EndpointReference getEndpointReference(Element... referenceParameters)
+ {
+ throw new NotImplementedException();
+ }
+
+ public <T extends EndpointReference> T getEndpointReference(Class<T>
clazz, Element... referenceParameters)
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
Deleted:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextImpl.java 2007-01-21
17:53:05 UTC (rev 2017)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextImpl.java 2007-01-21
18:51:37 UTC (rev 2018)
@@ -1,76 +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.core.jaxws;
-
-import java.security.Principal;
-
-import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServiceContext;
-import javax.xml.ws.handler.MessageContext;
-
-import org.jboss.util.NotImplementedException;
-import org.w3c.dom.Element;
-
-/**
- * A WebServiceContext makes it possible for a web service endpoint implementation
- * class to access message context and security information relative to a request
- * being served. Typically a WebServiceContext is injected into an endpoint
implementation
- * class using the Resource annotation.
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 03-May-2006
- */
-public class WebServiceContextImpl implements WebServiceContext
-{
- private MessageContext messageContext;
-
-
- public WebServiceContextImpl(MessageContext messageContext)
- {
- this.messageContext = messageContext;
- }
-
- public MessageContext getMessageContext()
- {
- return messageContext;
- }
-
- public Principal getUserPrincipal()
- {
- throw new NotImplementedException();
- }
-
- public boolean isUserInRole(String role)
- {
- throw new NotImplementedException();
- }
-
- public EndpointReference getEndpointReference(Element... referenceParameters)
- {
- throw new NotImplementedException();
- }
-
- public <T extends EndpointReference> T getEndpointReference(Class<T>
clazz, Element... referenceParameters)
- {
- throw new NotImplementedException();
- }
-}
\ No newline at end of file
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextInjector.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextInjector.java 2007-01-21
17:53:05 UTC (rev 2017)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextInjector.java 2007-01-21
18:51:37 UTC (rev 2018)
@@ -25,13 +25,20 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.security.Principal;
+import java.util.HashSet;
+import java.util.Set;
import javax.annotation.Resource;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import org.jboss.logging.Logger;
-import org.jboss.ws.core.jaxws.WebServiceContextImpl;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
/**
* Inject the JAXWS WebServiceContext
@@ -44,9 +51,9 @@
// provide logging
private static Logger log = Logger.getLogger(WebServiceContextInjector.class);
- public static void injectContext(Object epImpl, MessageContext msgContext)
+ public void injectContext(Object epImpl, MessageContext msgContext)
{
- WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgContext);
+ AbstractWebServiceContext webServiceContext = new
WebServiceContextJSE(msgContext);
try
{
// scan fields that are marked with @Resource
@@ -82,4 +89,54 @@
log.warn("Cannot inject WebServiceContext", ex);
}
}
+
+ class WebServiceContextJSE extends AbstractWebServiceContext
+ {
+ private RealmMapping realmMapping;
+
+ public WebServiceContextJSE(MessageContext messageContext)
+ {
+ super(messageContext);
+ }
+
+ @Override
+ public Principal getUserPrincipal()
+ {
+ Principal principal = SecurityAssociation.getCallerPrincipal();
+ return principal;
+ }
+
+ @Override
+ public boolean isUserInRole(String role)
+ {
+ boolean isUserInRole = false;
+ Principal principal = SecurityAssociation.getCallerPrincipal();
+ RealmMapping realmMapping = getRealmMapping();
+ if (realmMapping != null && principal != null)
+ {
+ Set<Principal> roles = new HashSet<Principal>();
+ roles.add(new SimplePrincipal(role));
+ isUserInRole = realmMapping.doesUserHaveRole(principal, roles);
+ }
+ return isUserInRole;
+ }
+
+ private RealmMapping getRealmMapping()
+ {
+ if (realmMapping == null)
+ {
+ String lookupName = "java:comp/env/security/realmMapping";
+ try
+ {
+ InitialContext iniCtx = new InitialContext();
+ realmMapping = (RealmMapping) iniCtx.lookup(lookupName);
+ }
+ catch (NamingException e)
+ {
+ log.debug("Cannot obtain realm mapping from: " + lookupName);
+ }
+ }
+ return realmMapping;
+ }
+ }
}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvokerJSE.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvokerJSE.java 2007-01-21
17:53:05 UTC (rev 2017)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvokerJSE.java 2007-01-21
18:51:37 UTC (rev 2018)
@@ -89,7 +89,7 @@
{
CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
if (msgContext instanceof SOAPMessageContextJAXWS)
- WebServiceContextInjector.injectContext(seiImpl,
(SOAPMessageContextJAXWS)msgContext);
+ new WebServiceContextInjector().injectContext(seiImpl,
(SOAPMessageContextJAXWS)msgContext);
Class implClass = seiImpl.getClass();
Method seiMethod = epInv.getJavaMethod();
Modified: trunk/jbossws-tests/src/main/resources/jaxws/context/WEB-INF/jboss-web.xml
===================================================================
--- trunk/jbossws-tests/src/main/resources/jaxws/context/WEB-INF/jboss-web.xml 2007-01-21
17:53:05 UTC (rev 2017)
+++ trunk/jbossws-tests/src/main/resources/jaxws/context/WEB-INF/jboss-web.xml 2007-01-21
18:51:37 UTC (rev 2018)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
+<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>
- <security-domain>JBossWS</security-domain>
+ <security-domain>java:/jaas/JBossWS</security-domain>
</jboss-web>
\ No newline at end of file