KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > net > rmi > RMIInvokerFactoryImpl


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2003-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: RMIInvokerFactoryImpl.java,v 1.2 2005/04/17 14:01:30 tanderson Exp $
44  */

45 package org.exolab.jms.net.rmi;
46
47 import java.rmi.RemoteException JavaDoc;
48 import java.rmi.AccessException JavaDoc;
49 import java.rmi.server.RemoteObject JavaDoc;
50 import java.security.Principal JavaDoc;
51
52 import org.exolab.jms.net.connector.ManagedConnectionAcceptorListener;
53 import org.exolab.jms.net.connector.Authenticator;
54 import org.exolab.jms.net.connector.ResourceException;
55 import org.exolab.jms.net.uri.URIHelper;
56
57
58 /**
59  * A factory for {@link RMIInvoker} instances.
60  *
61  * @author <a HREF="mailto:tma@netspace.net.au">Tim Anderson</a>
62  * @version $Revision: 1.2 $ $Date: 2005/04/17 14:01:30 $
63  */

64 public class RMIInvokerFactoryImpl
65         extends RemoteObject JavaDoc implements RMIInvokerFactory {
66
67     /**
68      * The connection authenticator.
69      */

70     private final Authenticator _authenticator;
71
72     /**
73      * The connection acceptor that constructed this.
74      */

75     private final RMIManagedConnectionAcceptor _acceptor;
76
77     /**
78      * The listener to delegate accepted connections to.
79      */

80     private final ManagedConnectionAcceptorListener _listener;
81
82
83     /**
84      * Construct a new <code>RMIInvokerFactoryImpl</code>.
85      *
86      * @param authenticator the connection authenticator
87      * @param acceptor the connection acceptor that constructed this
88      * @param listener the listsner to delegate new connections to
89      */

90     public RMIInvokerFactoryImpl(Authenticator authenticator,
91                                  RMIManagedConnectionAcceptor acceptor,
92                                  ManagedConnectionAcceptorListener listener) {
93         _authenticator = authenticator;
94         _acceptor = acceptor;
95         _listener = listener;
96
97     }
98
99     /**
100      * Creates an authenticated invoker.
101      *
102      * @param principal the security principal
103      * @param client the invoker for performing invocations back to the
104      * client
105      * @param uri the URI representing the client
106      * @return an authenticated invoker
107      * @throws RemoteException for any remote error
108      */

109     public RMIInvoker createInvoker(Principal JavaDoc principal, RMIInvoker client,
110                                     String JavaDoc uri)
111             throws RemoteException JavaDoc {
112         try {
113             if (!_authenticator.authenticate(principal)) {
114                 throw new AccessException JavaDoc("Failed to authenticate");
115             }
116         } catch (ResourceException exception) {
117             throw new AccessException JavaDoc("Failed to authenticate", exception);
118         }
119         RMIInvokerImpl invoker = new RMIInvokerImpl();
120         RMIManagedConnection connection =
121                 new RMIManagedConnection(principal, invoker, _acceptor.getURI(),
122                                          client, URIHelper.parse(uri));
123         _listener.accepted(_acceptor, connection);
124         return invoker;
125     }
126
127 }
128
Popular Tags