|
(→AHPSCRIPTS-15)
|
(→AHPSCRIPTS-95)
|
| Line 1475: | |||
| output = output.substring(0, output.indexOf("command exit code:")); | output = output.substring(0, output.indexOf("command exit code:")); | ||
| PropertyLookup.set("output", output.trim());</pre> | PropertyLookup.set("output", output.trim());</pre> | ||
| + | = Give Read, Write, and Security Permissions to Build Master and System Admin For Non-Ignored Agents = | ||
| + | *This can be used to fix broken permissions on the agents | ||
| + | ==== AHPSCRIPTS-96 ==== | ||
| + | <pre>import com.urbancode.anthill3.main.client.AnthillClient; | ||
| + | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
| + | import com.urbancode.anthill3.domain.agent.*; | ||
| + | import com.urbancode.anthill3.domain.authentication.*; | ||
| + | import com.urbancode.anthill3.domain.security.*; | ||
| + | import java.util.*; | ||
| + | try { | ||
| + | agentArray = AgentFactory.getInstance().restoreAllNotIgnored(); | ||
| + | Role bmRole = RoleFactory.getInstance().restoreForName("Build Master"); | ||
| + | Role saRole = RoleFactory.getInstance().restoreForName("System Admin"); | ||
| + | for (Agent agent: agentArray) { | ||
| + | boolean bmHasWrite = false; | ||
| + | boolean bmHasRead = false; | ||
| + | boolean bmHasSec = false; | ||
| + | boolean saHasWrite = false; | ||
| + | boolean saHasRead = false; | ||
| + | boolean saHasSec = false; | ||
| + | resource = ResourceFactory.getInstance().restoreForPersistent(agent); | ||
| + | |||
| + | // Determine roles don't have read access to an agent | ||
| + | Permission[] permissions = PermissionFactory.getInstance().restoreAllForResource(resource); | ||
| + | for (Permission permission : permissions) { | ||
| + | Role role = permission.getRole(); | ||
| + | action = permission.getAction(); | ||
| + | if (role.equals(bmRole) && action.equals("read")) { | ||
| + | bmHasRead = true; | ||
| + | } | ||
| + | else if (role.equals(bmRole) && action.equals("write")) { | ||
| + | bmHasWrite = true; | ||
| + | } | ||
| + | else if (role.equals(bmRole) && action.equals("security")) { | ||
| + | bmHasSec = true; | ||
| + | } | ||
| + | else if (role.equals(saRole) && action.equals("read")) { | ||
| + | saHasRead = true; | ||
| + | } | ||
| + | else if (role.equals(saRole) && action.equals("write")) { | ||
| + | saHasWrite = true; | ||
| + | } | ||
| + | else if (role.equals(saRole) && action.equals("security")) { | ||
| + | saHasSec = true; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | // Give Build Master Write Permission | ||
| + | if (!bmHasWrite) { | ||
| + | p = new Permission(true, resource, "write", bmRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | if (!bmHasRead) { | ||
| + | p = new Permission(true, resource, "read", bmRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | if (!bmHasSec) { | ||
| + | p = new Permission(true, resource, "security", bmRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | if (!saHasWrite) { | ||
| + | p = new Permission(true, resource, "write", saRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | if (!saHasRead) { | ||
| + | p = new Permission(true, resource, "read", saRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | if (!saHasSec) { | ||
| + | p = new Permission(true, resource, "security", saRole); | ||
| + | p.store(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | catch (Exception e) { | ||
| + | e.printStackTrace(commandOutput); | ||
| + | }</pre> | ||