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.util.Iterator;
   20   import java.util.Set;
   21   import javax.security.auth.Subject;
   22   
   23   import org.apache.geronimo.security.jaas.NamedUsernamePasswordCredential;
   24   import org.apache.geronimo.security.ContextManager;
   25   
   26   import org.apache.geronimo.corba.security.config.tss.TSSASMechConfig;
   27   import org.apache.geronimo.corba.security.config.tss.TSSGSSUPMechConfig;
   28   import org.apache.geronimo.corba.util.Util;
   29   
   30   
   31   /**
   32    * This GSSUP mechanism obtains its username and password from a named username
   33    * password credential that is stored in the subject associated w/ the call
   34    * stack.
   35    *
   36    * @version $Revision: 503493 $ $Date: 2007-02-04 13:47:55 -0800 (Sun, 04 Feb 2007) $
   37    */
   38   public class CSSGSSUPMechConfigDynamic implements CSSASMechConfig {
   39   
   40       private final String domain;
   41       private transient byte[] encoding;
   42   
   43       public CSSGSSUPMechConfigDynamic(String domain) {
   44           this.domain = domain;
   45       }
   46   
   47       public short getSupports() {
   48           return 0;
   49       }
   50   
   51       public short getRequires() {
   52           return 0;
   53       }
   54   
   55       public boolean canHandle(TSSASMechConfig asMech) {
   56           if (asMech instanceof TSSGSSUPMechConfig) return true;
   57           if (asMech.getRequires() == 0) return true;
   58   
   59           return false;
   60       }
   61   
   62       public byte[] encode() {
   63           if (encoding == null) {
   64               NamedUsernamePasswordCredential credential = null;
   65               Subject subject = ContextManager.getNextCaller();
   66   
   67               Set creds = subject.getPrivateCredentials(NamedUsernamePasswordCredential.class);
   68   
   69               if (creds.size() != 0) {
   70                   for (Iterator iter = creds.iterator(); iter.hasNext();) {
   71                       NamedUsernamePasswordCredential temp = (NamedUsernamePasswordCredential) iter.next();
   72                       if (temp.getName().equals(domain)) {
   73                           credential = temp;
   74                           break;
   75                       }
   76                   }
   77                   if(credential != null) {
   78                       String extendedUserName = Util.buildScopedUserName(credential.getUsername(), domain);
   79                       encoding = Util.encodeGSSUPToken(Util.getORB(), Util.getCodec(), extendedUserName, new String(credential.getPassword()), domain);
   80                   }
   81               }
   82   
   83               if (encoding == null) encoding = new byte[0];
   84           }
   85           return encoding;
   86       }
   87   
   88       public String toString() {
   89           StringBuffer buf = new StringBuffer();
   90           toString("", buf);
   91           return buf.toString();
   92       }
   93   
   94       public void toString(String spaces, StringBuffer buf) {
   95           String moreSpaces = spaces + "  ";
   96           buf.append(spaces).append("CSSGSSUPMechConfigDynamic: [\n");
   97           buf.append(moreSpaces).append("domain:   ").append(domain).append("\n");
   98           buf.append(spaces).append("]\n");
   99       }
  100   
  101   }

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