Search in sources :

Example 1 with SQ_AUTHORITY

use of org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY 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

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 UserDto (org.sonar.db.user.UserDto)1 ExternalIdentity (org.sonar.server.user.ExternalIdentity)1 SQ_AUTHORITY (org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY)1 NewUser (org.sonar.server.user.NewUser)1 UserSession (org.sonar.server.user.UserSession)1