Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.corba.security » [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.geronimo.corba.security;
   18   
   19   import java.util.List;
   20   
   21   import org.slf4j.Logger;
   22   import org.slf4j.LoggerFactory;
   23   import org.omg.CORBA.BAD_PARAM;
   24   import org.omg.CORBA.LocalObject;
   25   import org.omg.IOP.ServiceContext;
   26   import org.omg.IOP.TAG_CSI_SEC_MECH_LIST;
   27   import org.omg.IOP.TaggedComponent;
   28   import org.omg.PortableInterceptor.ClientRequestInfo;
   29   import org.omg.PortableInterceptor.ClientRequestInterceptor;
   30   
   31   import org.apache.geronimo.corba.security.config.css.CSSCompoundSecMechConfig;
   32   import org.apache.geronimo.corba.security.config.css.CSSConfig;
   33   import org.apache.geronimo.corba.security.config.tss.TSSCompoundSecMechListConfig;
   34   import org.apache.geronimo.corba.util.Util;
   35   
   36   
   37   /**
   38    * @version $Revision: 502310 $ $Date: 2007-02-01 10:34:57 -0800 (Thu, 01 Feb 2007) $
   39    */
   40   final class ClientSecurityInterceptor extends LocalObject implements ClientRequestInterceptor {
   41   
   42       private final Logger log = LoggerFactory.getLogger(ClientSecurityInterceptor.class);
   43   
   44       public ClientSecurityInterceptor() {
   45           if (log.isDebugEnabled()) log.debug("Registered");
   46       }
   47   
   48       public void receive_exception(ClientRequestInfo ri) {
   49       }
   50   
   51       public void receive_other(ClientRequestInfo ri) {
   52       }
   53   
   54       public void receive_reply(ClientRequestInfo ri) {
   55       }
   56   
   57       public void send_poll(ClientRequestInfo ri) {
   58       }
   59   
   60       public void send_request(ClientRequestInfo ri) {
   61   
   62           try {
   63               if (log.isDebugEnabled()) log.debug("Checking if target " + ri.operation() + " has a security policy");
   64   
   65               TaggedComponent tc = ri.get_effective_component(TAG_CSI_SEC_MECH_LIST.value);
   66               TSSCompoundSecMechListConfig csml = TSSCompoundSecMechListConfig.decodeIOR(Util.getCodec(), tc);
   67   
   68               if (log.isDebugEnabled()) log.debug("Target has a security policy");
   69   
   70               ClientPolicy clientPolicy = (ClientPolicy) ri.get_request_policy(ClientPolicyFactory.POLICY_TYPE);
   71               CSSConfig config = clientPolicy.getConfig();
   72               if (config == null) return;
   73   
   74               if (log.isDebugEnabled()) log.debug("Client has a security policy");
   75   
   76               List compat = config.findCompatibleSet(csml);
   77   
   78               if (compat.size() == 0) return;
   79   
   80               if (log.isDebugEnabled()) log.debug("Found compatible policy");
   81   
   82               ServiceContext context = ((CSSCompoundSecMechConfig) compat.get(0)).generateServiceContext();
   83   
   84               if (context == null) return;
   85   
   86               if (log.isDebugEnabled()) {
   87                   log.debug("Msg context id: " + context.context_id);
   88                   log.debug("Encoded msg: 0x" + Util.byteToString(context.context_data));
   89               }
   90   
   91               ri.add_request_service_context(context, true);
   92           } catch (BAD_PARAM bp) {
   93               // do nothing
   94           } catch (Exception ue) {
   95               log.error("Exception", ue);
   96           }
   97       }
   98   
   99       public void destroy() {
  100       }
  101   
  102       public String name() {
  103           return "org.apache.geronimo.corba.security.ClientSecurityInterceptor";
  104       }
  105   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.corba.security » [javadoc | source]