Version Differences for Remoting Specific Scripts

(AHPSCRIPTS-72)
(Give All Roles Read Permission to All Agents)
Line 1277:
  print("Committing Changes");     print("Committing Changes");  
  uow.commitAndClose();</pre>    uow.commitAndClose();</pre> 
       
    + = Give All Roles Read Permission to All Environment Groups  
       
    + * This is an example remoting script for giving all roles read permission to all Env Groups. This is an example of using the API to do mass updates of security and might be handy after upgrading to AnthillPro 3.5.  
       
    + ==== AHPSCRIPTS-87 ====  
    + <pre>import com.urbancode.anthill3.main.client.AnthillClient;  
    + import com.urbancode.anthill3.persistence.UnitOfWork;  
    + import com.urbancode.anthill3.domain.authentication.*;  
    + import com.urbancode.anthill3.domain.security.*;  
    + import com.urbancode.anthill3.domain.environmentgroup.*;  
    + import java.util.*;  
       
    + String serverHost = "youServerUrl";  
    + int serverPort = 4567;  
    + String userName = "admin";  
    + String password = "thisIsSetAtTheCommandLine";  
       
    + //serverHost = bsh.args[0];  
    + //serverPort = Integer.parseInt(bsh.args[1]);  
       
    + if (bsh.args.length != 2) {  
    + print("");  
    + print("Invalid snyax. Please enter the command as: ");  
    + print("ah3client createUser.bsh [user name] [password]");  
    + return 0;  
    + }  
       
    + userName = bsh.args[0];  
    + password = bsh.args[1];  
       
    + // obtain connection to the Anthill server  
    + AnthillClient anthill = AnthillClient.connect(serverHost, serverPort,  
    + userName, password);  
       
    + // create a Unit of Work  
    + UnitOfWork uow = anthill.createUnitOfWork();  
       
    + envGroupArray = EnvironmentGroupFactory.getInstance().restoreAll();  
    + allRolesArray = RoleFactory.getInstance().restoreAllActive();  
       
    + for (EnvironmentGroup envGroup: envGroupArray) {  
    + boolean buildMasterHasWrite = false;  
    + resource = ResourceFactory.getInstance().restoreForPersistent(envGroup);  
    +  
    + // Determine roles don't have read access to envGroup  
    + HashSet roleWithoutReadPermSet = new HashSet();  
    + roleWithoutReadPermSet.addAll(Arrays.asList(allRolesArray));  
    + Permission[] permissions = PermissionFactory.getInstance().restoreAllForResource(resource);  
    + for (Permission permission : permissions) {  
    + Role role = permission.getRole();  
    + action = permission.getAction();  
    + if (!role.isUserRole() && role.isActive() && action.equals("read")) {  
    + roleWithoutReadPermSet.remove(role);  
    + }  
    + else if (role.isUserRole() || !role.isActive()) {  
    + roleWithoutReadPermSet.remove(role);  
    + }  
    + else if (role.getName().equals("Build Master") && action.equals("write")) {  
    + buildMasterHasWrite = true;  
    + }  
    + }  
    +  
    + // Create the missing Read Permissions  
    + Iterator roleItr = roleWithoutReadPermSet.iterator();  
    + while (roleItr.hasNext()) {  
    + Role role = roleItr.next();  
    + p = new Permission(true, resource, "read", role);  
    + p.store();  
    + }  
    +  
    + // Give Build Master Write Permission  
    + if (!buildMasterHasWrite) {  
    + Role bmRole = RoleFactory.getInstance().restoreForName("Build Master");  
    + p = new Permission(true, resource, "write", bmRole);  
    + p.store();  
    + }  
    + }  
       
       
    + print("Committing Changes");  
    + uow.commitAndClose();</pre>