1 /*
2 * Copyright 2018 peter.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.river.phoenix.common;
17
18 import java.lang.reflect.Method;
19 import java.rmi.Remote;
20 import java.rmi.server.ExportException;
21 import java.util.Collection;
22 import net.jini.core.constraint.InvocationConstraints;
23 import net.jini.jeri.AtomicILFactory;
24 import net.jini.jeri.AtomicInvocationDispatcher;
25 import net.jini.jeri.InvocationDispatcher;
26 import net.jini.jeri.ServerCapabilities;
27
28 /**
29 *
30 * @author peter
31 */
32 public class AccessAtomicILFactory extends AtomicILFactory {
33
34 /**
35 * Creates an <code>AccessILFactory</code>instance with no server
36 * constraints, no permission class, and the specified class loader.
37 * The specified class loader is used by the {@link #createInstances
38 * createInstances} method.
39 *
40 * @param loader the class loader, or <code>null</code>
41 **/
42 public AccessAtomicILFactory(ClassLoader loader) {
43 super(null, null, loader);
44 }
45
46 /**
47 * Creates an <code>AccessILFactory</code>instance with no server
48 * constraints, no permission class, and the specified smart proxy
49 * or service implementation class, used to determined the ClassLoader.
50 * The specified class loader of proxyOrService is used by the
51 * {@link #createInstances createInstances} method.
52 *
53 * @param proxyOrService class of the smart proxy or service implementation.
54 * @throws NullPointerException if proxyOrService is null.
55 **/
56 public AccessAtomicILFactory(Class proxyOrService){
57 this(proxyOrService.getClassLoader());
58 }
59
60 /**
61 * Returns an {@link AccessDispatcher} instance constructed with the
62 * specified methods, the specified server capabilities, and the class
63 * loader specified at construction.
64 *
65 * @return the {@link AccessDispatcher} instance
66 * @throws NullPointerException {@inheritDoc}
67 **/
68 @Override
69 protected InvocationDispatcher
70 createInvocationDispatcher(Collection methods,
71 Remote impl,
72 ServerCapabilities caps)
73 throws ExportException
74 {
75 if (impl == null) {
76 throw new NullPointerException("impl is null");
77 }
78 return new AccessILFactory.AccessDispatcher(methods, caps, getClassLoader());
79 }
80
81 /**
82 * A subclass of {@link AtomicInvocationDispatcher} that only accepts
83 * calls from the local host.
84 */
85 public static class AccessDispatcher extends AtomicInvocationDispatcher {
86 /**
87 * Constructs an invocation dispatcher for the specified methods.
88 *
89 * @param methods a collection of {@link Method} instances
90 * for the remote methods
91 * @param caps the transport capabilities of the server
92 * @param loader the class loader, or <code>null</code>
93 * @throws NullPointerException if <code>methods</code> is
94 * <code>null</code> or if <code>methods</code> contains a
95 * <code>null</code> elememt
96 * @throws IllegalArgumentException if <code>methods</code>
97 * contains an element that is not a <code>Method</code>
98 * instance
99 * @throws ExportException doesn't throw ExportException as there are no
100 * constraints.
101 */
102 public AccessDispatcher(Collection methods,
103 ServerCapabilities caps,
104 ClassLoader loader)
105 throws ExportException
106 {
107 super(methods, caps, null, null, loader);
108 }
109
110 /**
111 * Checks that the client is calling from the local host.
112 *
113 * @throws java.security.AccessControlException if the client is not
114 * calling from the local host
115 */
116 @Override
117 protected void checkAccess(Remote impl,
118 Method method,
119 InvocationConstraints constraints,
120 Collection context)
121 {
122 LocalAccess.check();
123 }
124 }
125 }