All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.internet2.middleware.grouper.grouperUi.beans.ui.ProvisioningContainer Maven / Gradle / Ivy

There is a newer version: 5.13.5
Show newest version
/**
 * @author mchyzer
 * $Id$
 */
package edu.internet2.middleware.grouper.grouperUi.beans.ui;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.Member;
import edu.internet2.middleware.grouper.MemberFinder;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioner;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningAttributeValue;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningObjectMetadataItem;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningService;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningSettings;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningTarget;
import edu.internet2.middleware.grouper.exception.GrouperSessionException;
import edu.internet2.middleware.grouper.grouperUi.beans.api.GuiGroup;
import edu.internet2.middleware.grouper.grouperUi.beans.api.GuiStem;
import edu.internet2.middleware.grouper.grouperUi.beans.api.GuiSubject;
import edu.internet2.middleware.grouper.grouperUi.beans.api.provisioning.GuiGrouperProvisioningAttributeValue;
import edu.internet2.middleware.grouper.grouperUi.beans.api.provisioning.GuiGrouperSyncObject;
import edu.internet2.middleware.grouper.grouperUi.beans.json.GuiPaging;
import edu.internet2.middleware.grouper.grouperUi.serviceLogic.UiV2Group;
import edu.internet2.middleware.grouper.grouperUi.serviceLogic.UiV2Stem;
import edu.internet2.middleware.grouper.misc.GrouperObject;
import edu.internet2.middleware.grouper.misc.GrouperSessionHandler;
import edu.internet2.middleware.grouper.privs.AccessPrivilege;
import edu.internet2.middleware.grouper.privs.NamingPrivilege;
import edu.internet2.middleware.grouper.privs.PrivilegeHelper;
import edu.internet2.middleware.grouper.ui.GrouperUiFilter;
import edu.internet2.middleware.grouperClient.jdbc.tableSync.GcGrouperSyncGroup;
import edu.internet2.middleware.grouperClient.jdbc.tableSync.GcGrouperSyncLog;
import edu.internet2.middleware.grouperClient.jdbc.tableSync.GcGrouperSyncMember;
import edu.internet2.middleware.grouperClient.jdbc.tableSync.GcGrouperSyncMembership;
import edu.internet2.middleware.subject.Subject;

public class ProvisioningContainer {
  
  /**
   * for externalized text, current config suffix
   */
  private String currentConfigSuffix;
  
  /**
   * for externalized text, current config suffix
   */
  private String currentConfigValueTruncatedEscaped;

  
  /**
   * for externalized text, current config suffix
   * @return
   */
  public String getCurrentConfigSuffix() {
    return currentConfigSuffix;
  }

  /**
   * for externalized text, current config suffix
   * @param currentConfigSuffix
   */
  public void setCurrentConfigSuffix(String currentConfigSuffix) {
    this.currentConfigSuffix = currentConfigSuffix;
  }

  /**
   * for externalized text, current config suffix
   * @return
   */
  public String getCurrentConfigValueTruncatedEscaped() {
    return currentConfigValueTruncatedEscaped;
  }

  /**
   * for externalized text, current config suffix
   * @param currentConfigValueTruncatedEscaped
   */
  public void setCurrentConfigValueTruncatedEscaped(String currentConfigValueTruncatedEscaped) {
    this.currentConfigValueTruncatedEscaped = currentConfigValueTruncatedEscaped;
  }


  /**
   * target name user is currently working on
   */
  private String targetName;
  
  /**
   * attribute value for given group/stem and type
   */
  private GrouperProvisioningAttributeValue grouperProvisioningAttributeValue;
  
  /**
   * grouper proivisioning object metadata items
   */
  private List grouperProvisioningObjectMetadataItems = new ArrayList();
  
  /**
   * list of all grouper provisioning attribute values for a given group/stem
   */
  private List guiGrouperProvisioningAttributeValues = new ArrayList();

  
  private GuiGrouperProvisioningAttributeValue currentGuiGrouperProvisioningAttributeValue = null;
  
  
  public GuiGrouperProvisioningAttributeValue getCurrentGuiGrouperProvisioningAttributeValue() {
    return currentGuiGrouperProvisioningAttributeValue;
  }

  
  public void setCurrentGuiGrouperProvisioningAttributeValue(
      GuiGrouperProvisioningAttributeValue currentGuiGrouperProvisioningAttributeValue) {
    this.currentGuiGrouperProvisioningAttributeValue = currentGuiGrouperProvisioningAttributeValue;
  }


  /**
   * number of groups in a folder for a provisioner target 
   */
  private long groupsCount;
  
  /**
   * number of users in a folder for a provisioner target
   */
  private long usersCount;
  
  /**
   * number of memberships in a folder for a provisioner target
   */
  private long membershipsCount;
  
  /**
   * gc grouper sync group to show for a particular group and provisioner 
   */
  private GcGrouperSyncGroup gcGrouperSyncGroup;
  
  /**
   * logs for a particular group
   */
  private List gcGrouperSyncLogs = new ArrayList();
  
  /**
   * grouper sync members to show on subject provisioning screen
   */
  private List gcGrouperSyncMembers = new ArrayList();
  
  /**
   * grouper sync memberships to show on membership provisioning screen
   */
  private List gcGrouperSyncMemberships = new ArrayList();
  
  /**
   * gc grouper sync membership to show for a particular membership with provisioner 
   */
  private GcGrouperSyncMembership gcGrouperSyncMembership;

  /**
   * gc grouper sync member to show for a particular member with provisioner 
   */
  private GcGrouperSyncMember gcGrouperSyncMember;
  
  /**
   * encapsulate gcGrouperSyncMember/gcGrouperSyncMember with direct settings
   */
  private GuiGrouperSyncObject guiGrouperSyncObject;
  
  /**
   * encapsulate gcGrouperSyncMember/gcGrouperSyncMember with direct settings
   */
  private List guiGrouperSyncObjects = new ArrayList();
  
  /**
   * @return target name user is currently working on
   */
  public String getTargetName() {
    return targetName;
  }

  /**
   * target name user is currently working on
   * @param targetName
   */
  public void setTargetName(String targetName) {
    this.targetName = targetName;
  }
  
  
  /**
   * @return attribute value for given group/stem and type
   */
  public GrouperProvisioningAttributeValue getGrouperProvisioningAttributeValue() {
    return grouperProvisioningAttributeValue;
  }

  /**
   * attribute value for given group/stem and type
   * @param grouperProvisioningAttributeValue
   */
  public void setGrouperProvisioningAttributeValue(GrouperProvisioningAttributeValue grouperProvisioningAttributeValue) {
    this.grouperProvisioningAttributeValue = grouperProvisioningAttributeValue;
  }

  /**
   * @return list of all grouper provisioning attribute values for a given group/stem
   */
  public List getGuiGrouperProvisioningAttributeValues() {
    return guiGrouperProvisioningAttributeValues;
  }


  /**
   * list of all grouper provisioning attribute values for a given group/stem
   * @param guiGrouperProvisioningAttributeValues
   */
  public void setGuiGrouperProvisioningAttributeValues(List guiGrouperProvisioningAttributeValues) {
    this.guiGrouperProvisioningAttributeValues = guiGrouperProvisioningAttributeValues;
  }
  
  private boolean canViewProvisioningMenu(List provisioningAttributeValues, Subject loggedInSubject, GrouperObject grouperObject) {

    Map targets = GrouperProvisioningSettings.getTargets(true);
    
    // out of all the provisioners that have been configured on this group/stem/subject/membership, if one of them is viewable by the logged in user
    // we need to show the Provisioning option in the menu item
    
    for(GrouperProvisioningAttributeValue provisioningAttributeValue: provisioningAttributeValues) {
      
      String localTargetName = provisioningAttributeValue.getTargetName();
      GrouperProvisioningTarget provisioningTarget = targets.get(localTargetName);
      if (provisioningTarget != null && GrouperProvisioningService.isTargetViewable(provisioningTarget, loggedInSubject, grouperObject)) {
        return true;
      }
      
    }
    
    return getViewableTargets().size() > 0;
  }
  
  
  public boolean isCanReadProvisioningForMembership() {
    
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();

    if (PrivilegeHelper.isWheelOrRootOrViewonlyRoot(loggedInSubject)) {
      return true;
    }
    
    GuiGroup guiGroup = GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().getGuiGroup();
    GuiSubject guiSubject = GrouperRequestContainer.retrieveFromRequestOrCreate().getSubjectContainer().getGuiSubject();

    if (guiGroup != null && guiSubject != null) {
      if (!GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().isCanRead()) {
        return false;
      }
      
      Member member = (Member)GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {
        
        @Override
        public Object callback(GrouperSession theGrouperSession) throws GrouperSessionException {
          return MemberFinder.findBySubject(theGrouperSession, guiSubject.getSubject(), true);
          
        }
      });
      
      List provisioningAttributeValues =  GrouperProvisioningService.getProvisioningAttributeValues(guiGroup.getGroup(), member);
      
      boolean canViewProvisioningMenu = canViewProvisioningMenu(provisioningAttributeValues, loggedInSubject, null);
      if (canViewProvisioningMenu) {
        return true;
      }
      
      return false;
    }
    
    return false;
    
  }
  
  public boolean isCanReadProvisioningForGroup() {
    
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();

    if (PrivilegeHelper.isWheelOrRootOrViewonlyRoot(loggedInSubject)) {
      return true;
    }
    
    GuiGroup guiGroup = GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().getGuiGroup();
    
    if (guiGroup != null) {
      if (!GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().isCanView()) {
        return false;
      }
      
      Map allTargets = GrouperProvisioningSettings.getTargets(true);
      
      for (String targetNameSingle: allTargets.keySet()) {
        GrouperProvisioningTarget grouperProvisioningTarget = allTargets.get(targetNameSingle);
        if (GrouperProvisioningService.isTargetViewable(grouperProvisioningTarget, loggedInSubject, guiGroup.getGroup())) {
         return true;
        }
      } 
      
      return false;
    }
    
    return false;
  }
  
  public boolean isCanReadProvisioningForSubject() {
    
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();

    if (PrivilegeHelper.isWheelOrRootOrViewonlyRoot(loggedInSubject)) {
      return true;
    }
    
    GuiSubject guiSubject = GrouperRequestContainer.retrieveFromRequestOrCreate().getSubjectContainer().getGuiSubject();
    
    if (guiSubject != null) {
      
      Member member = (Member)GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {
        
        @Override
        public Object callback(GrouperSession theGrouperSession) throws GrouperSessionException {
          
          return MemberFinder.findBySubject(theGrouperSession, guiSubject.getSubject(), true);
          
        }
      });
      
      if (member != null) {
        List provisioningAttributeValues = GrouperProvisioningService.getProvisioningAttributeValues(member);
        boolean canViewProvisioningMenu = canViewProvisioningMenu(provisioningAttributeValues, loggedInSubject, null);
        
        if (canViewProvisioningMenu) {
          return true;
        }
      }
      
      
      return false;
    }
    
    return false;
    
  }
  
  public boolean isCanReadProvisioningForStem() {
    
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();

    if (PrivilegeHelper.isWheelOrRootOrViewonlyRoot(loggedInSubject)) {
      return true;
    }
    
    GuiStem guiStem = GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().getGuiStem();
    
    if (guiStem != null) {
      
      if (!GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().isCanViewPrivileges()) {
        return false;
      }
      
      Map allTargets = GrouperProvisioningSettings.getTargets(true);
      
      for (String targetNameSingle: allTargets.keySet()) {
        GrouperProvisioningTarget grouperProvisioningTarget = allTargets.get(targetNameSingle);
        if (GrouperProvisioningService.isTargetViewable(grouperProvisioningTarget, loggedInSubject, guiStem.getStem())) {
         return true;
        }
      } 
      
      return false;
    }
    
    return false;
    
  }
  
  /**
   * 
   * @return true if can write
   */
  public boolean isCanAssignProvisioning() {

    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    if (PrivilegeHelper.isWheelOrRoot(loggedInSubject)) {
      return true;
    }
    
    return getEditableTargets().size() > 0;
    
  }

  /**
   * 
   * @return true if can write
   */
  public boolean isCanWriteProvisioning() {

    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    if (PrivilegeHelper.isWheelOrRoot(loggedInSubject)) {
      return true;
    }
    
//    Boolean allowedInProvisioningGroup = null;
//    if (!StringUtils.isBlank(GrouperUiConfig.retrieveConfig().propertyValueString("uiV2.provisioning.must.be.in.group"))) {
//      String error = GrouperUiFilter.requireUiGroup("uiV2.provisioning.must.be.in.group", loggedInSubject, false);
//      //null error means allow
//      allowedInProvisioningGroup = ( error == null );
//    }
//
//    GuiGroup guiGroup = GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().getGuiGroup();
//    
//    if (guiGroup != null) {
//      if (!GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().isCanAdmin()) {
//        return false;
//      }
//      if (allowedInProvisioningGroup != null) {
//        return allowedInProvisioningGroup;
//      }
//      return true;
//    }
//
//    GuiStem guiStem = GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().getGuiStem();
//    
//    if (guiStem != null) {
//      if (!GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().isCanAdminPrivileges()) {
//        return false;
//      }
//      if (allowedInProvisioningGroup != null) {
//        return allowedInProvisioningGroup;
//      }
//      return true;
//    }

    return false;
  }
  
  /**
   * if this object or any parent has provisioning settings configured
   * @return if there is type
   */
  public boolean isHasProvisioningOnThisObjectOrParent() {
    
    for (GuiGrouperProvisioningAttributeValue attributeValue: guiGrouperProvisioningAttributeValues) {
      if (attributeValue.getGrouperProvisioningAttributeValue().isDirectAssignment() || StringUtils.isNotBlank(attributeValue.getGrouperProvisioningAttributeValue().getOwnerStemId())) {
        return true;
      }
    }
    
    return false;
  }
  
  /**
   * 
   * @return true if can run daemon
   */
  public boolean isCanRunDaemon() {
    
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    if (PrivilegeHelper.isWheelOrRoot(loggedInSubject)) {
      return true;
    }
    
    return false;
  }
  
  /**
   * if provisioning in ui is enabled in the config
   * @return true if enabled
   */
  public boolean isProvisioningEnabled() {
    return GrouperProvisioningSettings.provisioningInUiEnabled();
  }
  
  /**
   * @return all targets
   */
  public Set getTargets() {
    return new HashSet(GrouperProvisioningSettings.getTargets(true).values());
  }
  
  /**
   * get editable targets for current group/stem and logged in subject
   * @return
   */
  public Set getEditableTargets() {
    
    GrouperObject grouperObject = null;
    
    GuiGroup guiGroup = GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().getGuiGroup();
    GuiStem guiStem = GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().getGuiStem();
    
    if (guiGroup != null) {
      grouperObject = guiGroup.getGrouperObject();
    }
    if (guiStem != null) {
      grouperObject = guiStem.getGrouperObject();
    }
    
    Map targets = GrouperProvisioningSettings.getTargets(true);
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    
    Set editableTargets = new HashSet();
    
    for (GrouperProvisioningTarget target: targets.values()) {
      if (GrouperProvisioningService.isTargetEditable(target, loggedInSubject, grouperObject)) {
        editableTargets.add(target);
      }
    }
    
    return editableTargets;
  }

  /**
   * get viewable targets for current group/stem and logged in subject
   * @return
   */
  public Set getViewableTargets() {
    
    GrouperObject grouperObject = null;
    
    GuiGroup guiGroup = GrouperRequestContainer.retrieveFromRequestOrCreate().getGroupContainer().getGuiGroup();
    GuiStem guiStem = GrouperRequestContainer.retrieveFromRequestOrCreate().getStemContainer().getGuiStem();
    
    if (guiGroup != null) {
      grouperObject = guiGroup.getGrouperObject();
    }
    if (guiStem != null) {
      grouperObject = guiStem.getGrouperObject();
    }
    
    Map targets = GrouperProvisioningSettings.getTargets(true);
    Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    
    Set viewableTargets = new HashSet();
    
    for (GrouperProvisioningTarget target: targets.values()) {
      if (GrouperProvisioningService.isTargetViewable(target, loggedInSubject, grouperObject)) {
        viewableTargets.add(target);
      }
    }
    
    return viewableTargets;
  }
  
  /**
   * number of groups in a folder for a provisioner target 
   * @return
   */
  public long getGroupsCount() {
    return groupsCount;
  }

  /**
   * number of groups in a folder for a provisioner target 
   * @param groupsCount
   */
  public void setGroupsCount(long groupsCount) {
    this.groupsCount = groupsCount;
  }

  /**
   * number of users in a folder for a provisioner target 
   * @return
   */
  public long getUsersCount() {
    return usersCount;
  }

  /**
   * number of users in a folder for a provisioner target 
   * @param usersCount
   */
  public void setUsersCount(long usersCount) {
    this.usersCount = usersCount;
  }

  /**
   * number of memberships in a folder for a provisioner target 
   * @return
   */
  public long getMembershipsCount() {
    return membershipsCount;
  }

  /**
   * number of memberships in a folder for a provisioner target 
   * @param membershipsCount
   */
  public void setMembershipsCount(long membershipsCount) {
    this.membershipsCount = membershipsCount;
  }

  /**
   * grouper sync members to show on subject provisioning screen
   * @return
   */
  public List getGcGrouperSyncMembers() {
    return gcGrouperSyncMembers;
  }

  /**
   * grouper sync members to show on subject provisioning screen
   * @param gcGrouperSyncMembers
   */
  public void setGcGrouperSyncMembers(List gcGrouperSyncMembers) {
    this.gcGrouperSyncMembers = gcGrouperSyncMembers;
  }

  /**
   * grouper sync memberships to show on membership provisioning screen
   * @return
   */
  public List getGcGrouperSyncMemberships() {
    return gcGrouperSyncMemberships;
  }

  /**
   * grouper sync memberships to show on membership provisioning screen
   * @param gcGrouperSyncMemberships
   */
  public void setGcGrouperSyncMemberships(List gcGrouperSyncMemberships) {
    this.gcGrouperSyncMemberships = gcGrouperSyncMemberships;
  }

  /**
   * gc grouper sync group to show for a particular group and provisioner 
   * @return
   */
  public GcGrouperSyncGroup getGcGrouperSyncGroup() {
    return gcGrouperSyncGroup;
  }

  /**
   * gc grouper sync group to show for a particular group and provisioner 
   * @param gcGrouperSyncGroup
   */
  public void setGcGrouperSyncGroup(GcGrouperSyncGroup gcGrouperSyncGroup) {
    this.gcGrouperSyncGroup = gcGrouperSyncGroup;
  }

  /**
   * logs for a particular group
   * @return
   */
  public List getGcGrouperSyncLogs() {
    return gcGrouperSyncLogs;
  }

  /**
   * logs for a particular group
   * @param gcGrouperSyncLogs
   */
  public void setGcGrouperSyncLogs(List gcGrouperSyncLogs) {
    this.gcGrouperSyncLogs = gcGrouperSyncLogs;
  }
  
  /**
   * @return gc grouper sync membership to show for a particular membership with provisioner 
   */
  public GcGrouperSyncMembership getGcGrouperSyncMembership() {
    return gcGrouperSyncMembership;
  }

  /**
   * gc grouper sync membership to show for a particular membership with provisioner 
   * @param gcGrouperSyncMembership
   */
  public void setGcGrouperSyncMembership(GcGrouperSyncMembership gcGrouperSyncMembership) {
    this.gcGrouperSyncMembership = gcGrouperSyncMembership;
  }
  
  /**
   * gc grouper sync member to show for a particular member with provisioner 
   * @return
   */
  public GcGrouperSyncMember getGcGrouperSyncMember() {
    return gcGrouperSyncMember;
  }

  /**
   * gc grouper sync member to show for a particular member with provisioner 
   * @param gcGrouperSyncMember
   */
  public void setGcGrouperSyncMember(GcGrouperSyncMember gcGrouperSyncMember) {
    this.gcGrouperSyncMember = gcGrouperSyncMember;
  }

  /**
   * * grouper proivisioning object metadata items
   * @return
   */
  public List getGrouperProvisioningObjectMetadataItems() {
    return grouperProvisioningObjectMetadataItems;
  }

  /**
   * grouper proivisioning object metadata items
   * @param grouperProvisioningObjectMetadataItems
   */
  public void setGrouperProvisioningObjectMetadataItems(List grouperProvisioningObjectMetadataItems) {
    this.grouperProvisioningObjectMetadataItems = grouperProvisioningObjectMetadataItems;
  }


  /**
   * keep track of the paging on the config history screen
   */
  private GuiPaging guiPaging = null;

  
  /**
   * keep track of the paging on the config history screen
   * @return the paging object, init if not there...
   */
  public GuiPaging getGuiPaging() {
    if (this.guiPaging == null) {
      this.guiPaging = new GuiPaging();
    }
    return this.guiPaging;
  }

  
  public void setGuiPaging(GuiPaging guiPaging) {
    this.guiPaging = guiPaging;
  }

  
  public List getGuiGrouperSyncObjects() {
    return guiGrouperSyncObjects;
  }

  
  public void setGuiGrouperSyncObjects(List guiGrouperSyncObjects) {
    this.guiGrouperSyncObjects = guiGrouperSyncObjects;
  }

  
  public GuiGrouperSyncObject getGuiGrouperSyncObject() {
    return guiGrouperSyncObject;
  }

  
  public void setGuiGrouperSyncObject(GuiGrouperSyncObject guiGrouperSyncObject) {
    this.guiGrouperSyncObject = guiGrouperSyncObject;
  }

  private GrouperProvisioner grouperProvisioner;
  
  public void setGrouperProvisioner(GrouperProvisioner provisioner) {
    grouperProvisioner = provisioner;
    
  }

  
  public GrouperProvisioner getGrouperProvisioner() {
    return grouperProvisioner;
  }
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy