Uploaded image for project: 'Grouper'
  1. Grouper
  2. GRP-3510

gsh template transaction is not working correctly

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.5.53
    • None
    • None

    Description

       //
      ////uncomment to compile in eclipse (and last line)
      //// these are standard imports, can be commented out in script but needed in eclipse
      //import edu.internet2.middleware.grouper.*;
      //import edu.internet2.middleware.grouper.CompositeSave;
      //import edu.internet2.middleware.grouper.app.gsh.*;
      //import edu.internet2.middleware.grouper.privs.*;
      //import edu.internet2.middleware.grouper.misc.*;
      //import edu.internet2.middleware.grouper.app.loader.ldap.*;
      //import edu.internet2.middleware.grouper.attr.*;
      //import edu.internet2.middleware.grouper.attr.assign.*;
      //import edu.internet2.middleware.grouper.attr.finder.*;
      //import edu.internet2.middleware.grouper.attr.value.*;
      //import edu.internet2.middleware.grouper.audit.*;
      //import edu.internet2.middleware.grouper.client.*;
      //import edu.internet2.middleware.grouper.entity.*;
      //import edu.internet2.middleware.grouper.externalSubjects.*;
      //import edu.internet2.middleware.grouper.group.*;
      //import edu.internet2.middleware.grouper.ldap.*;
      //import edu.internet2.middleware.grouper.app.loader.*;
      //import edu.internet2.middleware.grouper.xml.*;
      //import edu.internet2.middleware.grouper.registry.*;
      //import edu.internet2.middleware.grouper.app.usdu.*;
      //import edu.internet2.middleware.grouper.rules.*;
      //import edu.internet2.middleware.grouper.hibernate.*;
      //import edu.internet2.middleware.grouper.permissions.*;
      //import edu.internet2.middleware.grouper.util.*;
      //import edu.internet2.middleware.grouper.xml.export.*;
      //import edu.internet2.middleware.subject.*;
      //import edu.internet2.middleware.subject.provider.*;
      //import edu.internet2.middleware.grouper.userData.*;
      //import edu.internet2.middleware.grouper.messaging.*;
      //import edu.internet2.middleware.grouper.filter.*;
      //import edu.internet2.middleware.grouper.authentication.*;
      //import edu.internet2.middleware.grouper.j2ee.*;
      //
      //import java.util.*;
      //import java.util.regex.*;
      //
      //import edu.internet2.middleware.grouper.cfg.*;
      //import edu.internet2.middleware.grouper.app.attestation.*;
      //import edu.internet2.middleware.grouper.app.grouperTypes.*;
      //import edu.internet2.middleware.grouper.app.gsh.template.*;
      //import edu.internet2.middleware.grouperClient.collections.*;
      //import edu.internet2.middleware.grouperClient.jdbc.*;
      //import org.apache.commons.lang.*;
      //
      //import edu.internet2.middleware.grouper.app.reports.*;import edu.internet2.middleware.grouper.Stem.Scope;
      //
      //public class Test15 {
      //
      //  public static void main(String[] args) {
      //    
      //    GrouperStartup.startup();
      //    
      //    String gsh_input_appName = "wiki"; 
      //    String gsh_input_subjectIds = "jsmith, banderson";
      //    
      //    GrouperSession gsh_builtin_grouperSession = GrouperSession.startRootSession();
      //    Subject gsh_builtin_subject = SubjectFinder.findByIdentifierAndSource("jsmith", "ldap", true);
      //    GrouperGroovyRuntime grouperGroovyRuntime = new GrouperGroovyRuntime();
      //    GshTemplateOutput gsh_builtin_gshTemplateOutput = new GshTemplateOutput();    // 1. app should not already exist
          String appStemName = "app:" + gsh_input_appName;
          Stem appFolder = StemFinder.findByName(gsh_builtin_grouperSession, appStemName, false);
          if (appFolder != null) {
            gsh_builtin_gshTemplateOutput.addValidationLine("gsh_input_appName",
                "Error: App already exists '" + gsh_input_appName + "'!");
          }
          
          // 2. resolve subjects, they need to resolve
          String[] subjectIdArray = GrouperUtil.nonNull(GrouperUtil.splitTrim(gsh_input_subjectIds, ","), String.class);
          Subject[] subjects = new Subject[GrouperUtil.length(subjectIdArray)];    for (int i=0;i<GrouperUtil.length(subjectIdArray);i++) {
            Subject subject = SubjectFinder.findByIdOrIdentifierAndSource(subjectIdArray[i], "ldap", false);
            if (subject == null) {
              gsh_builtin_gshTemplateOutput.addValidationLine("gsh_input_subjectIds",
                "Error: SubjectId cannot be found '" + subjectIdArray[i] + "'!");
            }
            subjects[i] = subject;
            
          }    // 3. Do not proceed is there is an error
          if (GrouperUtil.length(gsh_builtin_gshTemplateOutput.getValidationLines()) > 0) {
            gsh_builtin_gshTemplateOutput.assignIsError(true);
            GrouperUtil.gshReturn();
          }    // 4. Create stem
          appFolder = new StemSave().assignName(appStemName).save();
          gsh_builtin_gshTemplateOutput.addOutputLine("App folder created: " + appStemName);    // 5. Create admin group
          Group adminGroup = new GroupSave().assignName(appStemName + ":" + gsh_input_appName + "Admins").save();
          gsh_builtin_gshTemplateOutput.addOutputLine("Admin group created: " + adminGroup.getName());    // 6. Add users
          for (Subject subject : GrouperUtil.nonNull(subjects, Subject.class)) {
            adminGroup.addMember(subject, false);
            gsh_builtin_gshTemplateOutput.addOutputLine("Added admin: " + subject.getDescription());
          }    // 7. add inherited privileges
          PrivilegeGroupInheritanceSave privilegeGroupInheritanceSave = new PrivilegeGroupInheritanceSave().assignStem(appFolder).assignStemScope(Scope.SUB);
          privilegeGroupInheritanceSave.assignSubject(adminGroup.toSubject()).addPrivilege(AccessPrivilege.ADMIN).save();
          
          // 8. add attestation
          AttestationGroupSave attestationGroupSave = new AttestationGroupSave().assignGroup(adminGroup);
          attestationGroupSave.assignAttestationType(AttestationType.group).assignDaysUntilRecertify(30).assignMarkAsAttested(true).assignSendEmail(true).save();    // 9. success message
          gsh_builtin_gshTemplateOutput.addOutputLine("Finished running institution app template");//  }
      //
      //}

      From training

      Attachments

        Activity

          People

            chris.hyzer@at.internet2.edu Chris Hyzer (upenn.edu)
            chris.hyzer@at.internet2.edu Chris Hyzer (upenn.edu)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Smart Checklist