Search in sources :

Example 1 with ExternalIdentity

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

the class UserIdentityAuthenticator method registerExistingUser.

private void registerExistingUser(DbSession dbSession, UserDto userDto, UserIdentity user, IdentityProvider provider) {
    userUpdater.update(dbSession, UpdateUser.create(userDto.getLogin()).setEmail(user.getEmail()).setName(user.getName()).setExternalIdentity(new ExternalIdentity(provider.getKey(), user.getProviderLogin())).setPassword(null));
    syncGroups(dbSession, user, userDto);
}
Also used : ExternalIdentity(org.sonar.server.user.ExternalIdentity)

Example 2 with ExternalIdentity

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

the class UserIdentityAuthenticator method registerNewUser.

private UserDto registerNewUser(DbSession dbSession, UserIdentity user, IdentityProvider provider, AuthenticationEvent.Source source) {
    if (!provider.allowsUsersToSignUp()) {
        throw AuthenticationException.newBuilder().setSource(source).setLogin(user.getLogin()).setMessage(format("User signup disabled for provider '%s'", provider.getKey())).setPublicMessage(format("'%s' users are not allowed to sign up", provider.getKey())).build();
    }
    String email = user.getEmail();
    if (email != null && dbClient.userDao().doesEmailExist(dbSession, email)) {
        throw AuthenticationException.newBuilder().setSource(source).setLogin(user.getLogin()).setMessage(format("Email '%s' is already used", email)).setPublicMessage(format("You can't sign up because email '%s' is already used by an existing user. This means that you probably already registered with another account.", email)).build();
    }
    String userLogin = user.getLogin();
    userUpdater.create(dbSession, NewUser.builder().setLogin(userLogin).setEmail(user.getEmail()).setName(user.getName()).setExternalIdentity(new ExternalIdentity(provider.getKey(), user.getProviderLogin())).build());
    UserDto newUser = dbClient.userDao().selectOrFailByLogin(dbSession, userLogin);
    syncGroups(dbSession, user, newUser);
    return newUser;
}
Also used : UserDto(org.sonar.db.user.UserDto) ExternalIdentity(org.sonar.server.user.ExternalIdentity)

Example 3 with ExternalIdentity

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

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

Example 5 with ExternalIdentity

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

Aggregations

ExternalIdentity (org.sonar.server.user.ExternalIdentity)5 UserDto (org.sonar.db.user.UserDto)4 DbSession (org.sonar.db.DbSession)2 UpdateUser (org.sonar.server.user.UpdateUser)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 SQ_AUTHORITY (org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY)1 NewUser (org.sonar.server.user.NewUser)1