Coverage Report - org.kuali.rice.kns.service.impl.BusinessObjectAuthorizationServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectAuthorizationServiceImpl
0%
0/204
0%
0/116
4.043
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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.kuali.rice.kns.service.impl;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 21  
 import org.kuali.rice.kim.api.KimConstants;
 22  
 import org.kuali.rice.kim.api.identity.Person;
 23  
 import org.kuali.rice.kim.api.permission.PermissionService;
 24  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 25  
 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
 26  
 import org.kuali.rice.kns.datadictionary.FieldDefinition;
 27  
 import org.kuali.rice.kns.datadictionary.InquiryCollectionDefinition;
 28  
 import org.kuali.rice.kns.datadictionary.InquirySectionDefinition;
 29  
 import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition;
 30  
 import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition;
 31  
 import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
 32  
 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
 33  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 34  
 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
 35  
 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictionsBase;
 36  
 import org.kuali.rice.kns.document.authorization.InquiryOrMaintenanceDocumentRestrictions;
 37  
 import org.kuali.rice.kns.document.authorization.InquiryOrMaintenanceDocumentRestrictionsBase;
 38  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
 39  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictionsBase;
 40  
 import org.kuali.rice.kns.inquiry.InquiryRestrictions;
 41  
 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
 42  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 43  
 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
 44  
 import org.kuali.rice.krad.authorization.BusinessObjectAuthorizer;
 45  
 import org.kuali.rice.krad.bo.BusinessObject;
 46  
 import org.kuali.rice.krad.bo.authorization.InquiryOrMaintenanceDocumentAuthorizer;
 47  
 import org.kuali.rice.krad.bo.authorization.InquiryOrMaintenanceDocumentPresentationController;
 48  
 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
 49  
 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
 50  
 import org.kuali.rice.krad.document.Document;
 51  
 import org.kuali.rice.krad.document.authorization.MaintenanceDocumentAuthorizer;
 52  
 import org.kuali.rice.krad.document.authorization.MaintenanceDocumentPresentationController;
 53  
 import org.kuali.rice.krad.inquiry.InquiryAuthorizer;
 54  
 import org.kuali.rice.krad.inquiry.InquiryPresentationController;
 55  
 import org.kuali.rice.krad.service.BusinessObjectDictionaryService;
 56  
 import org.kuali.rice.krad.service.DataDictionaryService;
 57  
 import org.kuali.rice.krad.service.DocumentHelperService;
 58  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 59  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 60  
 import org.kuali.rice.krad.service.impl.DataObjectAuthorizationServiceImpl;
 61  
 import org.kuali.rice.krad.util.KRADConstants;
 62  
 import org.kuali.rice.krad.util.KRADUtils;
 63  
 import org.kuali.rice.krad.util.ObjectUtils;
 64  
 
 65  
 import java.util.Collection;
 66  
 import java.util.Collections;
 67  
 import java.util.HashMap;
 68  
 import java.util.Iterator;
 69  
 import java.util.List;
 70  
 import java.util.Map;
 71  
 
 72  
 @Deprecated
 73  0
 public class BusinessObjectAuthorizationServiceImpl extends DataObjectAuthorizationServiceImpl implements BusinessObjectAuthorizationService {
 74  
         private DataDictionaryService dataDictionaryService;
 75  
         private PermissionService permissionService;
 76  
         private BusinessObjectDictionaryService businessObjectDictionaryService;
 77  
         private DocumentHelperService documentHelperService;
 78  
         private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService;
 79  
         private ConfigurationService kualiConfigurationService;
 80  
         
 81  
         public BusinessObjectRestrictions getLookupResultRestrictions(
 82  
                         Object dataObject, Person user) {
 83  0
                 BusinessObjectRestrictions businessObjectRestrictions = new BusinessObjectRestrictionsBase();
 84  0
                 considerBusinessObjectFieldUnmaskAuthorization(dataObject, user,
 85  
                                 businessObjectRestrictions, "", null);
 86  0
                 return businessObjectRestrictions;
 87  
         }
 88  
 
 89  
         public InquiryRestrictions getInquiryRestrictions(
 90  
                         BusinessObject businessObject, Person user) {
 91  0
                 InquiryRestrictions inquiryRestrictions = new InquiryOrMaintenanceDocumentRestrictionsBase();
 92  0
                 BusinessObjectEntry businessObjectEntry = (BusinessObjectEntry) getDataDictionaryService()
 93  
                                 .getDataDictionary().getBusinessObjectEntry(
 94  
                                                 businessObject.getClass().getName());
 95  0
                 InquiryPresentationController inquiryPresentationController = getBusinessObjectDictionaryService()
 96  
                                 .getInquiryPresentationController(businessObject.getClass());
 97  0
                 InquiryAuthorizer inquiryAuthorizer = getBusinessObjectDictionaryService()
 98  
                                 .getInquiryAuthorizer(businessObject.getClass());
 99  0
                 considerBusinessObjectFieldUnmaskAuthorization(businessObject, user,
 100  
                                 inquiryRestrictions, "", null);
 101  0
                 considerBusinessObjectFieldViewAuthorization(businessObjectEntry,
 102  
                                 businessObject, null, user, inquiryAuthorizer, inquiryRestrictions,
 103  
                                 "");
 104  0
                 considerInquiryOrMaintenanceDocumentPresentationController(
 105  
                                 inquiryPresentationController, businessObject,
 106  
                                 inquiryRestrictions);
 107  0
                 considerInquiryOrMaintenanceDocumentAuthorizer(inquiryAuthorizer,
 108  
                                 businessObject, user, inquiryRestrictions);
 109  0
                 for (InquirySectionDefinition inquirySectionDefinition : businessObjectEntry.getInquiryDefinition().getInquirySections()) {
 110  0
                         if (inquirySectionDefinition.getInquiryCollections() != null) {
 111  0
                                 addInquirableItemRestrictions(inquirySectionDefinition.getInquiryCollections().values(), inquiryAuthorizer, 
 112  
                                                 inquiryRestrictions, businessObject, businessObject, "", user);
 113  
                         }
 114  
                         // Collections may also be stored in the inquiry fields, so we need to parse through that
 115  0
                         List<FieldDefinition> inquiryFields = inquirySectionDefinition.getInquiryFields();
 116  0
                         if (inquiryFields != null) {
 117  0
                                 for (FieldDefinition fieldDefinition : inquiryFields) {
 118  0
                                         addInquirableItemRestrictions(inquiryFields, inquiryAuthorizer, 
 119  
                                                         inquiryRestrictions, businessObject, businessObject, "", user);
 120  
                                 }
 121  
                         }
 122  0
                 }
 123  
                 
 124  0
                 return inquiryRestrictions;
 125  
         }
 126  
 
 127  
         public MaintenanceDocumentRestrictions getMaintenanceDocumentRestrictions(
 128  
                         MaintenanceDocument maintenanceDocument, Person user) {
 129  
 
 130  0
                 MaintenanceDocumentRestrictions maintenanceDocumentRestrictions = new MaintenanceDocumentRestrictionsBase();
 131  0
                 DataObjectEntry dataObjectEntry = getDataDictionaryService()
 132  
                                 .getDataDictionary().getDataObjectEntry(
 133  
                                                 maintenanceDocument.getNewMaintainableObject()
 134  
                                                                 .getDataObject().getClass().getName());
 135  0
                 MaintenanceDocumentPresentationController maintenanceDocumentPresentationController = (MaintenanceDocumentPresentationController) getDocumentHelperService()
 136  
                                 .getDocumentPresentationController(maintenanceDocument);
 137  0
                 MaintenanceDocumentAuthorizer maintenanceDocumentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentHelperService()
 138  
                                 .getDocumentAuthorizer(maintenanceDocument);
 139  0
                 considerBusinessObjectFieldUnmaskAuthorization(maintenanceDocument
 140  
                                 .getNewMaintainableObject().getDataObject(), user,
 141  
                                 maintenanceDocumentRestrictions, "", maintenanceDocument );
 142  0
                 considerBusinessObjectFieldViewAuthorization(dataObjectEntry,
 143  
                                 maintenanceDocument.getNewMaintainableObject().getDataObject(),
 144  
                                 null, user, maintenanceDocumentAuthorizer,
 145  
                                 maintenanceDocumentRestrictions, "");
 146  0
                 considerBusinessObjectFieldModifyAuthorization(dataObjectEntry,
 147  
                                 maintenanceDocument.getNewMaintainableObject().getDataObject(),
 148  
                                 null, user, maintenanceDocumentAuthorizer,
 149  
                                 maintenanceDocumentRestrictions, "");
 150  0
                 considerCustomButtonFieldAuthorization(dataObjectEntry,
 151  
                                 maintenanceDocument.getNewMaintainableObject().getDataObject(),
 152  
                                 null, user, maintenanceDocumentAuthorizer,
 153  
                                 maintenanceDocumentRestrictions, "");
 154  0
                 considerInquiryOrMaintenanceDocumentPresentationController(
 155  
                                 maintenanceDocumentPresentationController, maintenanceDocument,
 156  
                                 maintenanceDocumentRestrictions);
 157  0
                 considerInquiryOrMaintenanceDocumentAuthorizer(
 158  
                                 maintenanceDocumentAuthorizer, maintenanceDocument, user,
 159  
                                 maintenanceDocumentRestrictions);
 160  0
                 considerMaintenanceDocumentPresentationController(
 161  
                                 maintenanceDocumentPresentationController, maintenanceDocument,
 162  
                                 maintenanceDocumentRestrictions);
 163  0
                 considerMaintenanceDocumentAuthorizer(maintenanceDocumentAuthorizer,
 164  
                                 maintenanceDocument, user, maintenanceDocumentRestrictions);
 165  
                 
 166  0
                 MaintenanceDocumentEntry maintenanceDocumentEntry = getMaintenanceDocumentDictionaryService().getMaintenanceDocumentEntry(maintenanceDocument
 167  
                                 .getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
 168  0
                 for (MaintainableSectionDefinition maintainableSectionDefinition : maintenanceDocumentEntry.getMaintainableSections()) {
 169  0
                         addMaintainableItemRestrictions(maintainableSectionDefinition.getMaintainableItems(), maintenanceDocumentAuthorizer, maintenanceDocumentRestrictions,
 170  
                                         maintenanceDocument, maintenanceDocument.getNewMaintainableObject().getBusinessObject(), "", user);
 171  
                 }
 172  0
                 return maintenanceDocumentRestrictions;
 173  
         }
 174  
 
 175  
         protected void considerBusinessObjectFieldUnmaskAuthorization(Object dataObject, Person user, BusinessObjectRestrictions businessObjectRestrictions, String propertyPrefix, Document document) {
 176  0
                 DataObjectEntry objectEntry = getDataDictionaryService().getDataDictionary().getDataObjectEntry(dataObject.getClass().getName());
 177  0
                 for (String attributeName : objectEntry.getAttributeNames()) {
 178  0
                         AttributeDefinition attributeDefinition = objectEntry.getAttributeDefinition(attributeName);
 179  0
                         if (attributeDefinition.getAttributeSecurity() != null) {
 180  0
                                 if (attributeDefinition.getAttributeSecurity().isMask() && 
 181  
                                                 !canFullyUnmaskField(user, dataObject.getClass(), attributeName, document)) {
 182  0
                                         businessObjectRestrictions.addFullyMaskedField(propertyPrefix + attributeName, attributeDefinition.getAttributeSecurity().getMaskFormatter());
 183  
                                 }
 184  0
                                 if (attributeDefinition.getAttributeSecurity().isPartialMask() && 
 185  
                                                 !canPartiallyUnmaskField(user, dataObject.getClass(), attributeName, document)) {
 186  0
                                         businessObjectRestrictions.addPartiallyMaskedField(propertyPrefix + attributeName, attributeDefinition.getAttributeSecurity().getPartialMaskFormatter());
 187  
                                 }
 188  
                         }
 189  0
                 }
 190  0
         }
 191  
 
 192  
         /**
 193  
          * @param dataObjectEntry if collectionItemBusinessObject is not null, then it is the DD entry for collectionItemBusinessObject.
 194  
          * Otherwise, it is the entry for primaryBusinessObject
 195  
          * @param primaryDataObject the top-level BO that is being inquiried or maintained
 196  
          * @param collectionItemBusinessObject an element of a collection under the primaryBusinessObject that we are evaluating view auths for
 197  
          * @param user the logged in user
 198  
          * @param businessObjectAuthorizer
 199  
          * @param inquiryOrMaintenanceDocumentRestrictions
 200  
          * @param propertyPrefix
 201  
          */
 202  
         protected void considerBusinessObjectFieldViewAuthorization(
 203  
                         DataObjectEntry dataObjectEntry,
 204  
                         Object primaryDataObject,
 205  
                         BusinessObject collectionItemBusinessObject,
 206  
                         Person user,
 207  
                         BusinessObjectAuthorizer businessObjectAuthorizer,
 208  
                         InquiryOrMaintenanceDocumentRestrictions inquiryOrMaintenanceDocumentRestrictions,
 209  
                         String propertyPrefix) {
 210  0
                 for (String attributeName : dataObjectEntry.getAttributeNames()) {
 211  0
                         AttributeDefinition attributeDefinition = dataObjectEntry
 212  
                                         .getAttributeDefinition(attributeName);
 213  0
                         if (attributeDefinition.getAttributeSecurity() != null) {
 214  0
                                 if (attributeDefinition.getAttributeSecurity().isHide()) {
 215  0
                                         Map<String, String> collectionItemPermissionDetails = new HashMap<String, String>();
 216  0
                                         Map<String, String> collectionItemRoleQualifications = null;
 217  0
                                         if (ObjectUtils.isNotNull(collectionItemBusinessObject)) {
 218  0
                                                 collectionItemPermissionDetails.putAll(getFieldPermissionDetails(collectionItemBusinessObject, attributeName));
 219  0
                                                 collectionItemPermissionDetails.putAll(businessObjectAuthorizer.
 220  
                                                                 getCollectionItemPermissionDetails(collectionItemBusinessObject));
 221  0
                                                 collectionItemRoleQualifications = new HashMap<String, String>(businessObjectAuthorizer.
 222  
                                                                 getCollectionItemRoleQualifications(collectionItemBusinessObject));
 223  
                                         }
 224  
                                         else {
 225  0
                                                 collectionItemPermissionDetails.putAll(getFieldPermissionDetails(primaryDataObject, attributeName));
 226  
                                         }
 227  0
                                         if (!businessObjectAuthorizer
 228  
                                                         .isAuthorizedByTemplate(
 229  
                                                                         primaryDataObject,
 230  
                                                                         KRADConstants.KRAD_NAMESPACE,
 231  
                                                                         KimConstants.PermissionTemplateNames.VIEW_FIELD,
 232  
                                                                         user.getPrincipalId(),
 233  
                                                                         collectionItemPermissionDetails,
 234  
                                                                         collectionItemRoleQualifications)) {
 235  0
                                                 inquiryOrMaintenanceDocumentRestrictions
 236  
                                                                 .addHiddenField(propertyPrefix + attributeName);
 237  
                                         }
 238  
                                 }
 239  
                         }
 240  0
                 }
 241  0
         }
 242  
 
 243  
         /**
 244  
          * @param dataObjectEntry if collectionItemBusinessObject is not null, then it is the DD entry for collectionItemBusinessObject.
 245  
          * Otherwise, it is the entry for primaryBusinessObject
 246  
          * @param primaryDataObject the top-level BO that is being inquiried or maintained
 247  
          * @param collectionItemBusinessObject an element of a collection under the primaryBusinessObject that we are evaluating view auths for
 248  
          * @param user the logged in user
 249  
          * @param businessObjectAuthorizer
 250  
          * @param inquiryOrMaintenanceDocumentRestrictions
 251  
          * @param propertyPrefix
 252  
          */
 253  
         protected void considerBusinessObjectFieldModifyAuthorization(
 254  
                         DataObjectEntry dataObjectEntry,
 255  
                         Object primaryDataObject,
 256  
                         BusinessObject collectionItemBusinessObject, Person user,
 257  
                         BusinessObjectAuthorizer businessObjectAuthorizer,
 258  
                         MaintenanceDocumentRestrictions maintenanceDocumentRestrictions,
 259  
                         String propertyPrefix) {
 260  0
                 for (String attributeName : dataObjectEntry.getAttributeNames()) {
 261  0
                         AttributeDefinition attributeDefinition = dataObjectEntry
 262  
                                         .getAttributeDefinition(attributeName);
 263  0
                         if (attributeDefinition.getAttributeSecurity() != null) {
 264  0
                                 Map<String, String> collectionItemPermissionDetails = new HashMap<String, String>();
 265  0
                                 Map<String, String> collectionItemRoleQualifications = null;
 266  0
                                 if (ObjectUtils.isNotNull(collectionItemBusinessObject)) {
 267  0
                                         collectionItemPermissionDetails.putAll(getFieldPermissionDetails(collectionItemBusinessObject, attributeName));
 268  0
                                         collectionItemPermissionDetails.putAll(businessObjectAuthorizer.
 269  
                                                         getCollectionItemPermissionDetails(collectionItemBusinessObject));
 270  0
                                         collectionItemRoleQualifications = new HashMap<String, String>(businessObjectAuthorizer.
 271  
                                                         getCollectionItemRoleQualifications(collectionItemBusinessObject));
 272  
                                 }
 273  
                                 else {
 274  0
                                         collectionItemPermissionDetails.putAll(getFieldPermissionDetails(primaryDataObject, attributeName));
 275  
                                 }
 276  0
                                 if (attributeDefinition.getAttributeSecurity().isReadOnly()) {
 277  0
                                         if (!businessObjectAuthorizer
 278  
                                                                 .isAuthorizedByTemplate(
 279  
                                                                                 primaryDataObject,
 280  
                                                                                 KRADConstants.KRAD_NAMESPACE,
 281  
                                                                                 KimConstants.PermissionTemplateNames.MODIFY_FIELD,
 282  
                                                                                 user.getPrincipalId(),
 283  
                                                                                 collectionItemPermissionDetails,
 284  
                                                                                 collectionItemRoleQualifications)) {
 285  0
                                                 maintenanceDocumentRestrictions
 286  
                                                                 .addReadOnlyField(propertyPrefix + attributeName);
 287  
                                         }
 288  
                                 }
 289  
                         }
 290  0
                 }
 291  0
         }
 292  
         
 293  
         /**
 294  
          * @param dataObjectEntry if collectionItemBusinessObject is not null, then it is the DD entry for collectionItemBusinessObject.
 295  
          * Otherwise, it is the entry for primaryBusinessObject
 296  
          * @param primaryDataObject the top-level BO that is being inquiried or maintained
 297  
          * @param collectionItemBusinessObject an element of a collection under the primaryBusinessObject that we are evaluating view auths for
 298  
          * @param user the logged in user
 299  
          * @param businessObjectAuthorizer
 300  
          * @param inquiryOrMaintenanceDocumentRestrictions
 301  
          * @param propertyPrefix
 302  
          */
 303  
         protected void considerCustomButtonFieldAuthorization(
 304  
                         DataObjectEntry dataObjectEntry,
 305  
                         Object primaryDataObject,
 306  
                         BusinessObject collectionItemBusinessObject,
 307  
                         Person user,
 308  
                         BusinessObjectAuthorizer businessObjectAuthorizer,
 309  
                         MaintenanceDocumentRestrictions maintenanceDocumentRestrictions,
 310  
                         String propertyPrefix) {
 311  0
                 for (String attributeName : dataObjectEntry.getAttributeNames()) {
 312  0
                         AttributeDefinition attributeDefinition = dataObjectEntry
 313  
                                         .getAttributeDefinition(attributeName);
 314  
                         // TODO what is the equivalent of control.isButton in KRAD
 315  0
                         if (attributeDefinition.getControl() != null &&
 316  
                                 attributeDefinition.getControl().isButton()) {
 317  0
                                 Map<String, String> collectionItemPermissionDetails = new HashMap<String, String>();
 318  0
                                 Map<String, String> collectionItemRoleQualifications = null;
 319  0
                                 if (ObjectUtils.isNotNull(collectionItemBusinessObject)) {
 320  0
                                         collectionItemPermissionDetails.putAll(getButtonFieldPermissionDetails(collectionItemBusinessObject, attributeName));
 321  0
                                         collectionItemPermissionDetails.putAll(businessObjectAuthorizer.
 322  
                                                         getCollectionItemPermissionDetails(collectionItemBusinessObject));
 323  0
                                         collectionItemRoleQualifications = new HashMap<String, String>(businessObjectAuthorizer.
 324  
                                                         getCollectionItemRoleQualifications(collectionItemBusinessObject));
 325  
                                 }
 326  
                                 else {
 327  0
                                         getButtonFieldPermissionDetails(primaryDataObject, attributeName);
 328  
                                 }
 329  
                                 
 330  0
                                 if (!businessObjectAuthorizer
 331  
                                                 .isAuthorizedByTemplate(
 332  
                                                                 primaryDataObject,
 333  
                                                                 KRADConstants.KRAD_NAMESPACE,
 334  
                                                                 KimConstants.PermissionTemplateNames.PERFORM_CUSTOM_MAINTENANCE_DOCUMENT_FUNCTION,
 335  
                                                                 user.getPrincipalId(),
 336  
                                                                 collectionItemPermissionDetails,
 337  
                                                                 collectionItemRoleQualifications)) {
 338  0
                                         maintenanceDocumentRestrictions
 339  
                                                         .addHiddenField(propertyPrefix + attributeName);
 340  
                                 }
 341  
                         }
 342  0
                 }
 343  0
         }
 344  
 
 345  
         protected void considerInquiryOrMaintenanceDocumentPresentationController(
 346  
                         InquiryOrMaintenanceDocumentPresentationController businessObjectPresentationController,
 347  
                         BusinessObject businessObject,
 348  
                         InquiryOrMaintenanceDocumentRestrictions inquiryOrMaintenanceDocumentRestrictions) {
 349  0
                 for (String attributeName : businessObjectPresentationController
 350  
                                 .getConditionallyHiddenPropertyNames(businessObject)) {
 351  0
                         inquiryOrMaintenanceDocumentRestrictions
 352  
                                         .addHiddenField(attributeName);
 353  
                 }
 354  0
                 for (String sectionId : businessObjectPresentationController
 355  
                                 .getConditionallyHiddenSectionIds(businessObject)) {
 356  0
                         inquiryOrMaintenanceDocumentRestrictions
 357  
                                         .addHiddenSectionId(sectionId);
 358  
                 }
 359  0
         }
 360  
 
 361  
         protected void considerInquiryOrMaintenanceDocumentAuthorizer(
 362  
                         InquiryOrMaintenanceDocumentAuthorizer authorizer,
 363  
                         BusinessObject businessObject, Person user,
 364  
                         InquiryOrMaintenanceDocumentRestrictions restrictions) {
 365  0
                 for (String sectionId : authorizer
 366  
                                 .getSecurePotentiallyHiddenSectionIds()) {
 367  0
                         Map<String, String> additionalPermissionDetails = new HashMap<String, String>();
 368  0
                         additionalPermissionDetails
 369  
                                         .put(KimConstants.AttributeConstants.SECTION_ID, sectionId);
 370  0
                         if (!authorizer.isAuthorizedByTemplate(businessObject,
 371  
                                         KRADConstants.KRAD_NAMESPACE,
 372  
                                         KimConstants.PermissionTemplateNames.VIEW_SECTION, user
 373  
                                                         .getPrincipalId(), additionalPermissionDetails,
 374  
                                         null)) {
 375  0
                                 restrictions.addHiddenSectionId(sectionId);
 376  
                         }
 377  0
                 }
 378  0
         }
 379  
 
 380  
         protected void considerMaintenanceDocumentPresentationController(
 381  
                         MaintenanceDocumentPresentationController presentationController,
 382  
                         MaintenanceDocument document,
 383  
                         MaintenanceDocumentRestrictions restrictions) {
 384  0
                 for (String attributeName : presentationController
 385  
                                 .getConditionallyReadOnlyPropertyNames(document)) {
 386  0
                         restrictions.addReadOnlyField(attributeName);
 387  
                 }
 388  0
                 for (String sectionId : presentationController
 389  
                                 .getConditionallyReadOnlySectionIds(document)) {
 390  0
                         restrictions.addReadOnlySectionId(sectionId);
 391  
                 }
 392  0
         }
 393  
 
 394  
         protected void considerMaintenanceDocumentAuthorizer(
 395  
                         MaintenanceDocumentAuthorizer authorizer,
 396  
                         MaintenanceDocument document, Person user,
 397  
                         MaintenanceDocumentRestrictions restrictions) {
 398  0
                 for (String sectionId : authorizer
 399  
                                 .getSecurePotentiallyReadOnlySectionIds()) {
 400  0
                         Map<String, String> additionalPermissionDetails = new HashMap<String, String>();
 401  0
                         additionalPermissionDetails
 402  
                                         .put(KimConstants.AttributeConstants.SECTION_ID, sectionId);
 403  0
                         if (!authorizer.isAuthorizedByTemplate(document,
 404  
                                         KRADConstants.KRAD_NAMESPACE,
 405  
                                         KimConstants.PermissionTemplateNames.MODIFY_SECTION, user
 406  
                                                         .getPrincipalId(), additionalPermissionDetails,
 407  
                                         null)) {
 408  0
                                 restrictions.addReadOnlySectionId(sectionId);
 409  
                         }
 410  0
                 }
 411  0
         }
 412  
 
 413  
         @SuppressWarnings("unchecked")
 414  
         protected void addInquirableItemRestrictions(Collection sectionDefinitions,
 415  
                         InquiryAuthorizer authorizer, InquiryRestrictions restrictions,
 416  
                         BusinessObject primaryBusinessObject,
 417  
                         BusinessObject businessObject, String propertyPrefix, Person user) {
 418  0
                 for (Object inquirableItemDefinition : sectionDefinitions) {
 419  0
                         if (inquirableItemDefinition instanceof InquiryCollectionDefinition) {
 420  0
                                 InquiryCollectionDefinition inquiryCollectionDefinition = (InquiryCollectionDefinition) inquirableItemDefinition;
 421  0
                                 BusinessObjectEntry collectionBusinessObjectEntry = (BusinessObjectEntry) getDataDictionaryService()
 422  
                                                 .getDataDictionary().getBusinessObjectEntry(
 423  
                                                                 inquiryCollectionDefinition.getBusinessObjectClass().getName());
 424  
 
 425  
                                 try {
 426  0
                                         Collection<BusinessObject> collection = (Collection<BusinessObject>) PropertyUtils
 427  
                                                         .getProperty(businessObject,
 428  
                                                                         inquiryCollectionDefinition.getName());
 429  0
                                         int i = 0;
 430  0
                                         for (Iterator<BusinessObject> iterator = collection.iterator(); iterator
 431  0
                                                         .hasNext();) {
 432  0
                                                 String newPropertyPrefix = propertyPrefix + inquiryCollectionDefinition.getName() + "[" + i + "].";
 433  0
                                                 BusinessObject collectionItemBusinessObject = iterator.next();
 434  0
                                                 considerBusinessObjectFieldUnmaskAuthorization(
 435  
                                                                 collectionItemBusinessObject, user, restrictions,
 436  
                                                                 newPropertyPrefix, null);
 437  0
                                                 considerBusinessObjectFieldViewAuthorization(
 438  
                                                                 collectionBusinessObjectEntry, primaryBusinessObject, collectionItemBusinessObject,
 439  
                                                                 user, authorizer, restrictions, newPropertyPrefix);
 440  0
                                                 addInquirableItemRestrictions(
 441  
                                                                 inquiryCollectionDefinition
 442  
                                                                                 .getInquiryCollections(),
 443  
                                                                 authorizer,
 444  
                                                                 restrictions,
 445  
                                                                 primaryBusinessObject,
 446  
                                                                 collectionItemBusinessObject,
 447  
                                                                 newPropertyPrefix,
 448  
                                                                 user);
 449  0
                                                 i++;
 450  0
                                         }
 451  0
                                 } catch (Exception e) {
 452  0
                                         throw new RuntimeException(
 453  
                                                         "Unable to resolve collection property: "
 454  
                                                                         + businessObject.getClass() + ":"
 455  
                                                                         + inquiryCollectionDefinition.getName(), e);
 456  0
                                 }
 457  0
                         }
 458  
                 }
 459  0
         }
 460  
 
 461  
         @SuppressWarnings("unchecked")
 462  
         protected void addMaintainableItemRestrictions(List<? extends MaintainableItemDefinition> itemDefinitions,
 463  
                         MaintenanceDocumentAuthorizer authorizer,
 464  
                         MaintenanceDocumentRestrictions restrictions,
 465  
                         MaintenanceDocument maintenanceDocument,
 466  
                         BusinessObject businessObject, String propertyPrefix, Person user) {
 467  0
                 for (MaintainableItemDefinition maintainableItemDefinition : itemDefinitions) {
 468  0
                         if (maintainableItemDefinition instanceof MaintainableCollectionDefinition) {
 469  
                                 try {
 470  0
                                         MaintainableCollectionDefinition maintainableCollectionDefinition = (MaintainableCollectionDefinition) maintainableItemDefinition;
 471  
                                         
 472  0
                                         Collection<BusinessObject> collection = (Collection<BusinessObject>) ObjectUtils
 473  
                                                         .getNestedValue(businessObject,
 474  
                                                                         maintainableItemDefinition.getName());
 475  0
                                         BusinessObjectEntry collectionBusinessObjectEntry = (BusinessObjectEntry) getDataDictionaryService()
 476  
                                                         .getDataDictionary().getBusinessObjectEntry(
 477  
                                                                         maintainableCollectionDefinition.getBusinessObjectClass().getName());
 478  0
                                         if (collection != null && !collection.isEmpty()) {
 479  0
                                             int i = 0;
 480  0
                                              for (Iterator<BusinessObject> iterator = collection.iterator(); iterator
 481  0
                                                         .hasNext();) {
 482  0
                                                      String newPropertyPrefix = propertyPrefix + maintainableItemDefinition.getName() + "[" + i + "].";
 483  0
                                                     BusinessObject collectionBusinessObject = iterator.next();
 484  0
                                                     considerBusinessObjectFieldUnmaskAuthorization(
 485  
                                                                 collectionBusinessObject, user, restrictions,
 486  
                                                                 newPropertyPrefix, maintenanceDocument);
 487  0
                                                     considerBusinessObjectFieldViewAuthorization(
 488  
                                                                 collectionBusinessObjectEntry, maintenanceDocument, collectionBusinessObject, user,
 489  
                                                                 authorizer, restrictions, newPropertyPrefix);
 490  0
                                                     considerBusinessObjectFieldModifyAuthorization(
 491  
                                                                 collectionBusinessObjectEntry, maintenanceDocument, collectionBusinessObject, user,
 492  
                                                                 authorizer, restrictions, newPropertyPrefix);
 493  0
                                                     addMaintainableItemRestrictions(
 494  
                                                                 ((MaintainableCollectionDefinition) maintainableItemDefinition)
 495  
                                                                                 .getMaintainableCollections(),
 496  
                                                                 authorizer, restrictions, maintenanceDocument,
 497  
                                                                 collectionBusinessObject, newPropertyPrefix,
 498  
                                                                 user);
 499  0
                                                      addMaintainableItemRestrictions(
 500  
                                                                 ((MaintainableCollectionDefinition) maintainableItemDefinition)
 501  
                                                                                 .getMaintainableFields(), authorizer,
 502  
                                                                 restrictions, maintenanceDocument,
 503  
                                                                 collectionBusinessObject, newPropertyPrefix,
 504  
                                                                 user);
 505  0
                                                     i++;
 506  0
                                             }
 507  
                                         }
 508  0
                                 } catch (Exception e) {
 509  0
                                         throw new RuntimeException(
 510  
                                                         "Unable to resolve collection property: "
 511  
                                                                         + businessObject.getClass() + ":"
 512  
                                                                         + maintainableItemDefinition.getName(), e);
 513  0
                                 }
 514  
                         }
 515  
                 }
 516  0
         }
 517  
         
 518  
         public boolean canFullyUnmaskField(Person user,
 519  
                         Class<?> dataObjectClass, String fieldName, Document document) {
 520  
                 // KFSMI-5095
 521  0
                 if(isNonProductionEnvAndUnmaskingTurnedOff())
 522  0
                         return false;
 523  
 
 524  0
                 if(user==null || StringUtils.isEmpty(user.getPrincipalId())) 
 525  0
                         return false;
 526  0
                 Boolean result = null;
 527  0
                 if (document != null) { // if a document was passed, evaluate the permission in the context of a document
 528  
                         try { // try/catch and fallthrough is a fix for KULRICE-3365
 529  0
                                 result = getDocumentHelperService().getDocumentAuthorizer( document )
 530  
                                 .isAuthorizedByTemplate( document, 
 531  
                                                 KRADConstants.KRAD_NAMESPACE,
 532  
                                                 KimConstants.PermissionTemplateNames.FULL_UNMASK_FIELD, 
 533  
                                                 user.getPrincipalId(), getFieldPermissionDetails(dataObjectClass, fieldName), null  );
 534  0
                         } catch (IllegalArgumentException e) { 
 535  
                                 // document didn't have needed metadata
 536  
                                 // TODO: this requires intimate knowledge of DocumentHelperServiceImpl 
 537  0
                         } 
 538  
                 }
 539  0
                 if (result == null) { 
 540  0
                         result = getPermissionService().isAuthorizedByTemplateName(
 541  
                                         user.getPrincipalId(),
 542  
                                         KRADConstants.KRAD_NAMESPACE,
 543  
                                         KimConstants.PermissionTemplateNames.FULL_UNMASK_FIELD,
 544  
                                         new HashMap<String, String>(getFieldPermissionDetails(dataObjectClass, fieldName)),
 545  
                                         Collections.<String, String>emptyMap());
 546  
                 }
 547  0
                 return result; // should be safe to return Boolean here since the only circumstances that
 548  
                                // will leave it null will result in an exception being thrown above.
 549  
         }
 550  
 
 551  
         public boolean canPartiallyUnmaskField(
 552  
                         Person user, Class<?> dataObjectClass, String fieldName, Document document) {
 553  
                 // KFSMI-5095
 554  0
                 if(isNonProductionEnvAndUnmaskingTurnedOff())
 555  0
                         return false;
 556  
                 
 557  0
                 if(user==null || StringUtils.isEmpty(user.getPrincipalId())) 
 558  0
                         return false;
 559  
 
 560  0
                 if ( document == null ) {
 561  0
                         return getPermissionService().isAuthorizedByTemplateName(
 562  
                                         user.getPrincipalId(),
 563  
                                         KRADConstants.KRAD_NAMESPACE,
 564  
                                         KimConstants.PermissionTemplateNames.PARTIAL_UNMASK_FIELD,
 565  
                                         new HashMap<String, String>(getFieldPermissionDetails(dataObjectClass,fieldName)),
 566  
                                         Collections.<String, String>emptyMap());
 567  
                 } else { // if a document was passed, evaluate the permission in the context of a document
 568  0
                         return getDocumentHelperService().getDocumentAuthorizer( document )
 569  
                                         .isAuthorizedByTemplate( document, 
 570  
                                                                                          KRADConstants.KRAD_NAMESPACE,
 571  
                                                                                          KimConstants.PermissionTemplateNames.PARTIAL_UNMASK_FIELD, 
 572  
                                                                                          user.getPrincipalId(), getFieldPermissionDetails(dataObjectClass, fieldName), Collections.<String, String>emptyMap()  );
 573  
                 }
 574  
         }
 575  
 
 576  
         protected Map<String, String> getFieldPermissionDetails(
 577  
                         Class<?> dataObjectClass, String attributeName) {
 578  
                 try {
 579  0
                         return getFieldPermissionDetails(dataObjectClass.newInstance(),
 580  
                                         attributeName);
 581  0
                 } catch (Exception e) {
 582  0
                         throw new RuntimeException(
 583  
                                         "The getPermissionDetails method of BusinessObjectAuthorizationServiceImpl was unable to instantiate the dataObjectClass"
 584  
                                                         + dataObjectClass, e);
 585  
                 }
 586  
         }
 587  
 
 588  
         protected Map<String, String> getFieldPermissionDetails(
 589  
                         Object dataObject, String attributeName) {
 590  0
                 Map<String, String> permissionDetails = null;
 591  0
                 String namespaceCode = null;
 592  0
                 String componentName = null;
 593  0
                 String propertyName = null;
 594  
                 // JHK: commenting out for KFSMI-2398 - permission checks need to be done at the level specified
 595  
                 // that is, if the parent object specifies the security, that object should be used for the 
 596  
                 // component
 597  
 //                if (attributeName.contains(".")) {
 598  
 //                        try {
 599  
 //                                permissionDetails = KimCommonUtils
 600  
 //                                                .getNamespaceAndComponentSimpleName(PropertyUtils
 601  
 //                                                                .getPropertyType(businessObject, attributeName
 602  
 //                                                                                .substring(0, attributeName
 603  
 //                                                                                                .lastIndexOf("."))));
 604  
 //                        } catch (Exception e) {
 605  
 //                                throw new RuntimeException(
 606  
 //                                                "Unable to discover nested business object class: "
 607  
 //                                                                + businessObject.getClass() + " : "
 608  
 //                                                                + attributeName, e);
 609  
 //                        }
 610  
 //                        permissionDetails.put(KimAttributes.PROPERTY_NAME, attributeName
 611  
 //                                        .substring(attributeName.indexOf(".") + 1));
 612  
 //                } else {
 613  0
                         permissionDetails = KRADUtils
 614  
                                         .getNamespaceAndComponentSimpleName(dataObject.getClass());
 615  0
                         permissionDetails.put(KimConstants.AttributeConstants.PROPERTY_NAME, attributeName);
 616  
 //                }
 617  0
                 return permissionDetails;
 618  
         }
 619  
         
 620  
         protected Map<String, String> getButtonFieldPermissionDetails(
 621  
                         Object businessObject, String attributeName) {
 622  0
                 Map<String, String> permissionDetails = new HashMap<String, String>();
 623  0
                 if (attributeName.contains(".")) {
 624  0
                         permissionDetails.put(KimConstants.AttributeConstants.BUTTON_NAME, attributeName);
 625  
                 } else {
 626  0
                         permissionDetails.put(KimConstants.AttributeConstants.BUTTON_NAME, attributeName);
 627  
                 }
 628  0
                 return permissionDetails;
 629  
         }
 630  
 
 631  
         private PermissionService getPermissionService() {
 632  0
                 if (permissionService == null) {
 633  0
                         permissionService = KimApiServiceLocator
 634  
                                         .getPermissionService();
 635  
                 }
 636  0
                 return permissionService;
 637  
         }
 638  
 
 639  
         private BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
 640  0
                 if (businessObjectDictionaryService == null) {
 641  0
                         businessObjectDictionaryService = KRADServiceLocatorWeb
 642  
                                         .getBusinessObjectDictionaryService();
 643  
                 }
 644  0
                 return businessObjectDictionaryService;
 645  
         }
 646  
 
 647  
         private MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() {
 648  0
                 if (maintenanceDocumentDictionaryService == null) {
 649  0
                         maintenanceDocumentDictionaryService = KNSServiceLocator
 650  
                                         .getMaintenanceDocumentDictionaryService();
 651  
                 }
 652  0
                 return maintenanceDocumentDictionaryService;
 653  
         }
 654  
 
 655  
         private ConfigurationService getKualiConfigurationService() {
 656  0
                 if (kualiConfigurationService == null) {
 657  0
                         kualiConfigurationService = KRADServiceLocator.getKualiConfigurationService();
 658  
                 }
 659  0
                 return kualiConfigurationService;
 660  
         }
 661  
 
 662  
         private boolean isNonProductionEnvAndUnmaskingTurnedOff(){
 663  0
                 return !getKualiConfigurationService().getPropertyValueAsString(KRADConstants.PROD_ENVIRONMENT_CODE_KEY)
 664  
                 .equalsIgnoreCase(
 665  
                         getKualiConfigurationService().getPropertyValueAsString(KRADConstants.ENVIRONMENT_KEY)) &&
 666  
                                 !getKualiConfigurationService().getPropertyValueAsBoolean(KRADConstants.ENABLE_NONPRODUCTION_UNMASKING);
 667  
         }
 668  
 
 669  
 }