Exemplo n.º 1
0
  public Server(int port) {
    enc = null;
    dec = null;
    char[] password = null;
    char[] passwordcopy = null;
    try {
      password = PrivateKeyHandler.checkPassword(GenerateKeys.getPasswordInput());
      if (password == null) {
        System.err.println("Please enter admin password to start the server");
        System.exit(1);
      }
      passwordcopy = Arrays.copyOf(password, password.length);
      this.network = new ServerNetworkWrapper(port, password);
      dec = LoginManager.load(password);
      enc = LoginManager.save(passwordcopy);
    } finally {
      if (password != null) {
        for (int i = 0; i < password.length; i++) {
          password[i] = '\0';
          passwordcopy[i] = '\0';
        }
      }
    } // In-case LoginManager.load isn't reached

    challengeHanlder = new ChallengeHandler();
  }
Exemplo n.º 2
0
  private void addCourse() {

    JTextField pf = new JTextField();
    int okCxl =
        JOptionPane.showConfirmDialog(
            null, pf, "Enter Course Name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    String courseName = null;
    if (okCxl == JOptionPane.OK_OPTION) {
      courseName = new String(pf.getText());
    } else {
      return;
    }
    JComboBox<Person> profList = new JComboBox<Person>();
    profList.addItem(null);
    for (Person p : LoginManager.getPersons()) {
      profList.addItem(p);
    }
    okCxl =
        JOptionPane.showConfirmDialog(
            null,
            profList,
            "Select Professor",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    Person prof = null;
    if (okCxl == JOptionPane.OK_OPTION) {
      prof = (Person) profList.getSelectedItem();
    } else {
      return;
    }
    Course c = new Course(courseName, prof);
    char[] password = null;
    try {
      password =
          PrivateKeyHandler.checkPassword(
              GenerateKeys.getPasswordInput()); // This window shows garbage
      if (password == null) {
        System.err.println("Please enter admin password to apply changes");
        return;
      }
      LoginManager.putCourse(c.getCID(), c);
      enc = LoginManager.save(password);
    } finally {
      if (password != null) {
        for (int i = 0; i < password.length; i++) {
          password[i] = '\0';
        }
      }
    }
  }
Exemplo n.º 3
0
 private void apply() {
   String action = (String) StatusList.getSelectedItem();
   Person p = (Person) PersonList.getSelectedItem();
   Course c = (Course) CourseList.getSelectedItem();
   if (!checkValidAction(action, p, c)) {
     System.err.println("Invalid action... Ignoring...");
     return;
   }
   StatusList.setSelectedIndex(0);
   PersonList.setSelectedIndex(0);
   CourseList.setSelectedIndex(0);
   char[] password = null;
   try {
     password =
         PrivateKeyHandler.checkPassword(
             GenerateKeys.getPasswordInput()); // This window shows garbage
     if (password == null) {
       System.err.println("Please enter admin password to apply changes");
       return;
     }
     if (action == STUDENT) {
       LoginManager.setStudent(p.getPID(), c.getCID());
     } else if (action == TA) {
       LoginManager.setTA(p.getPID(), c.getCID());
     } else if (action == PROF) {
       LoginManager.setProf(p.getPID(), c.getCID());
     } else if (action == REMOVE) {
       LoginManager.remove(p.getPID(), c.getCID());
     } else if (action == REMOVEPERSON) {
       LoginManager.remove(p.getPID());
     } else if (action == REMOVECOURSE) {
       LoginManager.removeCourse(c.getCID());
     } else if (action == EDITCOURSE) {
       JTextField pf = new JTextField();
       int okCxl =
           JOptionPane.showConfirmDialog(
               null,
               pf,
               "Change Course name to",
               JOptionPane.OK_CANCEL_OPTION,
               JOptionPane.PLAIN_MESSAGE);
       String courseName = null;
       if (okCxl == JOptionPane.OK_OPTION) {
         courseName = new String(pf.getText());
       } else {
         return;
       }
       LoginManager.changeCoursename(c.getCID(), courseName);
     } else if (action == EDITUSERNAME) {
       JTextField pf = new JTextField();
       int okCxl =
           JOptionPane.showConfirmDialog(
               null,
               pf,
               "Change username to",
               JOptionPane.OK_CANCEL_OPTION,
               JOptionPane.PLAIN_MESSAGE);
       String username = null;
       if (okCxl == JOptionPane.OK_OPTION) {
         username = new String(pf.getText());
       } else {
         return;
       }
       LoginManager.changeUsername(p.getPID(), username);
     }
     enc = LoginManager.save(password);
   } finally {
     if (password != null) {
       for (int i = 0; i < password.length; i++) {
         password[i] = '\0';
       }
     }
   }
 }