Beispiel #1
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 #2
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;
  }