Change current users username.
The username must be unique

@param usernameRequest new username
@return 200 if success
409 if username is not unique
512034
@POST
  @Path("me/username")
  @RolesAllowed({"ROLE_ADMIN", "ROLE_USER"})
  public Response changeUsername(@Context HttpServletRequest request, UsernameRequest usernameRequest) {
    Long userId = (Long) request.getAttribute(OAuth2Filter.NAME_USER_ID);
    return changeUsername(userId, usernameRequest);
  }
1333325
private void sendRequest(HttpUriRequest request, int expectedStatus)
      throws Exception {
    addAuthHeader(request);
    
    HttpClient client = httpClient();
    
    HttpResponse response = client.execute(request);
    if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
      EntityUtils.consume(response.getEntity());
      System.err.println("Authentication has been disabled for "+args.get(1)+".");
    } else if(response.getStatusLine().getStatusCode() == expectedStatus) {
      if(expectedStatus == HttpStatus.SC_OK) {
        String responseStr = EntityUtils.toString(response.getEntity());
        List<String> usernames = new Gson().fromJson(responseStr, new TypeToken<List<String>>(){}.getType());
        if(usernames == null || usernames.isEmpty()) {
          System.out.println("There have been no site specific users created.");
        } else {
          System.out.println(usernames.size() + " Users:");
          for(String user : usernames) {
            System.out.println(user);
          }
        }
      }
    } else {
      System.err.println(EntityUtils.toString(response.getEntity()));
      System.err.println("Unexpected status code returned. "+response.getStatusLine().getStatusCode());
    }
  }
970769
def validate_username(form, field):
        """"""
        try:
            validate_username(field.data)
        except ValueError as e:
            raise ValidationError(e)

        try:
            user_profile = UserProfile.get_by_username(field.data)
            if current_userprofile.is_anonymous or \
                    (current_userprofile.user_id != user_profile.user_id and
                     field.data != current_userprofile.username):
                # NOTE: Form validation error.
                raise ValidationError(_('Username already exists.'))
        except NoResultFound:
            return
473167
@POST
  @Path("me/email")
  @RolesAllowed({"ROLE_ADMIN", "ROLE_USER"})
  public Response changeEmail(@Context HttpServletRequest request, EmailRequest emailRequest) {
    Long userId = (Long) request.getAttribute(OAuth2Filter.NAME_USER_ID);
    return changeEmail(userId, emailRequest);
  }
162652
@Override
  public final String getUserName() {
    if (httpReq.getUserPrincipal() != null) {
      return httpReq.getUserPrincipal().getName();
    }
    return null;
  }
1094709
public String getSessionUserName(HttpServletRequest request, HttpServletResponse response)
    {
        HttpSession session = null;

        SessionAffinityContext sac = getSessionAffinityContext(request);

        if (!sac.isFirstSessionIdValid() && !sac.isAllSessionIdsSetViaSet()) { //PM89885
            @SuppressWarnings("rawtypes")
            List allSessionIds = _sam.getAllCookieValues(request);
            sac.setAllSessionIds(allSessionIds);
            _sam.setNextId(sac); // we got rid of the first one in setAllSessionIds, get the next one so that we have an id to work with
        }

        String id = _sam.getInUseSessionID(request, sac);

        if (id != null) {
            session = (HttpSession) _coreHttpSessionManager.getSession(request, response, sac, false); // don't create here
        }
        if( session != null ){
            SessionData sd = (SessionData) session;
            return sd.getUserName();            
        } else{
            return null;
        }
    }
342126
function addUser(username) {
		return userProject.findOne({'username': username}).exec()
		.then(function(doc) {
			if (!doc) {
				return userProject.create(userProjectJSON(username));
			}
			return Promise.resolve(doc);
		});
	}
762809
public static boolean changePassword(String userName, String newPassword) {
        LOGGER.entering(userName, newPassword.replaceAll(".", "*"));
        boolean changeSucceeded = false;
        File authFile = new File(AUTH_FILE_LOCATION);
        try {
            authFile.delete();
            authFile.createNewFile();
            createAuthFile(authFile, userName, newPassword);
            changeSucceeded = true;
        } catch (Exception e) {
            changeSucceeded = false;
        }
        LOGGER.exiting(changeSucceeded);
        return changeSucceeded;
    }
1075490
def is_username_available(self, username):
        """"""
        params = {'user': username}
        try:
            result = self.request_json(self.config['username_available'],
                                       params=params)
        except errors.BadUsername:
            return False
        return result
29132
public static void setUsername(final String username) {
        if (username == null) {
            throw new AuthenticationException("Username can not be null");
        }

        if (!username.equals(Twilio.username)) {
            Twilio.invalidate();
        }

        Twilio.username = username;
    }
159679
def user_update(self, username, data):
        
        url = 'rest/api/2/user?username={0}'.format(username)
        return self.put(url, data=data)
696121
public void setUserName(String userName) {
        SystemAssert.requireArgument(userName != null && !userName.isEmpty(), "Username cannot be null or empty.");
        this.userName = userName;
    }
189127
def username_from_request(request):
    
    if config.USERNAME_FORM_FIELD in request.POST:
        return request.POST[config.USERNAME_FORM_FIELD][:255]
    return None
569185
def change_username(self, username):
        
        username = username.lower()
        if self.username != username:
            if self.get_by_username(username):
                raise exceptions.AuthError("Username exists already")
            self.update(username=username)
460030
public void addUsername(String username) {
        SystemAssert.requireArgument(username != null && !username.isEmpty(), "Username cannot be null or empty.");
        this.usernames.add(username);
    }
323329
function updateUsername() {
      var $username = $el.findByName('username');
      if ((!usernameFocused) && (snippet.username === undefined)) {
        var username = apos.slugify($firstName.val() + $lastName.val());
        $.post(self._action + '/username-unique', { username: username }, function(data) {
          $username.val(data.username);
        });
      }
      $username.on('focus', function() {
        usernameFocused = true;
      });
    }
830881
@Action(
            semantics = SemanticsOf.IDEMPOTENT,
            command = CommandReification.ENABLED
    )
    public SomeCommandAnnotatedObject changeName(
            @ParameterLayout(named = "New name")
            final String newName) {
        setName(newName);
        return this;
    }