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: import org.jboss.ejb.plugins.SecurityInterceptor;
042: import org.jboss.system.Registry;
043:
044: /**
045: * This is an <code>org.omg.PortableInterceptor.ORBInitializer</code> that
046: * initializes the Security Attibute Service (SAS).
047: *
048: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
049: * @version $Revision: 57194 $
050: */
051: public class SASInitializer extends LocalObject implements
052: ORBInitializer {
053: /** @since 4.0.1 */
054: static final long serialVersionUID = -2986312833694840538L;
055:
056: public SASInitializer() {
057: // do nothing
058: }
059:
060: // org.omg.PortableInterceptor.ORBInitializer operations ---------
061:
062: public void pre_init(ORBInitInfo info) {
063: try {
064: // Create and register the SASCurrent
065: SASCurrent sasCurrent = new SASCurrentImpl();
066: info.register_initial_reference("SASCurrent", sasCurrent);
067: } catch (InvalidName e) {
068: throw new RuntimeException("Could not register initial "
069: + "reference for SASCurrent: " + e);
070: }
071: }
072:
073: public void post_init(ORBInitInfo info) {
074: try {
075: // Use CDR encapsulations with GIOP 1.0 encoding
076: Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value,
077: (byte) 1, /* GIOP version */
078: (byte) 0 /* GIOP revision*/);
079: Codec codec = info.codec_factory().create_codec(encoding);
080:
081: // Create and register client interceptor
082: SASClientIdentityInterceptor clientInterceptor = new SASClientIdentityInterceptor(
083: codec);
084: info.add_client_request_interceptor(clientInterceptor);
085:
086: // Create and register server interceptor
087: SASTargetInterceptor serverInterceptor = new SASTargetInterceptor(
088: codec);
089: info.add_server_request_interceptor(serverInterceptor);
090:
091: // Initialize the SASCurrent implementation
092: org.omg.CORBA.Object obj = info
093: .resolve_initial_references("SASCurrent");
094: final SASCurrentImpl sasCurrentImpl = (SASCurrentImpl) obj;
095: sasCurrentImpl.init(serverInterceptor);
096:
097: // Create and register an AuthenticationObserver to be called
098: // by the SecurityInterceptor
099: Registry.bind(
100: SecurityInterceptor.AuthenticationObserver.KEY,
101: new SecurityInterceptor.AuthenticationObserver() {
102: public void authenticationFailed() {
103: sasCurrentImpl.reject_incoming_context();
104: }
105: });
106: } catch (Exception e) {
107: throw new RuntimeException("Unexpected " + e);
108: }
109: }
110:
111: }
|