Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.corba.security.config.css » [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.config.css;
   18   
   19   import java.io.Serializable;
   20   
   21   import org.slf4j.Logger;
   22   import org.slf4j.LoggerFactory;
   23   import org.omg.CORBA.Any;
   24   import org.omg.CORBA.UserException;
   25   import org.omg.CSI.EstablishContext;
   26   import org.omg.CSI.SASContextBody;
   27   import org.omg.CSI.SASContextBodyHelper;
   28   import org.omg.IOP.SecurityAttributeService;
   29   import org.omg.IOP.ServiceContext;
   30   
   31   import org.apache.geronimo.corba.security.config.ConfigUtil;
   32   import org.apache.geronimo.corba.security.config.tss.TSSCompoundSecMechConfig;
   33   import org.apache.geronimo.corba.util.Util;
   34   
   35   
   36   /**
   37    * @version $Rev: 503274 $ $Date: 2007-02-03 10:19:18 -0800 (Sat, 03 Feb 2007) $
   38    */
   39   public class CSSCompoundSecMechConfig implements Serializable {
   40   
   41       private final static Logger log = LoggerFactory.getLogger(CSSCompoundSecMechConfig.class);
   42   
   43       private short supports;
   44       private short requires;
   45       private CSSTransportMechConfig transport_mech;
   46       private CSSASMechConfig as_mech;
   47       private CSSSASMechConfig sas_mech;
   48   
   49       public CSSTransportMechConfig getTransport_mech() {
   50           return transport_mech;
   51       }
   52   
   53       public void setTransport_mech(CSSTransportMechConfig transport_mech) {
   54           this.transport_mech = transport_mech;
   55           this.supports |= transport_mech.getSupports();
   56           this.requires |= transport_mech.getRequires();
   57       }
   58   
   59       public CSSASMechConfig getAs_mech() {
   60           return as_mech;
   61       }
   62   
   63       public void setAs_mech(CSSASMechConfig as_mech) {
   64           this.as_mech = as_mech;
   65           this.supports |= as_mech.getSupports();
   66           this.requires |= as_mech.getRequires();
   67       }
   68   
   69       public CSSSASMechConfig getSas_mech() {
   70           return sas_mech;
   71       }
   72   
   73       public void setSas_mech(CSSSASMechConfig sas_mech) {
   74           this.sas_mech = sas_mech;
   75           this.supports |= sas_mech.getSupports();
   76           this.requires |= sas_mech.getRequires();
   77       }
   78   
   79       public boolean canHandle(TSSCompoundSecMechConfig requirement) {
   80   
   81           if (log.isDebugEnabled()) {
   82               log.debug("canHandle()");
   83               log.debug("    CSS SUPPORTS: " + ConfigUtil.flags(supports));
   84               log.debug("    CSS REQUIRES: " + ConfigUtil.flags(requires));
   85               log.debug("    TSS SUPPORTS: " + ConfigUtil.flags(requirement.getSupports()));
   86               log.debug("    TSS REQUIRES: " + ConfigUtil.flags(requirement.getRequires()));
   87           }
   88   
   89           if ((supports & requirement.getRequires()) != requirement.getRequires()) return false;
   90           if ((requires & requirement.getSupports()) != requires) return false;
   91   
   92           if (!transport_mech.canHandle(requirement.getTransport_mech())) return false;
   93           if (!as_mech.canHandle(requirement.getAs_mech())) return false;
   94           if (!sas_mech.canHandle(requirement.getSas_mech())) return false;
   95   
   96           return true;
   97       }
   98   
   99       public ServiceContext generateServiceContext() throws UserException {
  100   
  101           if (as_mech instanceof CSSNULLASMechConfig && sas_mech.getIdentityToken() instanceof CSSSASITTAbsent) return null;
  102   
  103           EstablishContext msg = new EstablishContext();
  104   
  105           msg.client_context_id = 0;
  106           msg.client_authentication_token = as_mech.encode();
  107           msg.authorization_token = sas_mech.encodeAuthorizationElement();
  108           msg.identity_token = sas_mech.encodeIdentityToken();
  109   
  110           ServiceContext context = new ServiceContext();
  111   
  112           SASContextBody sas = new SASContextBody();
  113           sas.establish_msg(msg);
  114           Any sas_any = Util.getORB().create_any();
  115           SASContextBodyHelper.insert(sas_any, sas);
  116           context.context_data = Util.getCodec().encode_value(sas_any);
  117   
  118           context.context_id = SecurityAttributeService.value;
  119   
  120           return context;
  121       }
  122   
  123       public String toString() {
  124           StringBuffer buf = new StringBuffer();
  125           toString("", buf);
  126           return buf.toString();
  127       }
  128   
  129       void toString(String spaces, StringBuffer buf) {
  130           String moreSpaces = spaces + "  ";
  131           buf.append(spaces).append("CSSCompoundSecMechConfig: [\n");
  132           buf.append(moreSpaces).append("SUPPORTS: ").append(ConfigUtil.flags(supports)).append("\n");
  133           buf.append(moreSpaces).append("REQUIRES: ").append(ConfigUtil.flags(requires)).append("\n");
  134           transport_mech.toString(moreSpaces, buf);
  135           as_mech.toString(moreSpaces, buf);
  136           sas_mech.toString(moreSpaces, buf);
  137           buf.append(spaces).append("]\n");
  138       }
  139       
  140   }

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