예제 #1
0
  /**
   * Returns the role that has the specified name.
   *
   * @throws RoleNotFoundException when the role could not be found
   */
  public Role getRole(String roleName) throws IOException {
    Assert.hasLength(roleName);

    ILockedRepository repo = null;
    try {
      repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
      String json = BlobUtils.getHeadContent(repo.r(), roleName + ROLE_SUFFIX);
      if (json == null) {
        throw new RoleNotFoundException(roleName);
      }

      Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
      Map<String, Object> roleMap =
          gson.fromJson(json, new TypeToken<Map<String, Object>>() {}.getType());
      @SuppressWarnings("unchecked")
      Collection<String> permissions =
          (Collection<String>) roleMap.get("permissions"); // $NON-NLS-1$
      EnumSet<Permission> rolePermissions = EnumSet.noneOf(Permission.class);
      for (String permission : permissions) {
        rolePermissions.add(Permission.valueOf(permission));
      }
      Role role = new Role(roleName, rolePermissions);
      return role;
    } finally {
      Util.closeQuietly(repo);
    }
  }
예제 #2
0
  /**
   * Returns the user that has the specified login name.
   *
   * @throws UserNotFoundException when the user could not be found
   */
  public User getUser(String loginName) throws IOException {
    Assert.hasLength(loginName);

    ILockedRepository repo = null;
    try {
      repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
      String json = BlobUtils.getHeadContent(repo.r(), loginName + USER_SUFFIX);
      if (json == null) {
        throw new UserNotFoundException(loginName);
      }

      return getUser(loginName, json);
    } finally {
      Util.closeQuietly(repo);
    }
  }
예제 #3
0
 @Override
 public boolean include(final RevCommit commit, final Collection<DiffEntry> diffs) {
   int count = 0;
   for (DiffEntry diff : diffs)
     for (Edit edit :
         BlobUtils.diff(repository, diff.getOldId().toObjectId(), diff.getNewId().toObjectId()))
       switch (edit.getType()) {
         case DELETE:
           count += edit.getLengthA();
           break;
         case INSERT:
         case REPLACE:
           count += edit.getLengthB();
           break;
         default:
           break;
       }
   return include(commit, diffs, count) ? true : include(false);
 }
예제 #4
0
  private List<RoleGrantedAuthority> getUserAuthorities(String loginName, ILockedRepository repo) {
    String json = BlobUtils.getHeadContent(repo.r(), loginName + AUTHORITIES_SUFFIX);
    if (json == null) {
      throw new UserNotFoundException(loginName);
    }

    Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
    Map<String, Set<String>> authoritiesMap =
        gson.fromJson(json, new TypeToken<Map<String, Set<String>>>() {}.getType());
    List<RoleGrantedAuthority> authorities = Lists.newArrayList();
    for (Map.Entry<String, Set<String>> entry : authoritiesMap.entrySet()) {
      String targetStr = entry.getKey();
      Type type = Type.valueOf(StringUtils.substringBefore(targetStr, ":")); // $NON-NLS-1$
      String targetId = StringUtils.substringAfter(targetStr, ":"); // $NON-NLS-1$
      for (String roleName : entry.getValue()) {
        authorities.add(
            new RoleGrantedAuthority(new GrantedAuthorityTarget(targetId, type), roleName));
      }
    }

    Collections.sort(authorities, new RoleGrantedAuthorityComparator());

    return authorities;
  }
예제 #5
0
 protected String doGetContent(Git git, String objectId, String blobPath) {
   objectId = defaultObjectId(git, objectId);
   Repository r = git.getRepository();
   return BlobUtils.getContent(r, objectId, blobPath);
 }