3 * Copyright (C) 2009-2018 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.authentication;
23 import org.sonar.api.server.authentication.IdentityProvider;
24 import org.sonar.api.server.authentication.UserIdentity;
25 import org.sonar.server.authentication.event.AuthenticationEvent;
27 import static java.util.Objects.requireNonNull;
29 class UserIdentityAuthenticatorParameters {
32 * Strategy to be executed when the email of the user is already used by another user
34 enum ExistingEmailStrategy {
36 * Authentication is allowed, the email is moved from other user to current user
40 * Authentication process is stopped, the user is redirected to a page explaining that the email is already used
44 * Forbid authentication of the user
50 * Strategy to be executed when the login of the user is updated
52 enum UpdateLoginStrategy {
54 * Authentication is allowed, the login of the user updated
58 * Authentication process is stopped, the user is redirected to a page explaining that the login will be updated.
59 * It only happens when personal organizations are activated
64 private final UserIdentity userIdentity;
65 private final IdentityProvider provider;
66 private final AuthenticationEvent.Source source;
67 private final ExistingEmailStrategy existingEmailStrategy;
68 private final UpdateLoginStrategy updateLoginStrategy;
70 UserIdentityAuthenticatorParameters(Builder builder) {
71 this.userIdentity = builder.userIdentity;
72 this.provider = builder.provider;
73 this.source = builder.source;
74 this.existingEmailStrategy = builder.existingEmailStrategy;
75 this.updateLoginStrategy = builder.updateLoginStrategy;
78 public UserIdentity getUserIdentity() {
82 public IdentityProvider getProvider() {
86 public AuthenticationEvent.Source getSource() {
90 public ExistingEmailStrategy getExistingEmailStrategy() {
91 return existingEmailStrategy;
94 public UpdateLoginStrategy getUpdateLoginStrategy() {
95 return updateLoginStrategy;
98 static UserIdentityAuthenticatorParameters.Builder builder() {
102 public static class Builder {
103 private UserIdentity userIdentity;
104 private IdentityProvider provider;
105 private AuthenticationEvent.Source source;
106 private ExistingEmailStrategy existingEmailStrategy;
107 private UpdateLoginStrategy updateLoginStrategy;
109 public Builder setUserIdentity(UserIdentity userIdentity) {
110 this.userIdentity = userIdentity;
114 public Builder setProvider(IdentityProvider provider) {
115 this.provider = provider;
119 public Builder setSource(AuthenticationEvent.Source source) {
120 this.source = source;
125 * Strategy to be executed when the email of the user is already used by another user
127 public Builder setExistingEmailStrategy(ExistingEmailStrategy existingEmailStrategy) {
128 this.existingEmailStrategy = existingEmailStrategy;
133 * Strategy to be executed when the login of the user has changed
135 public Builder setUpdateLoginStrategy(UpdateLoginStrategy updateLoginStrategy) {
136 this.updateLoginStrategy = updateLoginStrategy;
140 public UserIdentityAuthenticatorParameters build() {
141 requireNonNull(userIdentity, "userIdentity must be set");
142 requireNonNull(provider, "identityProvider must be set");
143 requireNonNull(source, "Source must be set");
144 requireNonNull(existingEmailStrategy, "existingEmailStrategy must be set ");
145 requireNonNull(updateLoginStrategy, "updateLoginStrategy must be set");
146 return new UserIdentityAuthenticatorParameters(this);