@Override
  protected Long validateInput(String ownerId, Long avatarId, final HttpServletResponse response)
      throws IOException {
    UserPropertyManager userPropertyManager =
        ComponentAccessor.getComponent(UserPropertyManager.class);
    if (StringUtils.isBlank(ownerId) && avatarId == null) {
      // no owner id or avatarId
      response.sendError(HttpServletResponse.SC_NOT_FOUND, "No avatar requested");
      return null;
    } else if (StringUtils.isNotBlank(ownerId)) {
      final ApplicationUser user = getUserUtil().getUserByKey(ownerId);
      if (user == null) {
        // return the anonymous avatar if the user can't be found! Maybe the case for deleted
        // users/anonymous users
        return Long.parseLong(
            getApplicationProperties().getString(APKeys.JIRA_ANONYMOUS_USER_AVATAR_ID));
      }
      if (!getAvatarManager().hasPermissionToView(getAuthenticationContext().getUser(), user)) {
        // no permission to see any avatar for this user. Simply return the default!
        avatarId =
            Long.parseLong(
                getApplicationProperties().getString(APKeys.JIRA_DEFAULT_USER_AVATAR_ID));
      }

      if (avatarId == null) {
        final PropertySet userPropertySet = userPropertyManager.getPropertySet(user);
        if (userPropertySet.exists(AvatarManager.USER_AVATAR_ID_KEY)) {
          avatarId = userPropertySet.getLong(AvatarManager.USER_AVATAR_ID_KEY);
        } else {
          avatarId =
              Long.parseLong(
                  getApplicationProperties().getString(APKeys.JIRA_DEFAULT_USER_AVATAR_ID));
        }
      }
    }
    return avatarId;
  }
Example #2
0
  /** This method retrieves a user's meta properties */
  protected void retrieveUserMetaProperties() {
    userProperties = new HashMap<String, String>();

    User user = getUser();
    if (user != null) {
      PropertySet userPropertySet = userPropertyManager.getPropertySet(user);

      @SuppressWarnings("unchecked")
      Collection<String> keys = userPropertySet.getKeys(PropertySet.STRING);
      if (keys != null) {
        for (String key : keys) {
          if (key.startsWith(UserUtil.META_PROPERTY_PREFIX)) {
            userProperties.put(
                key.substring(UserUtil.META_PROPERTY_PREFIX.length()),
                userPropertySet.getString(key));
          }
        }
      }
    }
  }