コード例 #1
0
  public String getPanelForDBDelete() {
    System.out.println("getPanelForDBDelete");
    setAndGetUserRole(userProjectsList(), projectIDValue);
    boolean actionAuthorised = false;
    try {
      actionAuthorised =
          IAMRoleManager.getInstance()
                  .getDatabaseAuthentication()
                  .isAllowedToAddEditOrRemoveDBData(currentRole)
              || SystemVars.treatAdminAsOwner(currentRole);
    } catch (MalformedURLException e) {
      e.printStackTrace();
      actionAuthorised = false;
    } catch (IOException e) {
      e.printStackTrace();
      actionAuthorised = false;
    }

    String rerenderPanelWhenDeletingDatabase;
    if (actionAuthorised) {
      System.out.println("Authorised");
      rerenderPanelWhenDeletingDatabase = "deleteDataspacePanel";
      notAuthMsg = "";
    } else {
      System.out.println("Not authorised!");
      rerenderPanelWhenDeletingDatabase = "notAuthorisedPanel";
      notAuthMsg = "You are not authorised to do this.";
    }
    return rerenderPanelWhenDeletingDatabase;
  }
コード例 #2
0
  public boolean checkAuthorisedToUploadDb() {
    System.out.println("checkAuthorisedToUploadDb:" + projectIDValue);
    setAndGetUserRole(userProjectsList(), projectIDValue);

    if (currentRole == null) {
      return false;
    }
    System.out.println(
        String.format(
            "Check if the user is authorised to create a database from schema when they have the role <%s>",
            currentRole));
    boolean actionAuthorised = false;
    try {
      actionAuthorised =
          IAMRoleManager.getInstance()
                  .getDatabaseAuthentication()
                  .isAllowedToAddEditOrRemoveDBData(currentRole)
              || SystemVars.treatAdminAsOwner(currentRole);
      System.out.println("Call returned " + actionAuthorised);
    } catch (MalformedURLException e) {
      System.out.println("Malformed exception");
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("IO Exception");
      e.printStackTrace();
    }
    return actionAuthorised;
  }
コード例 #3
0
 private boolean isAuthorisedToAlterUserRole() {
   boolean actionAuthorised = false;
   try {
     actionAuthorised =
         IAMRoleManager.getInstance()
                 .getProjectAuthentication()
                 .isAllowedToAlterOtherUsersRole(currentRole)
             || SystemVars.treatAdminAsOwner(currentRole);
   } catch (MalformedURLException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return actionAuthorised;
 }
コード例 #4
0
  public void modifyProjectMember() {
    System.out.println("userIDValue: " + userIDValue);

    this.userProjectHome.setId(new UserProjectId(projectIDValue, userIDValue));
    currentUserProject = this.userProjectHome.getInstance();

    List<UserProject> userProjectList =
        userProjectHome.findByProjectID(currentUserProject.getId().getProjectId());
    System.out.println("Number of users in project:" + userProjectList.size());

    boolean actionAuthorised = false;
    boolean attemptToModifyOwner = false;

    if (userProjectList.size() > 0) {
      setAndGetUserRole(userProjectsList(), projectIDValue);

      System.out.println(
          String.format("Check if %s is authorised to modify a project member", currentRole));
      actionAuthorised = isAuthorisedToAlterUserRole();

      if (actionAuthorised) {
        System.out.println("Yes, the user is authorised.");

        /** Look through each user in the project */
        System.out.println(
            String.format("There are %d users in this project", userProjectList.size()));
        for (int i = 0; i < userProjectList.size(); i++) {
          UserProject workingUserProject = userProjectList.get(i);
          System.out.println(
              String.format(
                  "Check who we are dealing with. Does user id %d match the current id %d?",
                  workingUserProject.getId().getUserId(), currentUserProject.getId().getUserId()));
          System.out.println(
              String.format("Project Name is %s", workingUserProject.getProject().getName()));
          if (workingUserProject.getId().getUserId() != currentUserProject.getId().getUserId()) {
            System.out.println("No, it doesn't!");
          } else {
            System.out.println(
                String.format(
                    "Yes, this is it. So we want to alter the role of user %d who has role of <%s>",
                    workingUserProject.getId().getUserId(), workingUserProject.getUserRole()));
            /*
             * We know the user doing the work is authorised to do it. Now
             * check if the user to be changed is owner.
             */
            try {
              attemptToModifyOwner =
                  (IAMRoleManager.getInstance()
                          .getOwnerRole()
                          .equals(workingUserProject.getUserRole())
                      || SystemVars.treatAdminAsOwner(workingUserProject.getUserRole()));
            } catch (MalformedURLException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
            if (attemptToModifyOwner) {
              System.out.println("Attempt to modify owner");
              editProjectMemberErrorMessage =
                  "You cannot modify the project owner! Change in role not allowed";
              editProjectMemberInclude = "/popup/editProjectMemberError.xhtml";
            } else {
              System.out.println(
                  String.format(
                      "Role %s is modifyable - so let's modify!",
                      workingUserProject.getUserRole()));
            }
          }

          break;
        }
        if (attemptToModifyOwner) {
          editProjectMemberErrorMessage =
              "You cannot modify the project owner! Change in role not allowed";
          editProjectMemberInclude = "/popup/editProjectMemberError.xhtml";
        } else {
          editProjectMemberInclude = "/popup/editProjectMemberForm.xhtml";
        }
      } else {
        setupErrorFields();
      }
    } else {
      System.out.println("Error - no users in the project. This should never happen.");
    }
    Contexts.getSessionContext().set("currentUserProject", currentUserProject);
  }