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);
}
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;
}
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;
}
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 -> {
}));
}
}
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 -> {
});
}
}
Aggregations