001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.csiv2;
023:
024: import org.omg.CORBA.LocalObject;
025: import org.omg.CORBA.Policy;
026: import org.omg.CORBA.ORB;
027:
028: import org.omg.IOP.Codec;
029: import org.omg.IOP.TaggedComponent;
030:
031: import org.jboss.iiop.CorbaORBService;
032: import org.jboss.logging.Logger;
033: import org.jboss.metadata.IorSecurityConfigMetaData;
034:
035: /**
036: * Implements <code>org.omg.CORBA.Policy</code> objects containing
037: * csiv2 ior security config info
038: *
039: * @author Dimitris.Andreadis@jboss.org
040: * @version $Revision: 57194 $
041: */
042: public class CSIv2Policy extends LocalObject implements Policy {
043: /** @since 4.0.1 */
044: static final long serialVersionUID = -8487980590230439410L;
045:
046: // Static -----------------------------------------------------------------
047: private static final Logger log = Logger
048: .getLogger(CSIv2Policy.class);
049:
050: // TODO: contact request@omg.org to get a policy type
051: public static final int TYPE = 0x87654321;
052:
053: // Private -----------------------------------------------------------------
054: private TaggedComponent sslTaggedComponent;
055: private TaggedComponent secTaggedComponent;
056:
057: // Constructor -------------------------------------------------------------
058: public CSIv2Policy(TaggedComponent sslTaggedComponent,
059: TaggedComponent secTaggedComponent) {
060: this .sslTaggedComponent = sslTaggedComponent;
061: this .secTaggedComponent = secTaggedComponent;
062: }
063:
064: public CSIv2Policy(IorSecurityConfigMetaData metadata, Codec codec) {
065: if (log.isDebugEnabled())
066: log.debug(metadata);
067:
068: // convert the ior metadata to a cached security tagged component
069:
070: try {
071: // get the singleton orb
072: ORB orb = ORB.init();
073:
074: this .sslTaggedComponent = CSIv2Util
075: .createSSLTaggedComponent(metadata, codec,
076: CorbaORBService.getTheActualSSLPort(), orb);
077:
078: this .secTaggedComponent = CSIv2Util
079: .createSecurityTaggedComponent(metadata, codec,
080: CorbaORBService.getTheActualSSLPort(), orb);
081: } catch (Exception e) {
082: throw new RuntimeException("Unexpected exception " + e);
083: }
084: }
085:
086: /**
087: * Return a copy of the cached SSL TaggedComponent
088: **/
089: public TaggedComponent getSSLTaggedComponent() {
090: return CSIv2Util.createCopy(this .sslTaggedComponent);
091: }
092:
093: /**
094: * Return a copy of the cached CSI TaggedComponent
095: **/
096: public TaggedComponent getSecurityTaggedComponent() {
097: return CSIv2Util.createCopy(this .secTaggedComponent);
098: }
099:
100: // org.omg.CORBA.Policy operations -----------------------------------------
101: /**
102: * Returns a copy of the Policy object.
103: */
104: public Policy copy() {
105: return new CSIv2Policy(getSSLTaggedComponent(),
106: getSecurityTaggedComponent());
107: }
108:
109: /**
110: * Destroys the Policy object.
111: */
112: public void destroy() {
113: this .sslTaggedComponent = null;
114: this .secTaggedComponent = null;
115: }
116:
117: /**
118: * Returns the constant value that corresponds to the type of the policy
119: * object.
120: */
121: public int policy_type() {
122: return TYPE;
123: }
124:
125: public String toString() {
126: return "CSIv2Policy[" + this .sslTaggedComponent + ", "
127: + this .secTaggedComponent + "]";
128: }
129: }
|