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.tss;
018
019 import java.util.ArrayList;
020 import java.util.Iterator;
021 import java.util.List;
022 import javax.net.ssl.SSLSession;
023 import javax.security.auth.Subject;
024
025 import org.omg.CORBA.Any;
026 import org.omg.CORBA.ORB;
027 import org.omg.CSIIOP.SECIOP_SEC_TRANS;
028 import org.omg.CSIIOP.SECIOP_SEC_TRANSHelper;
029 import org.omg.CSIIOP.TAG_SECIOP_SEC_TRANS;
030 import org.omg.CSIIOP.TLS_SEC_TRANSHelper;
031 import org.omg.CSIIOP.TransportAddress;
032 import org.omg.IOP.Codec;
033 import org.omg.IOP.TaggedComponent;
034
035 import org.apache.geronimo.corba.security.SASException;
036 import org.apache.geronimo.corba.security.config.ConfigUtil;
037 import org.apache.geronimo.corba.util.Util;
038
039
040 /**
041 * TODO: this class needs to be revisited.
042 *
043 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
044 */
045 public class TSSSECIOPTransportConfig extends TSSTransportMechConfig {
046
047 private short supports;
048 private short requires;
049 private String mechOID;
050 private String targetName;
051 private final List addresses = new ArrayList(1);
052
053 public TSSSECIOPTransportConfig() {
054 }
055
056 public TSSSECIOPTransportConfig(TaggedComponent component, Codec codec) throws Exception {
057 Any any = codec.decode_value(component.component_data, TLS_SEC_TRANSHelper.type());
058 SECIOP_SEC_TRANS tst = SECIOP_SEC_TRANSHelper.extract(any);
059
060 supports = tst.target_supports;
061 requires = tst.target_requires;
062 mechOID = Util.decodeOID(tst.mech_oid);
063 targetName = new String(tst.target_name);
064
065 for (int i = 0; i < tst.addresses.length; i++) {
066 addresses.add(new TSSTransportAddressConfig(tst.addresses[i].port, tst.addresses[i].host_name));
067 }
068 }
069
070 public short getSupports() {
071 return supports;
072 }
073
074 public void setSupports(short supports) {
075 this.supports = supports;
076 }
077
078 public short getRequires() {
079 return requires;
080 }
081
082 public void setRequires(short requires) {
083 this.requires = requires;
084 }
085
086 public String getMechOID() {
087 return mechOID;
088 }
089
090 public void setMechOID(String mechOID) {
091 this.mechOID = mechOID;
092 }
093
094 public String getTargetName() {
095 return targetName;
096 }
097
098 public void setTargetName(String targetName) {
099 this.targetName = targetName;
100 }
101
102 public List getAddresses() {
103 return addresses;
104 }
105
106 public TaggedComponent encodeIOR(ORB orb, Codec codec) throws Exception {
107 TaggedComponent result = new TaggedComponent();
108
109 SECIOP_SEC_TRANS sst = new SECIOP_SEC_TRANS();
110
111 sst.target_supports = supports;
112 sst.target_requires = requires;
113 sst.mech_oid = Util.encodeOID(mechOID);
114 sst.target_name = targetName.getBytes();
115
116 sst.addresses = new TransportAddress[addresses.size()];
117
118 int i = 0;
119 TSSTransportAddressConfig transportConfig;
120 for (Iterator iter = addresses.iterator(); iter.hasNext();) {
121 transportConfig = (TSSTransportAddressConfig) iter.next();
122 sst.addresses[i++] = new TransportAddress(transportConfig.getHostname(), transportConfig.getPort());
123 }
124
125 Any any = orb.create_any();
126 SECIOP_SEC_TRANSHelper.insert(any, sst);
127
128 result.tag = TAG_SECIOP_SEC_TRANS.value;
129 result.component_data = codec.encode_value(any);
130
131 return result;
132 }
133
134 public Subject check(SSLSession session) throws SASException {
135 return new Subject();
136 }
137
138 void toString(String spaces, StringBuffer buf) {
139 String moreSpaces = spaces + " ";
140 buf.append(spaces).append("TSSSASMechConfig: [\n");
141 buf.append(moreSpaces).append("SUPPORTS : ").append(ConfigUtil.flags(supports)).append("\n");
142 buf.append(moreSpaces).append("REQUIRES : ").append(ConfigUtil.flags(requires)).append("\n");
143 buf.append(moreSpaces).append("mechOID : ").append(mechOID).append("\n");
144 buf.append(moreSpaces).append("targetName: ").append(targetName).append("\n");
145 for (Iterator iterator = addresses.iterator(); iterator.hasNext();) {
146 TSSTransportAddressConfig tssTransportAddressConfig = (TSSTransportAddressConfig) iterator.next();
147 tssTransportAddressConfig.toString(moreSpaces, buf);
148 }
149 buf.append(spaces).append("]\n");
150 }
151
152
153 }