Home » openejb-3.1.2-src » org.apache » openejb » server » axis2 » pojo » [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   
   18   package org.apache.openejb.server.axis2.pojo;
   19   
   20   import java.security.Principal;
   21   
   22   import javax.servlet.http.HttpServletRequest;
   23   import javax.xml.ws.WebServiceContext;
   24   import javax.xml.ws.EndpointReference;
   25   import javax.xml.ws.handler.MessageContext;
   26   
   27   import org.w3c.dom.Element;
   28   
   29   /**
   30    * Implementation of WebServiceContext for POJO WS to ensure that getUserPrincipal()
   31    * and isUserInRole() are properly handled.
   32    */
   33   public class PojoWsContext implements WebServiceContext {
   34       private static ThreadLocal<MessageContext> context = new ThreadLocal<MessageContext>();
   35       
   36       public PojoWsContext() {
   37       }
   38           
   39       public final MessageContext getMessageContext() {
   40           return context.get();
   41       }
   42   
   43       private HttpServletRequest getHttpServletRequest() {
   44           MessageContext ctx = getMessageContext();
   45           return (ctx != null) ? (HttpServletRequest)ctx.get(MessageContext.SERVLET_REQUEST) : null;
   46       }
   47   
   48       public final Principal getUserPrincipal() {
   49           HttpServletRequest request = getHttpServletRequest();
   50           return (request != null) ? request.getUserPrincipal() : null;
   51       }
   52   
   53       public final boolean isUserInRole(String user) {
   54           HttpServletRequest request = getHttpServletRequest();
   55           return request != null && request.isUserInRole(user);
   56       }
   57               
   58       public static void setMessageContext(MessageContext ctx) {
   59           context.set(ctx);
   60       }
   61   
   62       public static void clear() {
   63           context.set(null);
   64       }
   65   
   66       @SuppressWarnings({"UnusedDeclaration"})
   67       public EndpointReference getEndpointReference(org.w3c.dom.Element... referenceParameters) {
   68           throw new UnsupportedOperationException("JaxWS 2.1 APIs are not supported");
   69       }
   70   
   71       @SuppressWarnings({"UnusedDeclaration"})
   72       public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element... referenceParameters) {
   73           throw new UnsupportedOperationException("JaxWS 2.1 APIs are not supported");
   74       }
   75   }

Home » openejb-3.1.2-src » org.apache » openejb » server » axis2 » pojo » [javadoc | source]