diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-03-14 11:54:57 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-03-16 11:06:14 +0100 |
commit | ab9805fd7b22aa2c488d59d38d8f0cf707e7763d (patch) | |
tree | 31538745192817c6c7f61a0c6c82f4d5698d8225 /it/it-plugins | |
parent | f29df5da27030596d7d3ef07b4e833bb664cb940 (diff) | |
download | sonarqube-ab9805fd7b22aa2c488d59d38d8f0cf707e7763d.tar.gz sonarqube-ab9805fd7b22aa2c488d59d38d8f0cf707e7763d.zip |
SONAR-7444 Provide an UnauthorizedException to display functional error
Diffstat (limited to 'it/it-plugins')
-rw-r--r-- | it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java b/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java index 730bef971e1..a7d897b137f 100644 --- a/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java +++ b/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.sonar.api.config.Settings; import org.sonar.api.server.authentication.BaseIdentityProvider; import org.sonar.api.server.authentication.Display; +import org.sonar.api.server.authentication.UnauthorizedException; import org.sonar.api.server.authentication.UserIdentity; public class FakeBaseIdProvider implements BaseIdentityProvider { @@ -29,6 +30,8 @@ public class FakeBaseIdProvider implements BaseIdentityProvider { private static final String ALLOWS_USERS_TO_SIGN_UP = "sonar.auth.fake-base-id-provider.allowsUsersToSignUp"; private static final String USER_INFO = "sonar.auth.fake-base-id-provider.user"; + private static final String THROW_UNAUTHORIZED_EXCEPTION = "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage"; + private final Settings settings; public FakeBaseIdProvider(Settings settings) { @@ -41,6 +44,11 @@ public class FakeBaseIdProvider implements BaseIdentityProvider { if (userInfoProperty == null) { throw new IllegalStateException(String.format("The property %s is required", USER_INFO)); } + boolean throwUnauthorizedException = settings.getBoolean(THROW_UNAUTHORIZED_EXCEPTION); + if (throwUnauthorizedException) { + throw new UnauthorizedException("A functional error has happened"); + } + String[] userInfos = userInfoProperty.split(","); context.authenticate(UserIdentity.builder() .setLogin(userInfos[0]) |