1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.reggie.proxy;
19
20 import org.apache.river.proxy.ConstrainableProxyUtil;
21 import java.io.IOException;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24 import net.jini.core.constraint.MethodConstraints;
25 import net.jini.core.constraint.RemoteMethodControl;
26 import net.jini.security.proxytrust.ProxyTrustIterator;
27 import net.jini.security.proxytrust.SingletonProxyTrustIterator;
28 import org.apache.river.api.io.AtomicSerial;
29 import org.apache.river.api.io.AtomicSerial.GetArg;
30
31
32
33
34
35
36
37 @AtomicSerial
38 final class ConstrainableRegistration
39 extends Registration implements RemoteMethodControl
40 {
41 private static final long serialVersionUID = 2L;
42
43
44 private final MethodConstraints constraints;
45
46 private static MethodConstraints check(GetArg arg) throws IOException {
47 MethodConstraints constraints = (MethodConstraints) arg.get("constraints", null);
48 Registration reg = new Registration(arg);
49 MethodConstraints proxyCon = null;
50 if (reg.server instanceof RemoteMethodControl &&
51 (proxyCon = ((RemoteMethodControl)reg.server).getConstraints()) != null) {
52
53 return ConstrainableProxyUtil.reverseTranslateConstraints(
54 proxyCon, methodMappings);
55 }
56 ConstrainableProxyUtil.verifyConsistentConstraints(
57 constraints, reg.server, methodMappings);
58 return constraints;
59 }
60
61 ConstrainableRegistration(GetArg arg) throws IOException {
62 this(arg, check(arg));
63 }
64
65 ConstrainableRegistration(GetArg arg, MethodConstraints constraints) throws IOException{
66 super(arg);
67 this.constraints = constraints;
68 }
69
70
71
72
73
74 ConstrainableRegistration( Registrar server,
75 ServiceLease lease,
76 MethodConstraints constraints,
77 boolean setConstraints)
78 {
79 super( setConstraints ? (Registrar) ((RemoteMethodControl) server).setConstraints(
80 translateConstraints(constraints)): server,lease);
81 this.constraints = constraints;
82 }
83
84
85 @Override
86 public RemoteMethodControl setConstraints(MethodConstraints constraints) {
87 return new ConstrainableRegistration(server, lease, constraints, true);
88 }
89
90
91 @Override
92 public MethodConstraints getConstraints() {
93 return constraints;
94 }
95
96
97
98
99
100 private ProxyTrustIterator getProxyTrustIterator() {
101 return new SingletonProxyTrustIterator(server);
102 }
103
104 private void writeObject(ObjectOutputStream out) throws IOException {
105 out.defaultWriteObject();
106 }
107
108
109
110
111
112 private void readObject(ObjectInputStream in)
113 throws IOException, ClassNotFoundException
114 {
115 in.defaultReadObject();
116 ConstrainableProxyUtil.verifyConsistentConstraints(
117 constraints, server, methodMappings);
118 }
119 }