Example #1
0
  protected IUserService createUserService(File realmFile) {
    IUserService service = null;
    if (realmFile.getName().toLowerCase().endsWith(".conf")) {
      // v0.8.0+ 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;
  }
Example #2
0
  @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;
  }
  @Test
  public void linkWithRolesTest() throws ServiceException, DAOException {
    Long userId = 1L;
    List<Role> roles = new ArrayList<Role>();

    userService.linkWithRoles(userId, roles);
    verify(userDAOMock, times(1)).linkWithItems(userId, roles);
  }
Example #4
0
 @Override
 public List<UserModel> getAllUsers() {
   List<UserModel> users = serviceImpl.getAllUsers();
   for (UserModel user : users) {
     setAccountType(user);
   }
   return users;
 }
  @Test
  public void getAllUsersTest() throws ServiceException, DAOException {
    List<UserWithRestLinks> expectedUsers = usersWithLinkMock;
    List<UserWithRestLinks> resultUsers = null;
    when(userDAOMock.getAllUsers()).thenReturn(expectedUsers);

    resultUsers = userService.getAllUsers();
    verify(userDAOMock, times(1)).getAllUsers();
    assertEquals(expectedUsers, resultUsers);
  }
  @Test
  public void readUserTest() throws ServiceException, DAOException {
    User expectedUser = userMock;
    User resultUser = null;
    when(userDAOMock.read(anyLong())).thenReturn(expectedUser);

    resultUser = userService.readUser(anyLong());
    verify(userDAOMock, times(1)).read(anyLong());
    assertEquals(expectedUser, resultUser);
  }
  /*
   * This method will list all existing users.
   */
  @RequestMapping(
      value = {"/users"},
      method = RequestMethod.GET)
  public String getUsers(ModelMap model) {

    List<GameUser> users = userService.findAll();
    logger.info("getUsers results " + users.iterator().next().getId());
    model.addAttribute("users", users);
    return "test/users";
  }
  @Test
  public void createUserTest() throws ServiceException, DAOException {
    Long expectedRoleId = anyLong();
    Long resultRoleId = null;
    when(userDAOMock.create(userMock)).thenReturn(anyLong());

    resultRoleId = userService.createUser(userMock);
    verify(userDAOMock, times(1)).create(userMock);
    assertEquals(expectedRoleId, resultRoleId);
  }
Example #9
0
  @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);
  }
  @Override
  @Transactional(readOnly = true)
  public void refreshAllData(int start, int end, int entityId, ITransactionCallback callBack) {

    User user = SharedData.getSharedInstace().getCurrentUser();
    user = userService.findById(user.getId(), false);

    List<Transaction> transactions =
        new ArrayList<>(); // this.fetchAllByRole(start, end, entityId);
    Integer totalRows = service.getTotalTransactionCount(entityId);
    List<Payer> payerList = payerService.getAll();
    List<Practice> practiceList = new ArrayList<>(); // practiseService.fetchAllByRole();
    List<Provider> providerList = new ArrayList<>(); // providerService.fetchAllByRole();

    Map<String, Object> otherInfo = new HashMap<>();
    otherInfo.put("count", totalRows);
    callBack.refreshAllData(user, transactions, payerList, practiceList, providerList, otherInfo);
  }
Example #11
0
 @Override
 public List<String> getUsernamesForRepositoryRole(String role) {
   return serviceImpl.getUsernamesForRepositoryRole(role);
 }
Example #12
0
 @Override
 public boolean deleteTeam(String teamname) {
   return serviceImpl.deleteTeam(teamname);
 }
Example #13
0
 @Override
 public boolean deleteTeamModel(TeamModel model) {
   return serviceImpl.deleteTeamModel(model);
 }
Example #14
0
 @Override
 public boolean updateTeamModels(Collection<TeamModel> models) {
   return serviceImpl.updateTeamModels(models);
 }
Example #15
0
 @Override
 public boolean updateTeamModel(TeamModel model) {
   return serviceImpl.updateTeamModel(model);
 }
Example #16
0
 @Override
 public boolean updateUserModel(UserModel model) {
   return serviceImpl.updateUserModel(model);
 }
Example #17
0
 @Override
 public boolean supportsDisplayNameChanges() {
   return serviceImpl.supportsDisplayNameChanges();
 }
Example #18
0
 @Override
 public boolean deleteRepositoryRole(String role) {
   return serviceImpl.deleteRepositoryRole(role);
 }
Example #19
0
 @Override
 public boolean deleteUser(String username) {
   return serviceImpl.deleteUser(username);
 }
Example #20
0
 @Override
 public boolean deleteUserModel(UserModel model) {
   return serviceImpl.deleteUserModel(model);
 }
Example #21
0
 @Override
 public void logout(UserModel user) {
   serviceImpl.logout(user);
 }
Example #22
0
 @Override
 @Deprecated
 public boolean setUsernamesForRepositoryRole(String role, List<String> usernames) {
   return serviceImpl.setUsernamesForRepositoryRole(role, usernames);
 }
Example #23
0
 @Override
 public boolean renameRepositoryRole(String oldRole, String newRole) {
   return serviceImpl.renameRepositoryRole(oldRole, newRole);
 }
Example #24
0
 @Override
 public UserModel getUserModel(String username) {
   UserModel user = serviceImpl.getUserModel(username);
   setAccountType(user);
   return user;
 }
Example #25
0
 @Override
 public void setup(IStoredSettings settings) {
   File realmFile = GitBlit.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");
   serviceImpl = createUserService(realmFile);
   logger.info("GUS delegating to " + serviceImpl.toString());
 }
Example #26
0
 @Override
 public List<String> getAllTeamNames() {
   return serviceImpl.getAllTeamNames();
 }
Example #27
0
 @Override
 public boolean supportsCredentialChanges() {
   return serviceImpl.supportsCredentialChanges();
 }
Example #28
0
 @Override
 public List<TeamModel> getAllTeams() {
   return serviceImpl.getAllTeams();
 }
Example #29
0
  public ClientSession createClientSession(IClientInfo client, String clientType) {

    // Both OE and BB share the session file.  Don't stomp an existing file.
    if (client == null || !client.isConfigured()) {
      throw new IllegalStateException("Client not configured.");
    }

    clientType = clientType == null ? "" : clientType;

    ClientSession session = null;
    String tmpName = null;
    String targetName = null;
    try {
      File targetFile = getSessionFile(client.getLastActivationToken());
      targetName = targetFile.getAbsolutePath();
      if (targetFile.exists()) {
        session = new ClientSession();
        session.read(targetFile);
        if (session.getLastActivationId() != client.getLastActivationId()
            || session.getUserId() != client.getUserId()) {
          // Existing session file found but it's clearly not ours.
          // A hash collision is improbable.  If this occurs, its more likely to be a
          // bug.  We can't safely rewrite the session file because another client
          // might later call getClientSession() and read our email.
          // This is a support concern.
          LogMessageGen lmg = new LogMessageGen();
          lmg.setSubject("Found existing session, but the content is unexpected.");
          lmg.param(LoggingConsts.FILENAME, targetFile.getAbsolutePath());
          m_logCategory.error(lmg.toString());
          throw new ClientServiceException("");
        }
        session.setActivationToken(client.getLastActivationToken());
      } // targetFile already found.

      if (session == null) {
        UserAccount user = m_userService.getUserAccount(client.getCustomerId(), client.getUserId());
        session = client.createSession(user);

        // What if the BB and OE create a session at the same time?
        // This ensures a unique filename.
        // The client who does the last renameTo() below wins the race
        // and that becomes the common session file.

        tmpName = targetFile.getAbsolutePath() + "_tmp_" + clientType;
        File tmpFile = new File(tmpName);
        session.write(tmpFile);

        // If 'targetFile' already exists it'll get clobbered.
        // Makes the session targetFile generation atomic.
        boolean ok = FileUtils.clobberingRename(tmpFile, targetFile);
        if (!ok) {
          throw new IOException("Rename failed");
        }
      } // need to create session.
    } catch (Exception ex) {
      if (ex instanceof ClientServiceException) {
        // We already logged it.
        throw (ClientServiceException) ex;
      }
      LogMessageGen lmg = new LogMessageGen();
      lmg.setSubject("Unable to generate session file.");
      lmg.param(LoggingConsts.USER_ID, client.getUserId());
      lmg.param(LoggingConsts.TEMP_NAME, tmpName);
      lmg.param(LoggingConsts.FILENAME, targetName);

      m_logCategory.error(lmg.toString(), ex);
      throw new ClientServiceException("");
    }
    return session;
  }
Example #30
0
 @Override
 public TeamModel getTeamModel(String teamname) {
   return serviceImpl.getTeamModel(teamname);
 }