Author: thomas.diesler(a)jboss.com
Date: 2007-01-23 07:37:52 -0500 (Tue, 23 Jan 2007)
New Revision: 2033
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextEJB.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextJSE.java
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/context/EndpointNoInjectEJB.java
Log:
Provide workaround for: [JBWS-1468] - @Resource WebServiceContext for jbossas-4.x
Added: trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextEJB.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextEJB.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextEJB.java 2007-01-23
12:37:52 UTC (rev 2033)
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+// $Id$
+
+import java.security.Principal;
+
+import javax.ejb.EJBContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A WebServiceContext implementation that delegates to the EJBContext.
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 23-Jan-2007
+ */
+public class WebServiceContextEJB extends AbstractWebServiceContext
+{
+ // provide logging
+ private Logger log = Logger.getLogger(WebServiceContextEJB.class);
+
+ private EJBContext ejbContext;
+
+ public WebServiceContextEJB(MessageContext messageContext, EJBContext ejbContext)
+ {
+ super(messageContext);
+ this.ejbContext = ejbContext;
+ }
+
+ @Override
+ public Principal getUserPrincipal()
+ {
+ Principal principal = ejbContext.getCallerPrincipal();
+ return principal;
+ }
+
+ @Override
+ public boolean isUserInRole(String role)
+ {
+ boolean isUserInRole = ejbContext.isCallerInRole(role);
+ return isUserInRole;
+ }
+}
Property changes on:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextEJB.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextJSE.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextJSE.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextJSE.java 2007-01-23
12:37:52 UTC (rev 2033)
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+// $Id$
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * A WebServiceContext implementation that delegates to jbosssx.
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 23-Jan-2007
+ */
+public class WebServiceContextJSE extends AbstractWebServiceContext
+{
+ // provide logging
+ private Logger log = Logger.getLogger(WebServiceContextJSE.class);
+
+ 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;
+ }
+}
Property changes on:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WebServiceContextJSE.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/context/EndpointNoInjectEJB.java
===================================================================
---
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/context/EndpointNoInjectEJB.java
(rev 0)
+++
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/context/EndpointNoInjectEJB.java 2007-01-23
12:37:52 UTC (rev 2033)
@@ -0,0 +1,87 @@
+/*
+ * 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.test.ws.jaxws.context;
+
+// $Id$
+
+import java.security.Principal;
+
+import javax.annotation.Resource;
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.EJBContext;
+import javax.ejb.Stateless;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.Style;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.ws.annotation.WebContext;
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.jaxws.WebServiceContextEJB;
+import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
+import org.jboss.ws.core.soap.MessageContextAssociation;
+
+@WebService(name = "TestEndpoint", targetNamespace =
"http://org.jboss.ws/jaxws/context")
+@SOAPBinding(style = Style.RPC)
+@Stateless
+
+@WebContext(contextRoot = "/jaxws-context", urlPattern = "/*",
authMethod = "BASIC", transportGuarantee = "NONE", secureWSDLAccess =
false)
+@SecurityDomain("JBossWS")
+@RolesAllowed("friend")
+public class EndpointNoInjectEJB
+{
+ // @Resource
+ WebServiceContext wsCtx;
+
+ @Resource
+ EJBContext ejbCtx;
+
+ @WebMethod
+ public String testGetMessageContext()
+ {
+ // @Resource WebServiceContext for jbossas-4.x
+ //
http://jira.jboss.org/jira/browse/JBWS-1468
+ if (wsCtx == null)
+ {
+ CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
+ wsCtx = new WebServiceContextEJB((SOAPMessageContextJAXWS)msgContext, ejbCtx);
+ }
+
+ SOAPMessageContext jaxwsContext = (SOAPMessageContext)wsCtx.getMessageContext();
+ return jaxwsContext != null ? "pass" : "fail";
+ }
+
+ @WebMethod
+ public String testGetUserPrincipal()
+ {
+ return wsCtx.getUserPrincipal().getName();
+ }
+
+ @WebMethod
+ public boolean testIsUserInRole(String role)
+ {
+ return wsCtx.isUserInRole(role);
+ }
+}
Property changes on:
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/context/EndpointNoInjectEJB.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF