Search in sources :

Example 1 with NewUser

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

the class UserRegistrarImpl method registerNewUser.

private UserDto registerNewUser(DbSession dbSession, @Nullable UserDto disabledUser, UserRegistration authenticatorParameters) {
    Optional<UserDto> otherUserToIndex = detectEmailUpdate(dbSession, authenticatorParameters, disabledUser != null ? disabledUser.getUuid() : null);
    NewUser newUser = createNewUser(authenticatorParameters);
    if (disabledUser == null) {
        return userUpdater.createAndCommit(dbSession, newUser, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex));
    }
    return userUpdater.reactivateAndCommit(dbSession, disabledUser, newUser, beforeCommit(dbSession, authenticatorParameters), toArray(otherUserToIndex));
}
Also used : UserDto(org.sonar.db.user.UserDto) NewUser(org.sonar.server.user.NewUser)

Example 2 with NewUser

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

the class CreateAction method doHandle.

private CreateWsResponse doHandle(CreateRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        String login = request.getLogin();
        NewUser.Builder newUser = NewUser.builder().setLogin(login).setName(request.getName()).setEmail(request.getEmail()).setScmAccounts(request.getScmAccounts()).setPassword(request.getPassword());
        if (!request.isLocal()) {
            newUser.setExternalIdentity(new ExternalIdentity(SQ_AUTHORITY, login, login));
        }
        UserDto existingUser = dbClient.userDao().selectByLogin(dbSession, login);
        if (existingUser == null) {
            return buildResponse(userUpdater.createAndCommit(dbSession, newUser.build(), u -> {
            }));
        }
        checkArgument(!existingUser.isActive(), "An active user with login '%s' already exists", login);
        return buildResponse(userUpdater.reactivateAndCommit(dbSession, existingUser, newUser.build(), u -> {
        }));
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) EmailValidator.isValidIfPresent(org.sonar.server.user.ws.EmailValidator.isValidIfPresent) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) NewUser(org.sonar.server.user.NewUser) DbSession(org.sonar.db.DbSession) UserUpdater(org.sonar.server.user.UserUpdater) NAME_MAX_LENGTH(org.sonar.server.user.UserUpdater.NAME_MAX_LENGTH) PARAM_PASSWORD(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD) Request(org.sonar.api.server.ws.Request) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PARAM_EMAIL(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_EMAIL) WebService(org.sonar.api.server.ws.WebService) Response(org.sonar.api.server.ws.Response) Nullable(javax.annotation.Nullable) ACTION_CREATE(org.sonarqube.ws.client.user.UsersWsParameters.ACTION_CREATE) EMAIL_MAX_LENGTH(org.sonar.server.user.UserUpdater.EMAIL_MAX_LENGTH) LOGIN_MIN_LENGTH(org.sonar.server.user.UserUpdater.LOGIN_MIN_LENGTH) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) CreateWsResponse(org.sonarqube.ws.Users.CreateWsResponse) PARAM_LOGIN(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN) PARAM_LOCAL(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOCAL) ExternalIdentity(org.sonar.server.user.ExternalIdentity) PARAM_NAME(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME) DbClient(org.sonar.db.DbClient) List(java.util.List) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) SQ_AUTHORITY(org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY) Change(org.sonar.api.server.ws.Change) PARAM_SCM_ACCOUNT(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT) UserSession(org.sonar.server.user.UserSession) Collections(java.util.Collections) CheckForNull(javax.annotation.CheckForNull) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) LOGIN_MAX_LENGTH(org.sonar.server.user.UserUpdater.LOGIN_MAX_LENGTH) DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) ExternalIdentity(org.sonar.server.user.ExternalIdentity) NewUser(org.sonar.server.user.NewUser)

Aggregations

UserDto (org.sonar.db.user.UserDto)2 NewUser (org.sonar.server.user.NewUser)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings.emptyToNull (com.google.common.base.Strings.emptyToNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 Change (org.sonar.api.server.ws.Change)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 ExternalIdentity (org.sonar.server.user.ExternalIdentity)1 SQ_AUTHORITY (org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY)1 UserSession (org.sonar.server.user.UserSession)1