CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 779   Methods: 14
NCLOC: 656   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PolicyDataHandler.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Portions of this file Copyright 1999-2005 University of Chicago
 3    * Portions of this file Copyright 1999-2005 The University of Southern California.
 4    *
 5    * This file or a portion of this file is licensed under the
 6    * terms of the Globus Toolkit Public License, found at
 7    * http://www.globus.org/toolkit/download/license.html.
 8    * If you redistribute this file, with or without
 9    * modifications, you must include this notice in the file.
 10    */
 11    package org.globus.cas.impl.databaseAccess;
 12   
 13    import java.sql.ResultSet;
 14    import java.sql.SQLException;
 15    import java.sql.Connection;
 16    import java.sql.Statement;
 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.utils.CasStringUtils;
 24   
 25    import org.globus.cas.impl.CasConstants;
 26   
 27    import org.globus.cas.types.UserData;
 28    import org.globus.cas.types.PolicyData;
 29    import org.globus.cas.types.ObjectData;
 30    import org.globus.cas.types.NamespaceData;
 31    import org.globus.cas.types.CasObjectData;
 32    import org.globus.cas.types.UserGroupData;
 33    import org.globus.cas.types.TrustAnchorData;
 34    import org.globus.cas.types.ServiceTypeData;
 35    import org.globus.cas.types.ObjectGroupData;
 36    import org.globus.cas.types.ArrayOfString;
 37   
 38    import org.globus.util.I18n;
 39   
 40    /**
 41    * Used to manipulate PolicyData in the database
 42    */
 43    public class PolicyDataHandler {
 44   
 45    static Log logger = LogFactory.getLog(PolicyDataHandler.class.getName());
 46   
 47    private static I18n i18n =
 48    I18n.getI18n("org.globus.cas.impl.databaseAccess.errors",
 49    PolicyDataHandler.class.getClassLoader());
 50   
 51    /**
 52    * Store the policy data object - (grant of rights)
 53    * Manipulates only the policy_table in the database
 54    */
 55  0 public static String storeObject(PolicyData policyData)
 56    throws CasDBException {
 57   
 58  0 String baseErrMesg = i18n.getMessage("policyStrErr");
 59   
 60    // Need to ensure that the user/object/action specifed exist
 61    // in the database
 62  0 String userGroupName = policyData.getUserGroupName();
 63  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_USERGP,
 64    CasDBConstants.COL_USERGP_NAME, userGroupName)) {
 65  0 String err = i18n.getMessage("doesNotExistTable", new Object[] {
 66    userGroupName, "user group" });
 67  0 logger.error(err);
 68  0 throw new CasDBException(baseErrMesg + err);
 69    }
 70   
 71  0 boolean actionValid = false;
 72  0 String actionSpec = policyData.getActionSpec();
 73  0 String actionSpecDesc = policyData.getActionSpecDesc();
 74    // action specification can be serviceAction or serviceActionGroup
 75  0 if (actionSpecDesc.equals(CasConstants.SERVICEACTION_SPEC)) {
 76  0 if (!CasDBStorage.rowExists(CasDBConstants
 77    .TABLE_SERVICETYPE_ACTION,
 78    CasDBConstants.COL_SERVICEACTION_ID, actionSpec)) {
 79  0 String errMesg = i18n.getMessage("doesNotExistTable",
 80    new Object[] {
 81    actionSpec,
 82    "service action" });
 83  0 logger.error(errMesg);
 84  0 throw new CasDBException(baseErrMesg + errMesg);
 85    }
 86  0 actionValid = true;
 87    }
 88   
 89  0 if (actionSpecDesc.equals(CasConstants.SERVICEACTIONGP_SPEC)) {
 90  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_SERVICEACTIONGP,
 91    CasDBConstants.COL_SERVICEACTIONGP_NAME,
 92    actionSpec)) {
 93  0 String errMesg = i18n.getMessage("doesNotExistTable",
 94    new Object[] {
 95    actionSpec,
 96    "service action group" });
 97  0 logger.error(errMesg);
 98  0 throw new CasDBException(baseErrMesg + errMesg);
 99    }
 100  0 actionValid = true;
 101    }
 102  0 if (!actionValid) {
 103  0 logger.error(i18n.getMessage("invalidActionSpec"));
 104  0 throw new CasDBException(baseErrMesg
 105    + i18n.getMessage("invalidActionSpec"));
 106   
 107    }
 108   
 109  0 boolean objValid = false;
 110  0 String objectSpec = policyData.getObjectSpec();
 111  0 String objectSpecDesc = policyData.getObjectSpecDesc();
 112    // object specification can be object, objectGroup, user, userGroup,
 113    // serviceType, namespace, trustAnchor
 114    // object
 115  0 if (objectSpecDesc.equals(CasConstants.OBJECT_SPEC)) {
 116  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_OBJECT,
 117    CasDBConstants.COL_OBJECT_ID, objectSpec)) {
 118  0 String errMesg = i18n.getMessage("doesNotExistTable",
 119    new Object[] {
 120    objectSpec,
 121    "object" });
 122  0 logger.error(errMesg);
 123  0 throw new CasDBException(baseErrMesg + errMesg);
 124    }
 125  0 objValid = true;
 126    }
 127    // objectGp
 128  0 if (objectSpecDesc.equals(CasConstants.OBJECTGP_SPEC)) {
 129  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_OBJECTGP,
 130    CasDBConstants.COL_OBJECTGP_NAME, objectSpec)) {
 131  0 String errMesg = i18n.getMessage("doesNotExistTable",
 132    new Object[] {
 133    objectSpec,
 134    "objectGp" });
 135  0 logger.error(errMesg);
 136  0 throw new CasDBException(baseErrMesg + errMesg);
 137    }
 138  0 objValid = true;
 139    }
 140    // user
 141  0 if (objectSpecDesc.equals(CasConstants.USER_SPEC)) {
 142  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_USER,
 143    CasDBConstants.COL_USER_NICKNAME, objectSpec)) {
 144  0 String errMesg = i18n.getMessage("doesNotExistTable",
 145    new Object[] {
 146    objectSpec,
 147    "user" });
 148  0 logger.error(errMesg);
 149  0 throw new CasDBException(baseErrMesg + errMesg);
 150    }
 151  0 objValid = true;
 152    }
 153    // userGp
 154  0 if (objectSpecDesc.equals(CasConstants.USERGP_SPEC)) {
 155  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_USERGP,
 156    CasDBConstants.COL_USERGP_NAME, objectSpec)) {
 157  0 String errMesg = i18n.getMessage("doesNotExistTable",
 158    new Object[] {
 159    objectSpec,
 160    "user group" });
 161  0 logger.error(errMesg);
 162  0 throw new CasDBException(baseErrMesg + errMesg);
 163    }
 164  0 objValid = true;
 165    }
 166    // serviceType
 167  0 if (objectSpecDesc.equals(CasConstants.SERVICETYPE_SPEC)) {
 168  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_SERVICETYPE,
 169    CasDBConstants.COL_SERVICETYPE_NAME, objectSpec)) {
 170  0 String errMesg = i18n.getMessage("doesNotExistTable",
 171    new Object[] {
 172    objectSpec,
 173    "service type" });
 174  0 logger.error(errMesg);
 175  0 throw new CasDBException(baseErrMesg + errMesg);
 176    }
 177  0 objValid = true;
 178    }
 179    // Namespace
 180  0 if (objectSpecDesc.equals(CasConstants.NAMESPACE_SPEC)) {
 181  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_NAMESPACE,
 182    CasDBConstants.COL_NS_NICKNAME, objectSpec)) {
 183  0 String errMesg = i18n.getMessage("doesNotExistTable",
 184    new Object[] {
 185    objectSpec,
 186    "namespace" });
 187  0 logger.error(errMesg);
 188  0 throw new CasDBException(baseErrMesg + errMesg);
 189    }
 190  0 objValid = true;
 191    }
 192    // trust anchor
 193  0 if (objectSpecDesc.equals(CasConstants.TRUSTANCHOR_SPEC)) {
 194  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_TRUSTANCHOR,
 195    CasDBConstants.COL_TRUST_NICKNAME, objectSpec)) {
 196  0 String errMesg = i18n.getMessage("doesNotExistTable",
 197    new Object[] {
 198    objectSpec,
 199    "trustanchor" });
 200  0 logger.error(errMesg);
 201  0 throw new CasDBException(baseErrMesg + errMesg);
 202    }
 203  0 objValid = true;
 204    }
 205    // ServiceActionGp
 206  0 if (objectSpecDesc.equals(CasConstants.SERVICEACTIONGP_SPEC)) {
 207  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_SERVICEACTIONGP,
 208    CasDBConstants.COL_SERVICEACTIONGP_NAME,
 209    objectSpec)) {
 210  0 String errMesg = i18n.getMessage("doesNotExistTable",
 211    new Object[] {
 212    objectSpec,
 213    "service action group" });
 214  0 logger.error(errMesg);
 215  0 throw new CasDBException(baseErrMesg + errMesg);
 216    }
 217  0 objValid = true;
 218    }
 219    // PolicyData
 220  0 if (objectSpecDesc.equals(CasConstants.POLICY_SPEC)) {
 221  0 if (!CasDBStorage.rowExists(CasDBConstants.TABLE_POLICY,
 222    CasDBConstants.COL_POLICY_ID, objectSpec)) {
 223  0 String errMesg = i18n.getMessage("doesNotExistTable",
 224    new Object[] {
 225    objectSpec,
 226    "policy" });
 227  0 logger.error(errMesg);
 228  0 throw new CasDBException(baseErrMesg + errMesg);
 229    }
 230  0 objValid = true;
 231    }
 232   
 233  0 if (!objValid) {
 234  0 logger.error(i18n.getMessage("invalidObjSpec"));
 235  0 throw new CasDBException(baseErrMesg
 236    + i18n.getMessage("invalidObjSpec"));
 237    }
 238   
 239  0 String columnString = "insert into" + CasDBConstants.TABLE_POLICY
 240    + " (" + CasDBConstants.COL_USERGP_NAME + ","
 241    + CasDBConstants.COL_OBJECT_SPEC + ","
 242    + CasDBConstants.COL_OBJECT_SPEC_DESC + ","
 243    + CasDBConstants.COL_ACTION_SPEC + ","
 244    + CasDBConstants.COL_ACTION_SPEC_DESC + ") values ('";
 245   
 246  0 StringBuffer query = new StringBuffer(columnString);
 247  0 query = query.append(policyData.getUserGroupName()).append("','")
 248    .append(policyData.getObjectSpec()).append("','")
 249    .append(policyData.getObjectSpecDesc()).append("','")
 250    .append(policyData.getActionSpec()).append("','")
 251    .append(policyData.getActionSpecDesc()).append("')");
 252  0 CasDBStorage.runUpdateQuery(query.toString());
 253   
 254  0 String resultString = getPolicyId(policyData);
 255  0 if (resultString == null) {
 256  0 logger.error(baseErrMesg);
 257  0 throw new CasDBException(baseErrMesg);
 258    }
 259  0 return resultString;
 260    }
 261   
 262    // given policy object, returns policy id
 263  0 public static String getPolicyId(PolicyData policyObj)
 264    throws CasDBException {
 265   
 266  0 String policyId = null;
 267  0 String userGroupName = policyObj.getUserGroupName();
 268  0 String actionSpec = policyObj.getActionSpec();
 269  0 String actionSpecDesc = policyObj.getActionSpecDesc();
 270  0 String objectSpec = policyObj.getObjectSpec();
 271  0 String objectSpecDesc = policyObj.getObjectSpecDesc();
 272  0 StringBuffer query =
 273    new StringBuffer("select" + CasDBConstants.COL_POLICY_ID + " from"
 274    + CasDBConstants.TABLE_POLICY + " where ("
 275    + CasDBConstants.COL_USERGP_NAME + "='");
 276  0 query = query.append(userGroupName).append("') and (")
 277    .append(CasDBConstants.COL_OBJECT_SPEC).append("='")
 278    .append(objectSpec).append("') and (")
 279    .append(CasDBConstants.COL_OBJECT_SPEC_DESC).append("='")
 280    .append(objectSpecDesc).append("') and (")
 281    .append(CasDBConstants.COL_ACTION_SPEC).append("='")
 282    .append(actionSpec).append("') and (")
 283    .append(CasDBConstants.COL_ACTION_SPEC_DESC).append("='")
 284    .append(actionSpecDesc).append("')");
 285  0 Connection connection = CasDBStorage.getDBConnection();
 286  0 Statement statement = null;
 287  0 ResultSet resultSet = null;
 288  0 try {
 289  0 statement = connection.createStatement();
 290  0 resultSet = statement.executeQuery(query.toString());
 291  0 if ((resultSet!=null) && (resultSet.next())) {
 292  0 policyId = resultSet.getString(
 293    CasDBConstants.COL_POLICY_ID.trim());
 294    }
 295    }
 296    catch (SQLException exp) {
 297  0 logger.error(i18n.getMessage("retrieveErr", new Object [] {
 298    "policy id", query }));
 299  0 throw new CasDBException(i18n.getMessage("retrieveErr",
 300    new Object [] {
 301    "policy id", ""})
 302    + exp.getMessage(), exp);
 303    }
 304    finally {
 305    // returning connection irrespective of whether stmt
 306    // and result set are closed or not.
 307  0 CasDBStorage.returnDBConnection(connection);
 308  0 try {
 309  0 if (resultSet != null)
 310  0 resultSet.close();
 311  0 if (statement != null)
 312  0 statement.close();
 313    }
 314    catch (SQLException exp) {
 315  0 logger.warn(i18n.getMessage("retrieveErrClose", "policy id"),
 316    exp);
 317    }
 318    }
 319  0 return policyId;
 320    }
 321   
 322    /**
 323    * List of all Policy Data
 324    */
 325  0 public static String[] list() throws CasDBException {
 326   
 327  0 String query = "select" + CasDBConstants.COL_POLICY_ID + " from"
 328    + CasDBConstants.TABLE_POLICY;
 329  0 return CasDBStorage.runListQuery(query, CasDBConstants.COL_POLICY_ID);
 330    }
 331   
 332    /*
 333    * Retrieves PolicData data
 334    * Picks up values from policy_table
 335    */
 336  0 public static CasObjectData retrieveObject(String policyId)
 337    throws CasDBException {
 338   
 339  0 PolicyData returnObject = null;
 340  0 String query = "select * from" + CasDBConstants.TABLE_POLICY
 341    + " where" + CasDBConstants.COL_POLICY_ID + " = '"
 342    + policyId.trim() + "'";
 343  0 Connection connection = CasDBStorage.getDBConnection();
 344  0 Statement statement = null;
 345  0 ResultSet resultSet = null;
 346  0 try {
 347  0 statement = connection.createStatement();
 348  0 resultSet = statement.executeQuery(query);
 349  0 if (resultSet!=null) {
 350  0 if (resultSet.next()) {
 351  0 returnObject = new PolicyData();
 352  0 returnObject.setPolicyId(policyId);
 353  0 returnObject.setUserGroupName(
 354    resultSet.getString(
 355    CasDBConstants.COL_USERGP_NAME.trim()));
 356  0 returnObject.setObjectSpec(
 357    resultSet.getString(
 358    CasDBConstants.COL_OBJECT_SPEC.trim()));
 359  0 returnObject.setObjectSpecDesc(
 360    resultSet.getString(
 361    CasDBConstants.COL_OBJECT_SPEC_DESC.trim()));
 362  0 returnObject.setActionSpec(
 363    resultSet.getString(
 364    CasDBConstants.COL_ACTION_SPEC.trim()));
 365  0 returnObject.setActionSpecDesc(
 366    resultSet.getString(
 367    CasDBConstants.COL_ACTION_SPEC_DESC.trim()));
 368    }
 369    }
 370    }
 371    catch (SQLException exp) {
 372  0 logger.error(i18n.getMessage("retrieveErr", new Object[] {
 373    "policy", query }), exp);
 374  0 throw new CasDBException(i18n.getMessage("retrieveErr",
 375    new Object[] {
 376    "policy", "" })
 377    + exp.getMessage() , exp);
 378    }
 379    finally {
 380    // returning connection irrespective of whether stmt
 381    // and result set are closed or not.
 382  0 CasDBStorage.returnDBConnection(connection);
 383  0 try {
 384  0 if (resultSet != null)
 385  0 resultSet.close();
 386  0 if (statement != null)
 387  0 statement.close();
 388    }
 389    catch (SQLException exp) {
 390  0 logger.warn(i18n.getMessage("retrieveErrClose", "policy"),
 391    exp);
 392    }
 393    }
 394  0 return returnObject;
 395    }
 396   
 397    /**
 398    * Remove policy table entry from database - (revoke rights)
 399    * Manipulates only policy table
 400    */
 401  0 public static void deleteObject(String policyId) throws CasDBException {
 402   
 403  0 String query = "delete from" + CasDBConstants.TABLE_POLICY
 404    + " where" + CasDBConstants.COL_POLICY_ID + " = '"
 405    + policyId.trim() + "'";
 406  0 CasDBStorage.runUpdateQuery(query);
 407    }
 408   
 409    /**
 410    * Returns true if policy object exists in the table
 411    * This is *not* a permission query and does not have any
 412    * semantic ramifications
 413    */
 414  0 public boolean policyObjectExists(PolicyData policyData)
 415    throws CasDBException {
 416   
 417  0 String resultString = getPolicyId(policyData);
 418  0 if (resultString == null)
 419  0 return false;
 420    else
 421  0 return true;
 422    }
 423   
 424    /**
 425    * Store the policy represented by the given parameters
 426    * Construct the policy object and store
 427    * Does not handle serviceActionGp as spec
 428    */
 429  0 public static PolicyData grantObject(String userGroupName,
 430    CasObjectData objSpec,
 431    String objSpecDesc, String actionSpec,
 432    String actionSpecDesc )
 433    throws CasDBException {
 434  0 String objSpecString = getObjectSpecString(objSpec, objSpecDesc);
 435  0 return grant(userGroupName, objSpecString, objSpecDesc, actionSpec,
 436    actionSpecDesc);
 437    }
 438    /**
 439    * Store the policy represented by the given parameters
 440    * Construct the policy object and store
 441    */
 442  0 public static PolicyData grant(String userGroupName, String objSpec,
 443    String objSpecDesc, String actionSpec,
 444    String actionSpecDesc )
 445    throws CasDBException {
 446  0 PolicyData returnPolicy = new PolicyData();
 447  0 returnPolicy.setUserGroupName(userGroupName.trim());
 448  0 returnPolicy.setObjectSpec(objSpec.trim());
 449  0 returnPolicy.setObjectSpecDesc(objSpecDesc.trim());
 450  0 returnPolicy.setActionSpec(actionSpec.trim());
 451  0 returnPolicy.setActionSpecDesc(actionSpecDesc.trim());
 452  0 String policyId =storeObject(returnPolicy);
 453  0 returnPolicy.setPolicyId(policyId);
 454  0 return returnPolicy;
 455    }
 456   
 457  0 public static String getObjectSpecString(CasObjectData objSpec,
 458    String objectSpecDesc)
 459    throws CasDBException {
 460   
 461  0 objectSpecDesc = objectSpecDesc.trim();
 462    // object
 463  0 if (objectSpecDesc.equals(CasConstants.OBJECT_SPEC)) {
 464  0 logger.debug("it is object");
 465  0 if (((ObjectData)objSpec).getObjectId() == null) {
 466  0 logger.debug("object id not set");
 467  0 String tempObjName = ((ObjectData)objSpec).getObjectName();
 468  0 String tempObjNS = ((ObjectData)objSpec).getObjectNamespace();
 469  0 int tempObjectId =
 470    ObjectDataHandler.getObjectId(tempObjName, tempObjNS);
 471  0 return Integer.toString(tempObjectId);
 472    }
 473    else
 474  0 return ((ObjectData)objSpec).getObjectId();
 475    }
 476    // objectGp
 477  0 if (objectSpecDesc.equals(CasConstants.OBJECTGP_SPEC)) {
 478  0 logger.debug("it is object group");
 479  0 return ((ObjectGroupData)objSpec).getGroupName();
 480    }
 481    // user
 482  0 if (objectSpecDesc.equals(CasConstants.USER_SPEC)) {
 483  0 logger.debug("it is user");
 484  0 return ((UserData)objSpec).getNickname();
 485    }
 486    // userGp
 487  0 if (objectSpecDesc.equals(CasConstants.USERGP_SPEC)) {
 488  0 logger.debug("it is userGp");
 489  0 return ((UserGroupData)objSpec).getGroupName();
 490    }
 491    // serviceType
 492  0 if (objectSpecDesc.equals(CasConstants.SERVICETYPE_SPEC)) {
 493  0 logger.debug("it is serviceType");
 494  0 return ((ServiceTypeData)objSpec).getName();
 495    }
 496    // Namespace
 497  0 if (objectSpecDesc.equals(CasConstants.NAMESPACE_SPEC)) {
 498  0 logger.debug("it is Namespace");
 499  0 return ((NamespaceData)objSpec).getNickname();
 500    }
 501    // trust anchor
 502  0 if (objectSpecDesc.equals(CasConstants.TRUSTANCHOR_SPEC)) {
 503  0 logger.debug("it is TrustAnchor");
 504  0 return ((TrustAnchorData)objSpec).getNickname();
 505    }
 506    // policy data
 507  0 if (objectSpecDesc.equals(CasConstants.POLICY_SPEC)) {
 508  0 logger.debug("it is policy");
 509  0 return ((PolicyData)objSpec).getPolicyId();
 510    }
 511  0 logger.error(i18n.getMessage("invalidObjSpec"));
 512  0 throw new CasDBException(i18n.getMessage("invalidObjSpec"));
 513    }
 514   
 515  0 public static void deletePolicyForObject(String objectSpec,
 516    String objectSpecDesc)
 517    throws CasDBException {
 518   
 519  0 String query = "delete from" + CasDBConstants.TABLE_POLICY + " where "
 520    + CasDBConstants.COL_OBJECT_SPEC + "='" + objectSpec.trim()
 521    + "' and " + CasDBConstants.COL_OBJECT_SPEC_DESC + "='"
 522    + objectSpecDesc.trim() + "'";
 523  0 CasDBStorage.runUpdateQuery(query);
 524    }
 525   
 526    // Vector of policyData
 527  0 public static Vector constructPolicyData(Connection connection,
 528    ResultSet resultSet,
 529    boolean external)
 530    throws CasDBException {
 531   
 532  0 logger.debug("Construct Policy data " + external);
 533  0 Vector policiesVector = null;
 534  0 try {
 535  0 if ((resultSet != null) && (resultSet.next())) {
 536  0 String selfObjId =
 537    Integer.toString(
 538    ObjectDataHandler
 539    .getObjectId(connection, CasConstants.OBJECT_SELF,
 540    CasConstants.NAMESPACE_SELF));
 541  0 policiesVector = new Vector(resultSet.getFetchSize());
 542  0 do {
 543  0 boolean addPolicy = false;
 544  0 logger.debug("ConstuctData :"
 545    + resultSet.getString(
 546    CasDBConstants.COL_POLICY_ID.trim()));
 547  0 String policyId =
 548    resultSet.getString(
 549    CasDBConstants.COL_POLICY_ID.trim());
 550  0 String userGpName =
 551    resultSet.getString(
 552    CasDBConstants.COL_USERGP_NAME.trim());
 553  0 String objSpec =
 554    resultSet.getString(
 555    CasDBConstants.COL_OBJECT_SPEC.trim());
 556  0 String objSpecDesc =
 557    resultSet.getString(
 558    CasDBConstants.COL_OBJECT_SPEC_DESC.trim());
 559  0 String actionSpec =
 560    resultSet.getString(
 561    CasDBConstants.COL_ACTION_SPEC.trim());
 562  0 String actionSpecDesc = resultSet
 563    .getString(CasDBConstants.COL_ACTION_SPEC_DESC.trim());
 564   
 565  0 if (external) {
 566    // object spec can only be objectgp or object
 567  0 if ((objSpecDesc
 568    .equals(CasConstants.OBJECTGP_SPEC))) {
 569  0 logger.debug("external and Object group "
 570    + "processing");
 571  0 Vector tempVector =
 572    getPolicyFromObjGp(connection,
 573    policyId, userGpName,
 574    objSpec, actionSpec,
 575    actionSpecDesc);
 576  0 if (tempVector != null) {
 577  0 logger.debug("adding the object gp policies "
 578    + tempVector.size());
 579  0 policiesVector.addAll(tempVector);
 580    }
 581    } else {
 582  0 if (objSpecDesc
 583    .equals(CasConstants.OBJECT_SPEC)) {
 584  0 logger.debug("External and object");
 585  0 if (!objSpec.equals(selfObjId)) {
 586  0 if ((actionSpecDesc.equals(
 587    CasConstants.SERVICEACTIONGP_SPEC))) {
 588  0 logger.debug("not cas, action gp");
 589  0 Vector tempVector =
 590    getPolicyFromActionGp(connection,
 591    policyId,
 592    userGpName,
 593    objSpec,
 594    actionSpec);
 595  0 if (tempVector != null) {
 596  0 logger.debug("adding action gp "
 597    + " policies");
 598  0 policiesVector.addAll(tempVector);
 599    }
 600    } else
 601  0 addPolicy = true;
 602    } else
 603  0 logger.debug("Cas policy");
 604    }
 605    }
 606    } else {
 607  0 logger.debug("Not external");
 608  0 addPolicy = true;
 609    }
 610   
 611  0 if (addPolicy) {
 612  0 logger.debug("constructin policy");
 613  0 logger.debug("adding policy " + policyId);
 614  0 PolicyData policyData = new PolicyData();
 615  0 policyData.setPolicyId(policyId);
 616  0 policyData.setUserGroupName(userGpName);
 617  0 policyData.setObjectSpec(objSpec);
 618  0 policyData.setObjectSpecDesc(objSpecDesc);
 619  0 policyData.setActionSpec(actionSpec);
 620  0 policyData.setActionSpecDesc(actionSpecDesc);
 621  0 policiesVector.add(policyData);
 622    }
 623  0 } while (resultSet.next());
 624    }
 625    }
 626    catch (SQLException exp) {
 627  0 logger.error(i18n.getMessage("constPolicyErr"), exp);
 628  0 throw new CasDBException(i18n.getMessage("constPolicyErr")
 629    + exp.getMessage(), exp);
 630    }
 631    finally {
 632  0 try {
 633  0 if (resultSet != null)
 634  0 resultSet.close();
 635    }
 636    catch (SQLException exp) {
 637  0 logger.warn(i18n.getMessage("constPolicyErrClose"), exp);
 638    }
 639    }
 640  0 if ((policiesVector != null) && (policiesVector.size() >0)) {
 641  0 if (logger.isDebugEnabled()) {
 642  0 printPolicyVector(policiesVector);
 643    }
 644  0 return policiesVector;
 645    }
 646    else
 647  0 return null;
 648    }
 649   
 650    // Returns set of policies that are part of the service action group
 651    // expects ObjectSpec is always object and not cas
 652  0 private static Vector getPolicyFromActionGp(Connection connection,
 653    String policyId,
 654    String userGpName,
 655    String objectSpec,
 656    String actionSpec)
 657    throws CasDBException {
 658  0 logger.debug("getPolicyFromActionGp " + actionSpec);
 659  0 String serviceActionId[] =
 660    ServiceTypeActionHandler.retrieveServiceActionGpEntriesAsId(
 661    connection, actionSpec);
 662  0 if (serviceActionId != null) {
 663  0 logger.debug("service action gp has members, adding");
 664  0 Vector policiesVector = new Vector(serviceActionId.length);
 665  0 for (int i=0; i<serviceActionId.length; i++) {
 666  0 logger.debug("adding policy id " + policyId);
 667  0 PolicyData policyData = new PolicyData();
 668  0 policyData.setPolicyId(policyId);
 669  0 policyData.setUserGroupName(userGpName);
 670  0 policyData.setObjectSpec(objectSpec);
 671  0 policyData.setObjectSpecDesc(CasConstants.OBJECT_SPEC);
 672  0 policyData.setActionSpec(serviceActionId[i]);
 673  0 policyData.setActionSpecDesc(
 674    CasConstants.SERVICEACTION_SPEC);
 675  0 policiesVector.add(policyData);
 676    }
 677  0 return policiesVector;
 678    }
 679  0 return null;
 680    }
 681   
 682    // Returns set of policies that are part of this object group
 683    // Only external policies are returned
 684  0 private static Vector getPolicyFromObjGp(Connection connection,
 685    String policyId,
 686    String userGpName,
 687    String objSpec,
 688    String actionSpec,
 689    String actionSpecDesc)
 690    throws CasDBException {
 691  0 logger.debug("getPolicyFromObjGp " + objSpec);
 692   
 693  0 int selfObjId =
 694    ObjectDataHandler.getObjectId(connection,
 695    CasConstants.OBJECT_SELF,
 696    CasConstants.NAMESPACE_SELF);
 697   
 698  0 String query = "select * from" + CasDBConstants.TABLE_OBJECTGP_ENTRY
 699    + " where (" + CasDBConstants.COL_OBJECTGP_NAME + "='"
 700    + objSpec + "') and (" + CasDBConstants.COL_OBJECT_SPEC_DESC
 701    + "='" + CasConstants.OBJECT_SPEC + "') and not ("
 702    + CasDBConstants.COL_OBJECT_SPEC + " ='"
 703    + Integer.toString(selfObjId) + "')";
 704   
 705  0 logger.debug("query " + query);
 706  0 Vector policiesVector = null;
 707  0 Statement statement = null;
 708  0 ResultSet resultSet = null;
 709  0 try {
 710  0 statement = connection.createStatement();
 711  0 resultSet = statement.executeQuery(query);
 712  0 if ((resultSet != null) && (resultSet.next())) {
 713  0 logger.debug("result size " + resultSet.getFetchSize());
 714  0 policiesVector = new Vector(resultSet.getFetchSize());
 715  0 do {
 716  0 String objSpecDesc =
 717    resultSet.getString(
 718    CasDBConstants.COL_OBJECT_SPEC_DESC.trim());
 719  0 String objName =
 720    resultSet.getString(
 721    CasDBConstants.COL_OBJECT_SPEC.trim());
 722  0 if (actionSpecDesc.equals(
 723    CasConstants.SERVICEACTIONGP_SPEC)) {
 724  0 logger.debug("Action gp");
 725  0 Vector tempVector =
 726    getPolicyFromActionGp(connection, policyId,
 727    userGpName,
 728    objName, actionSpec);
 729  0 if (tempVector != null) {
 730  0 logger.debug("adding action gp policies");
 731  0 policiesVector.addAll(tempVector);
 732    }
 733    }
 734    else {
 735    // This policy object will have objectSpec as
 736    // object and actionSpec as action
 737  0 logger.debug("adding policy with obj and action"
 738    + policyId);
 739  0 PolicyData policyData = new PolicyData();
 740  0 policyData.setPolicyId(policyId);
 741  0 policyData.setUserGroupName(userGpName);
 742  0 policyData.setObjectSpec(objName);
 743  0 policyData.setObjectSpecDesc(objSpecDesc);
 744  0 policyData.setActionSpec(actionSpec);
 745  0 policyData.setActionSpecDesc(actionSpecDesc);
 746  0 policiesVector.add(policyData);
 747    }
 748  0 } while (resultSet.next());
 749    }
 750    }
 751    catch (SQLException exp) {
 752  0 logger.error(i18n.getMessage("retrPolicyGpMem", query), exp);
 753  0 throw new CasDBException(i18n.getMessage("retrPolicyGpMem", "")
 754    + exp.getMessage(), exp);
 755    }
 756    finally {
 757  0 try {
 758  0 if (resultSet != null)
 759  0 resultSet.close();
 760  0 if (statement != null)
 761  0 statement.close();
 762    }
 763    catch (SQLException exp) {
 764  0 logger.warn(i18n.getMessage("retrPolicyGpMemClose"), exp);
 765    }
 766    }
 767  0 return policiesVector;
 768    }
 769   
 770  0 public static void printPolicyVector(Vector policies) {
 771  0 if (policies != null) {
 772  0 logger.debug("Printing policies " + policies.size());
 773  0 for (int i=0; i<policies.size(); i++) {
 774  0 logger.debug(CasStringUtils.policyToString(
 775    (PolicyData)policies.get(i)));
 776    }
 777    }
 778    }
 779    }