001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.geronimo.corba.security.config.css;
018    
019    import org.apache.geronimo.corba.security.config.tss.TSSASMechConfig;
020    import org.apache.geronimo.corba.security.config.tss.TSSGSSUPMechConfig;
021    import org.apache.geronimo.corba.util.Util;
022    
023    
024    /**
025     * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
026     */
027    public class CSSGSSUPMechConfigStatic implements CSSASMechConfig {
028    
029        private final String username;
030        private final String password;
031        private final String domain;
032        private transient byte[] encoding;
033    
034        public CSSGSSUPMechConfigStatic(String username, String password, String domain) {
035            this.username = username;
036            this.password = password;
037            this.domain = domain;
038        }
039    
040        public short getSupports() {
041            return 0;
042        }
043    
044        public short getRequires() {
045            return 0;
046        }
047    
048        public boolean canHandle(TSSASMechConfig asMech) {
049            if (asMech instanceof TSSGSSUPMechConfig) return true;
050            if (asMech.getRequires() == 0) return true;
051    
052            return false;
053        }
054    
055        public byte[] encode() {
056            if (encoding == null) {
057                String scopedUserName = Util.buildScopedUserName(username, domain);
058                encoding = Util.encodeGSSUPToken(Util.getORB(), Util.getCodec(), scopedUserName, password, domain);
059    
060                if (encoding == null) encoding = new byte[0];
061            }
062            return encoding;
063        }
064        
065        public String toString() {
066            StringBuffer buf = new StringBuffer();
067            toString("", buf);
068            return buf.toString();
069        }
070    
071        public void toString(String spaces, StringBuffer buf) {
072            String moreSpaces = spaces + "  ";
073            buf.append(spaces).append("CSSGSSUPMechConfigStatic: [\n");
074            buf.append(moreSpaces).append("username: ").append(username).append("\n");
075            buf.append(moreSpaces).append("password: ").append(password).append("\n");
076            buf.append(moreSpaces).append("domain:   ").append(domain).append("\n");
077            buf.append(spaces).append("]\n");
078        }
079    
080    }