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: /***************************************
025: * *
026: * JBoss: The OpenSource J2EE WebOS *
027: * *
028: * Distributable under LGPL license. *
029: * See terms of license at gnu.org. *
030: * *
031: ***************************************/
032:
033: import org.omg.CORBA.LocalObject;
034: import org.omg.IOP.Codec;
035: import org.omg.IOP.ENCODING_CDR_ENCAPS;
036: import org.omg.IOP.Encoding;
037: import org.omg.PortableInterceptor.ORBInitInfo;
038: import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName;
039: import org.omg.PortableInterceptor.ORBInitializer;
040:
041: /**
042: * This is an <code>org.omg.PortableInterceptor.ORBInitializer</code> that
043: * initializes the Security Attibute Service (SAS).
044: *
045: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
046: * @version $Revision: 57194 $
047: */
048: public class SASClientInitializer extends LocalObject implements
049: ORBInitializer {
050: /** @since 4.0.1 */
051: static final long serialVersionUID = -2606258922369211218L;
052:
053: public SASClientInitializer() {
054: // do nothing
055: }
056:
057: // org.omg.PortableInterceptor.ORBInitializer operations ---------
058:
059: public void pre_init(ORBInitInfo info) {
060: try {
061: // Create and register the SASCurrent
062: SASCurrent sasCurrent = new SASCurrentImpl();
063: info.register_initial_reference("SASCurrent", sasCurrent);
064:
065: // The SASCurrent still needs to be initialized.
066: // Its initialization is deferred to post_init, as it needs
067: // to call resolve_initial_references.
068: } catch (InvalidName e) {
069: throw new RuntimeException("Could not register initial "
070: + "reference for SASCurrent: " + e);
071: }
072: }
073:
074: public void post_init(ORBInitInfo info) {
075: try {
076: org.omg.CORBA.Object obj;
077:
078: // Use CDR encapsulations with GIOP 1.0 encoding
079: Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value,
080: (byte) 1, /* GIOP version */
081: (byte) 0 /* GIOP revision*/);
082: Codec codec = info.codec_factory().create_codec(encoding);
083:
084: // Create and register client interceptor
085: obj = info.resolve_initial_references("SASCurrent");
086: SASCurrentImpl sasCurrentImpl = (SASCurrentImpl) obj;
087: SASClientInterceptor clientInterceptor = new SASClientInterceptor(
088: codec);
089: info.add_client_request_interceptor(clientInterceptor);
090:
091: // Create and register server interceptor
092: SASTargetInterceptor serverInterceptor = new SASTargetInterceptor(
093: codec);
094: info.add_server_request_interceptor(serverInterceptor);
095:
096: // Initialize the SASCurrent implementation
097: sasCurrentImpl.init(serverInterceptor);
098: } catch (Exception e) {
099: throw new RuntimeException("Unexpected " + e);
100: }
101: }
102:
103: }
|