|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.databaseAccess; |
|
12 |
| |
|
13 |
| import java.sql.Connection; |
|
14 |
| import java.sql.Statement; |
|
15 |
| import java.sql.SQLException; |
|
16 |
| import java.sql.ResultSet; |
|
17 |
| |
|
18 |
| import java.util.Vector; |
|
19 |
| |
|
20 |
| import org.apache.commons.logging.Log; |
|
21 |
| import org.apache.commons.logging.LogFactory; |
|
22 |
| |
|
23 |
| import org.globus.cas.types.CasObjectData; |
|
24 |
| import org.globus.cas.types.ObjectGroupData; |
|
25 |
| import org.globus.cas.types.ArrayOfString; |
|
26 |
| |
|
27 |
| import org.globus.cas.impl.CasConstants; |
|
28 |
| |
|
29 |
| import org.globus.util.I18n; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class ObjectGroupDataHandler { |
|
35 |
| |
|
36 |
| static Log logger = |
|
37 |
| LogFactory.getLog(ObjectGroupDataHandler.class.getName() ); |
|
38 |
| |
|
39 |
| |
|
40 |
| private static I18n i18n = |
|
41 |
| I18n.getI18n("org.globus.cas.impl.databaseAccess.errors", |
|
42 |
| ObjectGroupDataHandler.class.getClassLoader()); |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
0
| public static String storeObject(ObjectGroupData objectGpData)
|
|
50 |
| throws CasDBException { |
|
51 |
| |
|
52 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
53 |
0
| String groupName = objectGpData.getGroupName();
|
|
54 |
0
| String query = "insert into " + CasDBConstants.TABLE_OBJECTGP + " ("
|
|
55 |
| + CasDBConstants.COL_OBJECTGP_NAME + ") values ('" + groupName |
|
56 |
| + "')"; |
|
57 |
0
| Statement statement = null;
|
|
58 |
0
| try {
|
|
59 |
0
| statement = connection.createStatement();
|
|
60 |
0
| logger.debug("store query is " + query);
|
|
61 |
0
| statement.executeUpdate(query);
|
|
62 |
| } |
|
63 |
| catch (SQLException exp) { |
|
64 |
0
| logger.error(i18n.getMessage("storeErr", new Object[] {
|
|
65 |
| "object group", query }), exp); |
|
66 |
0
| throw new CasDBException(i18n.getMessage("storeErr", new Object[] {
|
|
67 |
| "object group", "" } ) + exp.getMessage(), exp); |
|
68 |
| } |
|
69 |
| finally { |
|
70 |
| |
|
71 |
| |
|
72 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
73 |
0
| try {
|
|
74 |
0
| if (statement != null)
|
|
75 |
0
| statement.close();
|
|
76 |
| } |
|
77 |
| catch (SQLException exp) { |
|
78 |
0
| String err = "Error storing object group data. Could not "
|
|
79 |
| + " close SQL statement."; |
|
80 |
0
| logger.warn(err, exp);
|
|
81 |
| } |
|
82 |
| } |
|
83 |
0
| return groupName;
|
|
84 |
| } |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
0
| public static String[] list() throws CasDBException {
|
|
91 |
0
| String query = "select" + CasDBConstants.COL_OBJECTGP_NAME + " from"
|
|
92 |
| + CasDBConstants.TABLE_OBJECTGP; |
|
93 |
0
| return CasDBStorage.runListQuery(query,
|
|
94 |
| CasDBConstants.COL_OBJECTGP_NAME); |
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
0
| public static CasObjectData retrieveObject(String groupName)
|
|
102 |
| throws CasDBException { |
|
103 |
| |
|
104 |
0
| ObjectGroupData returnObject = null;
|
|
105 |
0
| Vector temp = null;
|
|
106 |
0
| Vector temp1 = null;
|
|
107 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
108 |
0
| String query = "select" + CasDBConstants.COL_OBJECT_SPEC + ","
|
|
109 |
| + CasDBConstants.COL_OBJECT_SPEC_DESC + " from" |
|
110 |
| + CasDBConstants.TABLE_OBJECTGP_ENTRY + " where " |
|
111 |
| + CasDBConstants.COL_OBJECTGP_NAME + " ='" + groupName.trim() + "'"; |
|
112 |
0
| Statement statement = null;
|
|
113 |
0
| ResultSet resultSet = null;
|
|
114 |
0
| try {
|
|
115 |
0
| statement = connection.createStatement();
|
|
116 |
0
| resultSet = statement.executeQuery(query);
|
|
117 |
0
| if ((resultSet != null) && (resultSet.next())) {
|
|
118 |
0
| temp = new Vector(resultSet.getFetchSize());
|
|
119 |
0
| temp1 = new Vector(resultSet.getFetchSize());
|
|
120 |
0
| do {
|
|
121 |
0
| temp.add(resultSet.getString(
|
|
122 |
| CasDBConstants.COL_OBJECT_SPEC.trim())); |
|
123 |
0
| temp1.add(resultSet.getString(
|
|
124 |
| CasDBConstants.COL_OBJECT_SPEC_DESC.trim())); |
|
125 |
0
| } while (resultSet.next());
|
|
126 |
| } |
|
127 |
| } |
|
128 |
| catch (SQLException exp) { |
|
129 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
130 |
| "object group", query } ), exp); |
|
131 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
132 |
| new Object[] { |
|
133 |
| "object group", ""}) |
|
134 |
| + exp.getMessage() , exp); |
|
135 |
| } |
|
136 |
| finally { |
|
137 |
| |
|
138 |
| |
|
139 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
140 |
0
| try {
|
|
141 |
0
| if (resultSet != null)
|
|
142 |
0
| resultSet.close();
|
|
143 |
0
| if (statement != null)
|
|
144 |
0
| statement.close();
|
|
145 |
| } |
|
146 |
| catch (SQLException exp) { |
|
147 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
148 |
| "object group"), exp); |
|
149 |
| } |
|
150 |
| } |
|
151 |
| |
|
152 |
0
| ArrayOfString arrayOfObjSpec = null;
|
|
153 |
0
| ArrayOfString arrayOfObjSpecDesc = null;
|
|
154 |
0
| if (temp != null) {
|
|
155 |
0
| String objSpec[] = new String[temp.size()];
|
|
156 |
0
| String objSpecDesc[] = new String[temp.size()];
|
|
157 |
0
| temp.toArray(objSpec);
|
|
158 |
0
| temp1.toArray(objSpecDesc);
|
|
159 |
0
| arrayOfObjSpec = new ArrayOfString(objSpec);
|
|
160 |
0
| arrayOfObjSpecDesc = new ArrayOfString(objSpecDesc);
|
|
161 |
| } |
|
162 |
| |
|
163 |
0
| connection = CasDBStorage.getDBConnection();
|
|
164 |
0
| query = "select * from" + CasDBConstants.TABLE_OBJECTGP + " where"
|
|
165 |
| + CasDBConstants.COL_OBJECTGP_NAME + " = '" + groupName.trim() |
|
166 |
| + "'"; |
|
167 |
0
| try {
|
|
168 |
0
| statement = connection.createStatement();
|
|
169 |
0
| resultSet = statement.executeQuery(query);
|
|
170 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
171 |
0
| returnObject = new ObjectGroupData();
|
|
172 |
0
| returnObject.setGroupName(
|
|
173 |
| resultSet.getString( |
|
174 |
| CasDBConstants.COL_OBJECTGP_NAME.trim())); |
|
175 |
0
| returnObject.setObjectSpecs(arrayOfObjSpec);
|
|
176 |
0
| returnObject.setObjectSpecsDesc(arrayOfObjSpecDesc);
|
|
177 |
| } |
|
178 |
| } |
|
179 |
| catch (SQLException exp) { |
|
180 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
181 |
| "object group", query}), exp); |
|
182 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
183 |
| new Object[] { |
|
184 |
| "object group", ""}) |
|
185 |
| + exp.getMessage() , exp); |
|
186 |
| } |
|
187 |
| finally { |
|
188 |
| |
|
189 |
| |
|
190 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
191 |
0
| try {
|
|
192 |
0
| if (resultSet != null)
|
|
193 |
0
| resultSet.close();
|
|
194 |
0
| if (statement != null)
|
|
195 |
0
| statement.close();
|
|
196 |
| } |
|
197 |
| catch (SQLException exp) { |
|
198 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
199 |
| "object group"), exp); |
|
200 |
| } |
|
201 |
| } |
|
202 |
0
| return returnObject;
|
|
203 |
| } |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
0
| public static void deleteObject(String groupName) throws CasDBException {
|
|
210 |
| |
|
211 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
212 |
0
| String query = "delete from" + CasDBConstants.TABLE_OBJECTGP + " where"
|
|
213 |
| + CasDBConstants.COL_OBJECTGP_NAME + " ='" + groupName.trim() |
|
214 |
| + "'"; |
|
215 |
0
| Statement statement = null;
|
|
216 |
0
| int result = -1;
|
|
217 |
0
| try {
|
|
218 |
0
| statement = connection.createStatement();
|
|
219 |
0
| result = statement.executeUpdate(query);
|
|
220 |
| } |
|
221 |
| catch (SQLException exp) { |
|
222 |
0
| logger.error(i18n.getMessage("delObjErr", new Object[] {
|
|
223 |
| "object group", query }), exp); |
|
224 |
0
| throw new CasDBException(i18n.getMessage("delObjErr",
|
|
225 |
| new Object[] { |
|
226 |
| "object group", "" }) |
|
227 |
| + exp.getMessage(), exp); |
|
228 |
| } |
|
229 |
| finally { |
|
230 |
| |
|
231 |
| |
|
232 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
233 |
0
| try {
|
|
234 |
0
| if (statement != null)
|
|
235 |
0
| statement.close();
|
|
236 |
| } |
|
237 |
| catch (SQLException exp) { |
|
238 |
0
| logger.warn(i18n.getMessage("delObjErrClose", "object group"),
|
|
239 |
| exp); |
|
240 |
| } |
|
241 |
| } |
|
242 |
0
| if (result <=0) {
|
|
243 |
0
| String err = i18n.getMessage("objGpDelError", groupName);
|
|
244 |
0
| logger.error(err);
|
|
245 |
0
| throw new CasDBException(err);
|
|
246 |
| } |
|
247 |
| } |
|
248 |
| |
|
249 |
0
| private static String getObjectId(String objectName, String objectNamespace)
|
|
250 |
| throws CasDBException { |
|
251 |
| |
|
252 |
0
| String objectId = null;
|
|
253 |
0
| String query = "select" + CasDBConstants.COL_OBJECT_ID + " from"
|
|
254 |
| + CasDBConstants.TABLE_OBJECT + " where (" |
|
255 |
| + CasDBConstants.COL_OBJECT_NAME + "='" + objectName + "') and (" |
|
256 |
| + CasDBConstants.COL_NS_NICKNAME + "='" + objectNamespace + "')"; |
|
257 |
0
| logger.debug("Query is " + query);
|
|
258 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
259 |
0
| Statement statement = null;
|
|
260 |
0
| ResultSet resultSet = null;
|
|
261 |
0
| try {
|
|
262 |
0
| statement = connection.createStatement();
|
|
263 |
0
| resultSet = statement.executeQuery(query);
|
|
264 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
265 |
0
| logger.debug("setting objectid");
|
|
266 |
0
| objectId =
|
|
267 |
| resultSet.getString(CasDBConstants.COL_OBJECT_ID.trim()); |
|
268 |
| } |
|
269 |
| } |
|
270 |
| catch (SQLException exp) { |
|
271 |
0
| logger.error(i18n.getMessage("objIdRetrErr", query), exp);
|
|
272 |
0
| throw new CasDBException(i18n.getMessage("objIdRetrErr", "")
|
|
273 |
| + exp.getMessage(), exp); |
|
274 |
| } |
|
275 |
| finally { |
|
276 |
| |
|
277 |
| |
|
278 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
279 |
0
| try {
|
|
280 |
0
| if (resultSet != null)
|
|
281 |
0
| resultSet.close();
|
|
282 |
0
| if (statement != null)
|
|
283 |
0
| statement.close();
|
|
284 |
| } |
|
285 |
| catch (SQLException exp) { |
|
286 |
0
| logger.warn(i18n.getMessage("objIdRetrCloseErr"), exp);
|
|
287 |
| } |
|
288 |
| } |
|
289 |
0
| return objectId;
|
|
290 |
| } |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
0
| public static void addGroupMember(String groupName, String objectSpec,
|
|
302 |
| String objectSpecDesc) |
|
303 |
| throws CasDBException { |
|
304 |
| |
|
305 |
0
| String baseErrMesg = i18n.getMessage("objGpMemAddErr", "");
|
|
306 |
0
| if ((groupName == null) || (objectSpec== null) ||
|
|
307 |
| (objectSpecDesc == null)) { |
|
308 |
0
| String err =
|
|
309 |
| i18n.getMessage("paramNull", |
|
310 |
| "Groupname/ObjectSpec/ObjectSpecDesc"); |
|
311 |
0
| logger.error(err);
|
|
312 |
0
| throw new CasDBException(err);
|
|
313 |
| } |
|
314 |
| |
|
315 |
0
| groupName = groupName.trim();
|
|
316 |
0
| objectSpec = objectSpec.trim();
|
|
317 |
0
| objectSpecDesc = objectSpecDesc.trim();
|
|
318 |
| |
|
319 |
0
| boolean validSpec = false;
|
|
320 |
| |
|
321 |
| |
|
322 |
0
| if (objectSpecDesc.equals(CasConstants.OBJECT_SPEC)) {
|
|
323 |
0
| logger.debug("Object spec is \"object\". check if it exists in "
|
|
324 |
| + "object table "); |
|
325 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_OBJECT,
|
|
326 |
| CasDBConstants.COL_OBJECT_ID, objectSpec)) { |
|
327 |
0
| String err = i18n.getMessage("notPresentInTable",
|
|
328 |
| new Object[] { "objectid", |
|
329 |
| objectSpec, |
|
330 |
| "object" }); |
|
331 |
0
| logger.error(err);
|
|
332 |
0
| throw new CasDBException(err);
|
|
333 |
| } |
|
334 |
0
| validSpec = true;
|
|
335 |
| } |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
0
| if (objectSpecDesc.equals(CasConstants.USER_SPEC)) {
|
|
340 |
0
| logger.debug("Object spec is \"user\". check if it exists in user"
|
|
341 |
| + " table "); |
|
342 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_USER,
|
|
343 |
| CasDBConstants.COL_USER_NICKNAME, objectSpec)) { |
|
344 |
0
| String err = i18n.getMessage("notPresentInTable",
|
|
345 |
| new Object[] { "user name", |
|
346 |
| objectSpec, |
|
347 |
| "user table" }); |
|
348 |
0
| logger.error(err);
|
|
349 |
0
| throw new CasDBException(err);
|
|
350 |
| } |
|
351 |
0
| validSpec = true;
|
|
352 |
| } |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
0
| if (objectSpecDesc.equals(CasConstants.USERGP_SPEC)) {
|
|
357 |
0
| logger.debug("Object spec is \"userGroup\". check if it exists in"
|
|
358 |
| + " user group table "); |
|
359 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_USERGP,
|
|
360 |
| CasDBConstants.COL_USERGP_NAME, objectSpec)) { |
|
361 |
0
| String err = i18n.getMessage("notPresentInTable",
|
|
362 |
| new Object[] { |
|
363 |
| "user group name", |
|
364 |
| objectSpec, |
|
365 |
| "user group table" }); |
|
366 |
0
| logger.error(err);
|
|
367 |
0
| throw new CasDBException(err);
|
|
368 |
| } |
|
369 |
0
| validSpec = true;
|
|
370 |
| } |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
0
| if (objectSpecDesc.equals(CasConstants.SERVICETYPE_SPEC)) {
|
|
375 |
0
| logger.debug("Object spec is \"serviceType\". check if it exists "
|
|
376 |
| + "in serviceType table "); |
|
377 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_SERVICETYPE,
|
|
378 |
| CasDBConstants.COL_SERVICETYPE_NAME, objectSpec)) { |
|
379 |
0
| String err = i18n.getMessage("notPresentInTable",
|
|
380 |
| new Object[] { |
|
381 |
| "service type name", |
|
382 |
| objectSpec, |
|
383 |
| "service type table" }); |
|
384 |
0
| logger.error(err);
|
|
385 |
0
| throw new CasDBException(err);
|
|
386 |
| } |
|
387 |
0
| validSpec = true;
|
|
388 |
| } |
|
389 |
| |
|
390 |
| |
|
391 |
| |
|
392 |
0
| if (objectSpecDesc.equals(CasConstants.NAMESPACE_SPEC)) {
|
|
393 |
0
| logger.debug("Object spec is \"namespace\". check if it exists in "
|
|
394 |
| + "namespace table "); |
|
395 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_NAMESPACE,
|
|
396 |
| CasDBConstants.COL_NS_NICKNAME, objectSpec)) { |
|
397 |
0
| String err = baseErrMesg
|
|
398 |
| + i18n.getMessage("notPresentInTable", |
|
399 |
| new Object[] { |
|
400 |
| "namespace", |
|
401 |
| objectSpec, |
|
402 |
| "namespace table" }); |
|
403 |
0
| logger.error(err);
|
|
404 |
0
| throw new CasDBException(err);
|
|
405 |
| } |
|
406 |
0
| validSpec = true;
|
|
407 |
| } |
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
0
| if (objectSpecDesc.equals(CasConstants.TRUSTANCHOR_SPEC)) {
|
|
412 |
0
| logger.debug("Object spec is \"trustAnchor\". check if it exists "
|
|
413 |
| + "in TrustAnchor table "); |
|
414 |
0
| if (!CasDBStorage.rowExists(CasDBConstants.TABLE_TRUSTANCHOR,
|
|
415 |
| CasDBConstants.COL_TRUST_NICKNAME, objectSpec)) { |
|
416 |
0
| String err = baseErrMesg
|
|
417 |
| + i18n.getMessage("notPresentInTable", |
|
418 |
| new Object[] { |
|
419 |
| "TrustAnchor", |
|
420 |
| objectSpec, |
|
421 |
| "trustAnchor table" }); |
|
422 |
0
| logger.error(err);
|
|
423 |
0
| throw new CasDBException(err);
|
|
424 |
| } |
|
425 |
0
| validSpec = true;
|
|
426 |
| } |
|
427 |
| |
|
428 |
| |
|
429 |
0
| if (!validSpec) {
|
|
430 |
0
| String errMesg =
|
|
431 |
| i18n.getMessage("invalidObjSpe", new Object[] |
|
432 |
| { CasConstants.OBJECT_SPEC, CasConstants.USER_SPEC, |
|
433 |
| CasConstants.USERGP_SPEC, CasConstants.SERVICETYPE_SPEC, |
|
434 |
| CasConstants.NAMESPACE_SPEC, |
|
435 |
| CasConstants.TRUSTANCHOR_SPEC }); |
|
436 |
0
| logger.error(errMesg);
|
|
437 |
0
| throw new CasDBException(errMesg);
|
|
438 |
| } |
|
439 |
| |
|
440 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
441 |
0
| String query = "insert into" + CasDBConstants.TABLE_OBJECTGP_ENTRY
|
|
442 |
| + " ( " + CasDBConstants.COL_OBJECTGP_NAME + "," |
|
443 |
| + CasDBConstants.COL_OBJECT_SPEC + "," |
|
444 |
| + CasDBConstants.COL_OBJECT_SPEC_DESC + ") values ('" + groupName |
|
445 |
| + "','" + objectSpec + "','" + objectSpecDesc + "')"; |
|
446 |
0
| Statement statement = null;
|
|
447 |
0
| try {
|
|
448 |
0
| statement = connection.createStatement();
|
|
449 |
0
| logger.debug(" query is " + query);
|
|
450 |
0
| statement.executeUpdate(query);
|
|
451 |
0
| statement.close ();
|
|
452 |
| } |
|
453 |
| catch (SQLException exp) { |
|
454 |
0
| logger.error(i18n.getMessage("objGpMemAddErr", query), exp);
|
|
455 |
0
| throw new CasDBException(i18n.getMessage("objGpMemAddErr", "")
|
|
456 |
| + exp.getMessage(), exp); |
|
457 |
| } |
|
458 |
| finally { |
|
459 |
| |
|
460 |
| |
|
461 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
462 |
0
| try {
|
|
463 |
0
| if (statement != null)
|
|
464 |
0
| statement.close();
|
|
465 |
| } |
|
466 |
| catch (SQLException exp) { |
|
467 |
0
| logger.warn(i18n.getMessage("objGpMemAddCloseErr"), exp);
|
|
468 |
| } |
|
469 |
| } |
|
470 |
| } |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
| |
|
476 |
0
| public static void removeGroupMember(String groupName, String objectSpec,
|
|
477 |
| String objectSpecDesc) |
|
478 |
| throws CasDBException { |
|
479 |
| |
|
480 |
0
| if ((groupName == null) || (objectSpec== null) ||
|
|
481 |
| (objectSpecDesc == null)) { |
|
482 |
0
| String err =
|
|
483 |
| i18n.getMessage("paramNull", |
|
484 |
| "Groupname/ObjectSpec/ObjectSpecDesc"); |
|
485 |
0
| logger.error(err);
|
|
486 |
0
| throw new CasDBException(err);
|
|
487 |
| } |
|
488 |
| |
|
489 |
0
| String query = "delete from" + CasDBConstants.TABLE_OBJECTGP_ENTRY
|
|
490 |
| + " where (" + CasDBConstants.COL_OBJECTGP_NAME + "='" |
|
491 |
| + groupName.trim() + "') and (" + CasDBConstants.COL_OBJECT_SPEC |
|
492 |
| + " ='" + objectSpec.trim() + "') and (" |
|
493 |
| + CasDBConstants.COL_OBJECT_SPEC_DESC.trim() + "='" |
|
494 |
| + objectSpecDesc + "')"; |
|
495 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
496 |
0
| Statement statement = null;
|
|
497 |
0
| int result;
|
|
498 |
0
| try {
|
|
499 |
0
| statement = connection.createStatement();
|
|
500 |
0
| logger.debug(" query is " + query);
|
|
501 |
0
| result = statement.executeUpdate(query);
|
|
502 |
| } |
|
503 |
| catch (SQLException exp) { |
|
504 |
0
| logger.error(i18n.getMessage("delObjErr", new Object[] {
|
|
505 |
| "group member", query }), exp); |
|
506 |
0
| throw new CasDBException(i18n.getMessage("delObjErr",
|
|
507 |
| new Object[] { |
|
508 |
| "group member", "" }) |
|
509 |
| + exp.getMessage(), exp); |
|
510 |
| } |
|
511 |
| finally { |
|
512 |
| |
|
513 |
| |
|
514 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
515 |
0
| try {
|
|
516 |
0
| if (statement != null)
|
|
517 |
0
| statement.close();
|
|
518 |
| } |
|
519 |
| catch (SQLException exp) { |
|
520 |
0
| logger.warn(i18n.getMessage("delObjErrClose", "object group"),
|
|
521 |
| exp); |
|
522 |
| } |
|
523 |
| } |
|
524 |
0
| if (result <=0) {
|
|
525 |
0
| String err = i18n.getMessage("objGpMemDelError", new Object[] {
|
|
526 |
| groupName, objectSpec, objectSpecDesc }); |
|
527 |
0
| logger.error(err);
|
|
528 |
0
| throw new CasDBException(err);
|
|
529 |
| } |
|
530 |
| } |
|
531 |
| |
|
532 |
0
| public static void addObjectToGroup(String groupName, String objectName,
|
|
533 |
| String objectNamespace) |
|
534 |
| throws CasDBException { |
|
535 |
| |
|
536 |
0
| String objectId = getObjectId(objectName, objectNamespace);
|
|
537 |
0
| if (objectId == null) {
|
|
538 |
0
| String err = i18n.getMessage("addGpErr")
|
|
539 |
| + i18n.getMessage("objIdRetrErr", objectName + "/" |
|
540 |
| + objectNamespace); |
|
541 |
0
| logger.error(err);
|
|
542 |
0
| throw new CasDBException(err);
|
|
543 |
| } |
|
544 |
0
| addGroupMember(groupName, objectId, CasConstants.OBJECT_SPEC);
|
|
545 |
| } |
|
546 |
| |
|
547 |
0
| public static void removeObjectFromGroup(String groupName,
|
|
548 |
| String objectName, |
|
549 |
| String objectNamespace) |
|
550 |
| throws CasDBException { |
|
551 |
| |
|
552 |
0
| String objectId = getObjectId(objectName, objectNamespace);
|
|
553 |
0
| if (objectId == null) {
|
|
554 |
0
| String err = i18n.getMessage("delObjErr")
|
|
555 |
| + i18n.getMessage("objIdRetrErr", objectName + "/" |
|
556 |
| + objectNamespace); |
|
557 |
0
| logger.error(err);
|
|
558 |
0
| throw new CasDBException(err);
|
|
559 |
| } |
|
560 |
0
| removeGroupMember(groupName, objectId, CasConstants.OBJECT_SPEC);
|
|
561 |
| } |
|
562 |
| |
|
563 |
0
| public static String[] getObjectGroupsForMember(String objectSpec,
|
|
564 |
| String objectSpecDesc) |
|
565 |
| throws CasDBException { |
|
566 |
0
| logger.debug("ObjectGp Member for " + objectSpec.trim() + " "
|
|
567 |
| + objectSpecDesc.trim()); |
|
568 |
0
| String query = "select" + CasDBConstants.COL_OBJECTGP_NAME + " from"
|
|
569 |
| + CasDBConstants.TABLE_OBJECTGP_ENTRY + " where " |
|
570 |
| + CasDBConstants.COL_OBJECT_SPEC + "='" + objectSpec.trim() |
|
571 |
| + "' and " + CasDBConstants.COL_OBJECT_SPEC_DESC + "='" |
|
572 |
| + objectSpecDesc.trim() + "'"; |
|
573 |
0
| Vector groupNames = null;
|
|
574 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
575 |
0
| Statement statement = null;
|
|
576 |
0
| ResultSet resultSet= null;
|
|
577 |
0
| try {
|
|
578 |
0
| statement = connection.createStatement();
|
|
579 |
0
| resultSet = statement.executeQuery(query);
|
|
580 |
0
| if ((resultSet != null) && (resultSet.next())) {
|
|
581 |
0
| groupNames = new Vector(resultSet.getFetchSize());
|
|
582 |
0
| do {
|
|
583 |
0
| groupNames.add(
|
|
584 |
| resultSet.getString( |
|
585 |
| CasDBConstants.COL_OBJECTGP_NAME.trim())); |
|
586 |
0
| } while (resultSet.next());
|
|
587 |
| } |
|
588 |
| } |
|
589 |
| catch (SQLException exp) { |
|
590 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
591 |
| "object group", query }), exp); |
|
592 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
593 |
| new Object[] { |
|
594 |
| "object group", "" }) |
|
595 |
| + exp.getMessage(), exp); |
|
596 |
| } |
|
597 |
| finally { |
|
598 |
| |
|
599 |
| |
|
600 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
601 |
0
| try {
|
|
602 |
0
| if (resultSet != null)
|
|
603 |
0
| resultSet.close();
|
|
604 |
0
| if (statement != null)
|
|
605 |
0
| statement.close();
|
|
606 |
| } |
|
607 |
| catch (SQLException exp) { |
|
608 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
609 |
| "object group"), exp); |
|
610 |
| } |
|
611 |
| } |
|
612 |
0
| return CasDBStorage.vectorToStringArray(groupNames);
|
|
613 |
| } |
|
614 |
| |
|
615 |
0
| public static boolean isMember(String objectSpec, String objSpecDesc)
|
|
616 |
| throws CasDBException { |
|
617 |
| |
|
618 |
0
| if ((objectSpec == null) || (objSpecDesc == null)) {
|
|
619 |
0
| String errMesg = "Parameter(s) null. Could not verify group "
|
|
620 |
| + "membership"; |
|
621 |
0
| logger.error(errMesg);
|
|
622 |
0
| throw new CasDBException(errMesg);
|
|
623 |
| } |
|
624 |
0
| Connection connection = null;
|
|
625 |
0
| try {
|
|
626 |
0
| connection = CasDBStorage.getDBConnection();
|
|
627 |
0
| return isMemberNoValidate(connection, objectSpec, objSpecDesc);
|
|
628 |
| } finally { |
|
629 |
| |
|
630 |
| |
|
631 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
632 |
| } |
|
633 |
| } |
|
634 |
| |
|
635 |
0
| public static boolean isMember(Connection conn, String objectSpec,
|
|
636 |
| String objSpecDesc) |
|
637 |
| throws CasDBException { |
|
638 |
| |
|
639 |
0
| if ((objectSpec == null) || (objSpecDesc == null)) {
|
|
640 |
0
| String errMesg = "Parameter(s) null. Could not verify group "
|
|
641 |
| + "membership"; |
|
642 |
0
| logger.error(errMesg);
|
|
643 |
0
| throw new CasDBException(errMesg);
|
|
644 |
| } |
|
645 |
0
| return isMemberNoValidate(conn, objectSpec, objSpecDesc);
|
|
646 |
| } |
|
647 |
| |
|
648 |
0
| private static boolean isMemberNoValidate(Connection connection,
|
|
649 |
| String objectSpec, |
|
650 |
| String objSpecDesc) |
|
651 |
| throws CasDBException { |
|
652 |
0
| logger.debug("isMember check spec " + objectSpec.trim() + " desc "
|
|
653 |
| + objSpecDesc.trim()); |
|
654 |
0
| String query = "select * from" + CasDBConstants.TABLE_OBJECTGP_ENTRY
|
|
655 |
| + " where ((" + CasDBConstants.COL_OBJECT_SPEC + "='" |
|
656 |
| + objectSpec.trim() + "') and (" |
|
657 |
| + CasDBConstants.COL_OBJECT_SPEC_DESC + "='" + objSpecDesc.trim() |
|
658 |
| + "'))"; |
|
659 |
0
| logger.debug("\n Query is \n" + query + "\n");
|
|
660 |
| |
|
661 |
0
| Statement statement = null;
|
|
662 |
0
| ResultSet resultSet = null;
|
|
663 |
0
| try {
|
|
664 |
0
| statement = connection.createStatement();
|
|
665 |
0
| resultSet = statement.executeQuery(query);
|
|
666 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
667 |
0
| logger.debug("There is an entry and hence is a member ");
|
|
668 |
0
| return true;
|
|
669 |
| } |
|
670 |
| } |
|
671 |
| catch (SQLException exp) { |
|
672 |
0
| logger.error(i18n.getMessage("existenceErr", query), exp);
|
|
673 |
0
| throw new CasDBException(i18n.getMessage("existenceErr", "")
|
|
674 |
| + exp.getMessage(), exp); |
|
675 |
| } |
|
676 |
| finally { |
|
677 |
0
| try {
|
|
678 |
0
| if (resultSet != null)
|
|
679 |
0
| resultSet.close();
|
|
680 |
0
| if (statement != null)
|
|
681 |
0
| statement.close();
|
|
682 |
| } |
|
683 |
| catch (SQLException exp) { |
|
684 |
0
| logger.warn(i18n.getMessage("dataExistenceCloseErr"), exp);
|
|
685 |
| } |
|
686 |
| } |
|
687 |
0
| logger.debug("No entry, not a member");
|
|
688 |
| |
|
689 |
0
| return false;
|
|
690 |
| } |
|
691 |
| } |