Ejemplo n.º 1
0
  protected IUserService createUserService(File realmFile) {
    IUserService service = null;
    if (realmFile.getName().toLowerCase().endsWith(".conf")) {
      // config-based realm file
      service = new ConfigUserService(realmFile);
    }

    assert service != null;

    if (!realmFile.exists()) {
      // Create the Administrator account for a new realm file
      try {
        realmFile.createNewFile();
      } catch (IOException x) {
        logger.error(MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);
      }
      UserModel admin = new UserModel("admin");
      admin.password = "******";
      admin.canAdmin = true;
      admin.excludeFromFederation = true;
      service.updateUserModel(admin);
    }

    return service;
  }
Ejemplo n.º 2
0
 /**
  * Delete the team object with the specified teamname
  *
  * @param teamname
  * @return true if successful
  * @since 0.8.0
  */
 @Override
 public boolean deleteTeam(String teamname) {
   TeamModel team = userService.getTeamModel(teamname);
   if (userService.deleteTeam(teamname)) {
     callDeleteTeamListeners(team);
     return true;
   }
   return false;
 }
Ejemplo n.º 3
0
 /**
  * Updates/writes and replaces a complete team object keyed by teamname. This method allows for
  * renaming a team.
  *
  * @param teamname the old teamname
  * @param model the team object to use for teamname
  * @return true if update is successful
  * @since 0.8.0
  */
 @Override
 public boolean updateTeamModel(String teamname, TeamModel model) {
   final boolean isCreate = null == userService.getTeamModel(teamname);
   if (userService.updateTeamModel(teamname, model)) {
     if (isCreate) {
       callCreateTeamListeners(model);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 4
0
 /**
  * Adds/updates a user object keyed by username. This method allows for renaming a user.
  *
  * @param username the old username
  * @param model the user object to use for username
  * @return true if update is successful
  */
 @Override
 public boolean updateUserModel(String username, UserModel model) {
   final boolean isCreate = null == userService.getUserModel(username);
   if (userService.updateUserModel(username, model)) {
     if (isCreate) {
       callCreateUserListeners(model);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 5
0
 /**
  * Deletes the team object from the user service.
  *
  * @param model
  * @return true if successful
  * @since 0.8.0
  */
 @Override
 public boolean deleteTeamModel(TeamModel model) {
   if (userService.deleteTeamModel(model)) {
     callDeleteTeamListeners(model);
     return true;
   }
   return false;
 }
Ejemplo n.º 6
0
 /**
  * Retrieve the user object for the specified username.
  *
  * @param username
  * @return a user object or null
  */
 @Override
 public UserModel getUserModel(String username) {
   if (StringUtils.isEmpty(username)) {
     return null;
   }
   String usernameDecoded = StringUtils.decodeUsername(username);
   UserModel user = userService.getUserModel(usernameDecoded);
   return user;
 }
Ejemplo n.º 7
0
 /**
  * Delete the user object with the specified username
  *
  * @param username
  * @return true if successful
  */
 @Override
 public boolean deleteUser(String username) {
   if (StringUtils.isEmpty(username)) {
     return false;
   }
   String usernameDecoded = StringUtils.decodeUsername(username);
   UserModel user = getUserModel(usernameDecoded);
   if (userService.deleteUser(usernameDecoded)) {
     callDeleteUserListeners(user);
     return true;
   }
   return false;
 }
Ejemplo n.º 8
0
 /**
  * Updates/writes all specified team objects.
  *
  * @param models a list of team models
  * @return true if update is successful
  * @since 1.2.0
  */
 @Override
 public boolean updateTeamModels(Collection<TeamModel> models) {
   return userService.updateTeamModels(models);
 }
Ejemplo n.º 9
0
 /**
  * Retrieve the team object for the specified team name.
  *
  * @param teamname
  * @return a team object or null
  * @since 0.8.0
  */
 @Override
 public TeamModel getTeamModel(String teamname) {
   TeamModel team = userService.getTeamModel(teamname);
   return team;
 }
Ejemplo n.º 10
0
 /**
  * Returns the list of all teams who are allowed to bypass the access restriction placed on the
  * specified repository.
  *
  * @param role the repository name
  * @return list of all teams that can bypass the access restriction
  * @since 0.8.0
  */
 @Override
 public List<String> getTeamNamesForRepositoryRole(String role) {
   List<String> teams = userService.getTeamNamesForRepositoryRole(role);
   return teams;
 }
Ejemplo n.º 11
0
 /**
  * Removes a repository role from all users.
  *
  * @param role
  * @return true if successful
  */
 @Override
 public boolean deleteRepositoryRole(String role) {
   return userService.deleteRepositoryRole(role);
 }
Ejemplo n.º 12
0
 /**
  * Returns the list of all users who are allowed to bypass the access restriction placed on the
  * specified repository.
  *
  * @param role the repository name
  * @return list of all usernames that can bypass the access restriction
  * @since 0.8.0
  */
 @Override
 public List<String> getUsernamesForRepositoryRole(String role) {
   return userService.getUsernamesForRepositoryRole(role);
 }
Ejemplo n.º 13
0
 /**
  * Returns the list of all users available to the login service.
  *
  * @return list of all usernames
  */
 @Override
 public List<String> getAllUsernames() {
   List<String> names = new ArrayList<String>(userService.getAllUsernames());
   return names;
 }
Ejemplo n.º 14
0
 /**
  * Retrieve the user object for the specified cookie.
  *
  * @param cookie
  * @return a user object or null
  */
 @Override
 public UserModel getUserModel(char[] cookie) {
   UserModel user = userService.getUserModel(cookie);
   return user;
 }
Ejemplo n.º 15
0
 /**
  * Returns the cookie value for the specified user.
  *
  * @param model
  * @return cookie value
  */
 @Override
 public String getCookie(UserModel model) {
   return userService.getCookie(model);
 }
Ejemplo n.º 16
0
 /**
  * Returns the list of all users available to the login service.
  *
  * @return list of all users
  * @since 0.8.0
  */
 @Override
 public List<UserModel> getAllUsers() {
   List<UserModel> users = userService.getAllUsers();
   return users;
 }
Ejemplo n.º 17
0
 /**
  * Returns the list of all teams available to the login service.
  *
  * @return list of all teams
  * @since 0.8.0
  */
 @Override
 public List<String> getAllTeamNames() {
   List<String> teams = userService.getAllTeamNames();
   return teams;
 }
Ejemplo n.º 18
0
 /**
  * Renames a repository role.
  *
  * @param oldRole
  * @param newRole
  * @return true if successful
  */
 @Override
 public boolean renameRepositoryRole(String oldRole, String newRole) {
   return userService.renameRepositoryRole(oldRole, newRole);
 }
Ejemplo n.º 19
0
 /**
  * Returns the list of all teams available to the login service.
  *
  * @return list of all teams
  * @since 0.8.0
  */
 @Override
 public List<TeamModel> getAllTeams() {
   List<TeamModel> teams = userService.getAllTeams();
   return teams;
 }
Ejemplo n.º 20
0
 /**
  * Set the user service. The user service authenticates *local* users and is responsible for
  * persisting and retrieving all users and all teams.
  *
  * @param userService
  */
 public void setUserService(IUserService userService) {
   this.userService = userService;
   this.userService.setup(runtimeManager);
   logger.info(userService.toString());
 }
Ejemplo n.º 21
0
  private void load(File folder) {
    this.folder = folder;
    this.userService = loadUsers(folder);
    System.out.println(Constants.baseFolder$ + " set to " + folder);
    if (userService == null) {
      JOptionPane.showMessageDialog(
          this,
          MessageFormat.format("Sorry, {0} doesn't look like a Gitblit GO installation.", folder));
    } else {
      // build empty certificate model for all users
      Map<String, UserCertificateModel> map = new HashMap<String, UserCertificateModel>();
      for (String user : userService.getAllUsernames()) {
        UserModel model = userService.getUserModel(user);
        UserCertificateModel ucm = new UserCertificateModel(model);
        map.put(user, ucm);
      }
      File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
      FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
      if (certificatesConfigFile.exists()) {
        try {
          config.load();
          // replace user certificate model with actual data
          List<UserCertificateModel> list = UserCertificateConfig.KEY.parse(config).list;
          for (UserCertificateModel ucm : list) {
            ucm.user = userService.getUserModel(ucm.user.username);
            map.put(ucm.user.username, ucm);
          }
        } catch (IOException e) {
          e.printStackTrace();
        } catch (ConfigInvalidException e) {
          e.printStackTrace();
        }
      }

      tableModel.list = new ArrayList<UserCertificateModel>(map.values());
      Collections.sort(tableModel.list);
      tableModel.fireTableDataChanged();
      Utils.packColumns(table, Utils.MARGIN);

      File caKeystore = new File(folder, X509Utils.CA_KEY_STORE);
      if (!caKeystore.exists()) {

        if (!X509Utils.unlimitedStrength) {
          // prompt to confirm user understands JCE Standard Strength encryption
          int res =
              JOptionPane.showConfirmDialog(
                  GitblitAuthority.this,
                  Translation.get("gb.jceWarning"),
                  Translation.get("gb.warning"),
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.WARNING_MESSAGE);
          if (res != JOptionPane.YES_OPTION) {
            if (Desktop.isDesktopSupported()) {
              if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                try {
                  Desktop.getDesktop()
                      .browse(
                          URI.create(
                              "http://www.oracle.com/technetwork/java/javase/downloads/index.html"));
                } catch (IOException e) {
                }
              }
            }
            System.exit(1);
          }
        }

        // show certificate defaults dialog
        certificateDefaultsButton.doClick();

        // create "localhost" ssl certificate
        prepareX509Infrastructure();
      }
    }
  }