@Override
  public boolean updateUserModel(String username, UserModel model) {
    if (model.isLocalAccount() || supportsCredentialChanges()) {
      if (!model.isLocalAccount() && !supportsTeamMembershipChanges()) {
        //  teams are externally controlled - copy from original model
        UserModel existingModel = getUserModel(username);

        model = DeepCopier.copy(model);
        model.teams.clear();
        model.teams.addAll(existingModel.teams);
      }
      return serviceImpl.updateUserModel(username, model);
    }
    if (model.username.equals(username)) {
      // passwords are not persisted by the backing user service
      model.password = null;
      if (!model.isLocalAccount() && !supportsTeamMembershipChanges()) {
        //  teams are externally controlled- copy from original model
        UserModel existingModel = getUserModel(username);

        model = DeepCopier.copy(model);
        model.teams.clear();
        model.teams.addAll(existingModel.teams);
      }
      return serviceImpl.updateUserModel(username, model);
    }
    logger.error("Users can not be renamed!");
    return false;
  }
Beispiel #2
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> list = new ArrayList<TeamModel>(teams.values());
   list = DeepCopier.copy(list);
   Collections.sort(list);
   return list;
 }
Beispiel #3
0
 /**
  * Retrieve the user object for the specified username.
  *
  * @param username
  * @return a user object or null
  */
 @Override
 public UserModel getUserModel(String username) {
   Properties allUsers = read();
   String userInfo = allUsers.getProperty(username.toLowerCase());
   if (userInfo == null) {
     return null;
   }
   UserModel model = new UserModel(username.toLowerCase());
   String[] userValues = userInfo.split(",");
   model.password = userValues[0];
   for (int i = 1; i < userValues.length; i++) {
     String role = userValues[i];
     switch (role.charAt(0)) {
       case '#':
         // Permissions
         if (role.equalsIgnoreCase(Constants.ADMIN_ROLE)) {
           model.canAdmin = true;
         } else if (role.equalsIgnoreCase(Constants.NOT_FEDERATED_ROLE)) {
           model.excludeFromFederation = true;
         }
         break;
       default:
         model.addRepository(role);
     }
   }
   // set the teams for the user
   for (TeamModel team : teams.values()) {
     if (team.hasUser(username)) {
       model.teams.add(DeepCopier.copy(team));
     }
   }
   return model;
 }
Beispiel #4
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) {
   read();
   TeamModel team = teams.get(teamname.toLowerCase());
   if (team != null) {
     // clone the model, otherwise all changes to this object are
     // live and unpersisted
     team = DeepCopier.copy(team);
   }
   return team;
 }
  @Override
  public boolean updateTeamModel(String teamname, TeamModel model) {
    if (!supportsTeamMembershipChanges()) {
      // teams are externally controlled - copy from original model
      TeamModel existingModel = getTeamModel(teamname);

      model = DeepCopier.copy(model);
      model.users.clear();
      model.users.addAll(existingModel.users);
    }
    return serviceImpl.updateTeamModel(teamname, model);
  }