Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateless » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.openejb.core.stateless;
   18   
   19   import java.security.Principal;
   20   
   21   import javax.ejb.SessionContext;
   22   import javax.xml.ws.WebServiceContext;
   23   import javax.xml.ws.EndpointReference;
   24   import javax.xml.ws.handler.MessageContext;
   25   
   26   import org.apache.openejb.core.ThreadContext;
   27   import org.apache.openejb.core.webservices.AddressingSupport;
   28   import org.w3c.dom.Element;
   29   
   30   public class EjbWsContext implements WebServiceContext {
   31       private SessionContext context;
   32       
   33       public EjbWsContext(SessionContext context) {
   34           this.context = context;
   35       }
   36       
   37       public MessageContext getMessageContext() {
   38           ThreadContext threadContext = ThreadContext.getThreadContext();
   39           MessageContext messageContext = threadContext.get(MessageContext.class);
   40           if (messageContext == null) {
   41               throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
   42           }
   43           return messageContext;
   44       }
   45   
   46       public Principal getUserPrincipal() {
   47           return this.context.getCallerPrincipal();
   48       }
   49   
   50       public boolean isUserInRole(String roleName) {
   51           return this.context.isCallerInRole(roleName);
   52       }
   53   
   54       private AddressingSupport getAddressingSupport() {
   55           ThreadContext threadContext = ThreadContext.getThreadContext();
   56           AddressingSupport wsaSupport = threadContext.get(AddressingSupport.class);
   57           if (wsaSupport == null) {
   58               throw new IllegalStateException("Only calls on the service-endpoint can get the EndpointReference.");
   59           }
   60           return wsaSupport;
   61       }
   62       
   63       public EndpointReference getEndpointReference(org.w3c.dom.Element... referenceParameters) {
   64           return getAddressingSupport().getEndpointReference(referenceParameters);      
   65       }
   66   
   67       public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element... referenceParameters) {
   68           return getAddressingSupport().getEndpointReference(clazz, referenceParameters);
   69       }
   70   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateless » [javadoc | source]