Search in sources :

Example 1 with UpdateUser

use of org.sonar.server.user.UpdateUser in project sonarqube by SonarSource.

the class UserRegistrarImpl method registerExistingUser.

private UserDto registerExistingUser(DbSession dbSession, UserDto userDto, UserRegistration authenticatorParameters) {
    UpdateUser update = new UpdateUser().setEmail(authenticatorParameters.getUserIdentity().getEmail()).setName(authenticatorParameters.getUserIdentity().getName()).setExternalIdentity(new ExternalIdentity(authenticatorParameters.getProvider().getKey(), authenticatorParameters.getUserIdentity().getProviderLogin(), authenticatorParameters.getUserIdentity().getProviderId()));
    Optional<UserDto> otherUserToIndex = detectEmailUpdate(dbSession, authenticatorParameters, userDto.getUuid());
    userUpdater.updateAndCommit(dbSession, userDto, update, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex));
    return userDto;
}
Also used : UserDto(org.sonar.db.user.UserDto) ExternalIdentity(org.sonar.server.user.ExternalIdentity) UpdateUser(org.sonar.server.user.UpdateUser)

Example 2 with UpdateUser

use of org.sonar.server.user.UpdateUser in project sonarqube by SonarSource.

the class ChangePasswordAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(false)) {
        String login = request.mandatoryParam(PARAM_LOGIN);
        String password = request.mandatoryParam(PARAM_PASSWORD);
        UserDto user = getUser(dbSession, login);
        if (login.equals(userSession.getLogin())) {
            String previousPassword = request.mandatoryParam(PARAM_PREVIOUS_PASSWORD);
            checkPreviousPassword(dbSession, user, previousPassword);
            checkArgument(!previousPassword.equals(password), "Password must be different from old password");
        } else {
            userSession.checkIsSystemAdministrator();
        }
        UpdateUser updateUser = new UpdateUser().setPassword(password);
        userUpdater.updateAndCommit(dbSession, user, updateUser, u -> {
        });
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) UpdateUser(org.sonar.server.user.UpdateUser)

Example 3 with UpdateUser

use of org.sonar.server.user.UpdateUser in project sonarqube by SonarSource.

the class UpdateIdentityProviderAction method doHandle.

private void doHandle(UpdateIdentityProviderRequest request) {
    checkEnabledIdentityProviders(request.newExternalProvider);
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto user = getUser(dbSession, request.login);
        ExternalIdentity externalIdentity = getExternalIdentity(request, user);
        userUpdater.updateAndCommit(dbSession, user, new UpdateUser().setExternalIdentity(externalIdentity), u -> {
        });
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) ExternalIdentity(org.sonar.server.user.ExternalIdentity) UpdateUser(org.sonar.server.user.UpdateUser)

Example 4 with UpdateUser

use of org.sonar.server.user.UpdateUser in project sonarqube by SonarSource.

the class UpdateLoginAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    String login = request.mandatoryParam(PARAM_LOGIN);
    String newLogin = request.mandatoryParam(PARAM_NEW_LOGIN);
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto user = getUser(dbSession, login);
        userUpdater.updateAndCommit(dbSession, user, new UpdateUser().setLogin(newLogin), u -> {
        });
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) UpdateUser(org.sonar.server.user.UpdateUser)

Example 5 with UpdateUser

use of org.sonar.server.user.UpdateUser in project sonarqube by SonarSource.

the class UpdateAction method doHandle.

private void doHandle(DbSession dbSession, UpdateRequest request) {
    String login = request.getLogin();
    UserDto user = getUser(dbSession, login);
    UpdateUser updateUser = new UpdateUser();
    if (request.getName() != null) {
        Preconditions.checkArgument(user.isLocal(), "Name cannot be updated for a non-local user");
        updateUser.setName(request.getName());
    }
    if (request.getEmail() != null) {
        Preconditions.checkArgument(user.isLocal(), "Email cannot be updated for a non-local user");
        updateUser.setEmail(emptyToNull(request.getEmail()));
    }
    if (!request.getScmAccounts().isEmpty()) {
        updateUser.setScmAccounts(request.getScmAccounts());
    }
    userUpdater.updateAndCommit(dbSession, user, updateUser, u -> {
    });
}
Also used : UserDto(org.sonar.db.user.UserDto) UpdateUser(org.sonar.server.user.UpdateUser)

Aggregations

UserDto (org.sonar.db.user.UserDto)5 UpdateUser (org.sonar.server.user.UpdateUser)5 DbSession (org.sonar.db.DbSession)3 ExternalIdentity (org.sonar.server.user.ExternalIdentity)2