1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.astrogrid.community.client.policy.service ;
29
30 import org.apache.commons.logging.Log ;
31 import org.apache.commons.logging.LogFactory ;
32
33 import java.rmi.RemoteException ;
34
35 import org.astrogrid.community.common.policy.data.PolicyPermission ;
36 import org.astrogrid.community.common.policy.data.PolicyCredentials ;
37
38 import org.astrogrid.community.common.policy.service.PolicyService ;
39
40 import org.astrogrid.community.common.exception.CommunityPolicyException ;
41 import org.astrogrid.community.common.exception.CommunityServiceException ;
42 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
43
44 import org.astrogrid.community.client.service.CommunityServiceCoreDelegate ;
45
46 /***
47 * The core delegate for our PolicyService service.
48 * This acts as a wrapper for a PolicyService service, and converts RemoteExceptions into CommunityServiceException.
49 *
50 */
51 public class PolicyServiceCoreDelegate
52 extends CommunityServiceCoreDelegate
53 implements PolicyService, PolicyServiceDelegate
54 {
55 /***
56 * Our debug logger.
57 *
58 */
59 private static Log log = LogFactory.getLog(PolicyServiceCoreDelegate.class);
60
61 /***
62 * Public constructor.
63 *
64 */
65 public PolicyServiceCoreDelegate()
66 {
67 }
68
69 /***
70 * Our PolicyService service.
71 *
72 */
73 private PolicyService service = null ;
74
75 /***
76 * Get a reference to our PolicyService service.
77 *
78 */
79 protected PolicyService getPolicyService()
80 {
81 return this.service ;
82 }
83
84 /***
85 * Set our our PolicyService service.
86 *
87 */
88 protected void setPolicyService(PolicyService service)
89 {
90 this.setCommunityService(service) ;
91 this.service = service ;
92 }
93
94 /***
95 * Confirm permissions.
96 * @param credentials The credentials, containing the account and group identifiers.
97 * @param resource The resource identifier.
98 * @param action The action you want to perform.
99 * @return A PolicyPermission object confirming the permission.
100 * @throws CommunityIdentifierException If one of the identifiers is invalid.
101 * @throws CommunityPolicyException If there is no matching permission.
102 * @throws CommunityServiceException If there is an internal error in the service.
103 *
104 */
105 public PolicyPermission checkPermissions(PolicyCredentials credentials, String resource, String action)
106 throws CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
107 {
108
109
110 if (null != this.service)
111 {
112
113
114 try {
115 return this.service.checkPermissions(credentials, resource, action) ;
116 }
117
118
119 catch (RemoteException ouch)
120 {
121
122
123 policyException(ouch) ;
124 serviceException(ouch) ;
125 identifierException(ouch) ;
126
127
128 throw new CommunityServiceException(
129 "WebService call failed - " + ouch,
130 ouch
131 ) ;
132 }
133 }
134
135
136 else {
137 throw new CommunityServiceException(
138 "Service not initialised"
139 ) ;
140 }
141 }
142
143 /***
144 * Confirm membership.
145 * @param credentials The credentials, containing the account and group identifiers.
146 * @return A PolicyCredentials object confirming the membership.
147 * @throws CommunityIdentifierException If one of the identifiers is invalid.
148 * @throws CommunityPolicyException If there is no matching permission.
149 * @throws CommunityServiceException If there is an internal error in the service.
150 *
151 */
152 public PolicyCredentials checkMembership(PolicyCredentials credentials)
153 throws CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
154 {
155
156
157 if (null != this.service)
158 {
159
160
161 try {
162 return this.service.checkMembership(credentials) ;
163 }
164
165
166 catch (RemoteException ouch)
167 {
168
169
170 policyException(ouch) ;
171 serviceException(ouch) ;
172 identifierException(ouch) ;
173
174
175 throw new CommunityServiceException(
176 "WebService call failed - " + ouch,
177 ouch
178 ) ;
179 }
180 }
181
182
183 else {
184 throw new CommunityServiceException(
185 "Service not initialised"
186 ) ;
187 }
188 }
189 }