import org.sonar.api.platform.Server;
import org.sonar.api.server.authentication.OAuth2IdentityProvider;
import org.sonar.api.server.authentication.UserIdentity;
+import org.sonar.api.utils.MessageException;
+import static java.lang.String.format;
import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
+import static org.sonar.server.authentication.OAuth2CallbackFilter.CALLBACK_PATH;
public class OAuth2ContextFactory {
public String getCallbackUrl() {
String publicRootUrl = server.getPublicRootUrl();
if (publicRootUrl.startsWith("http:") && !server.isDev()) {
- throw new IllegalStateException(String.format("The server url should be configured in https, please update the property '%s'", SERVER_BASE_URL));
+ throw MessageException.of(format("The server url should be configured in https, please update the property '%s'", SERVER_BASE_URL));
}
- return publicRootUrl + OAuth2CallbackFilter.CALLBACK_PATH + "/" + identityProvider.getKey();
+ return publicRootUrl + CALLBACK_PATH + "/" + identityProvider.getKey();
}
@Override
try {
response.sendRedirect(url);
} catch (IOException e) {
- throw new IllegalStateException(String.format("Fail to redirect to %s", url), e);
+ throw new IllegalStateException(format("Fail to redirect to %s", url), e);
}
}
import org.sonar.api.platform.Server;
import org.sonar.api.server.authentication.OAuth2IdentityProvider;
import org.sonar.api.server.authentication.UserIdentity;
+import org.sonar.api.utils.MessageException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
OAuth2IdentityProvider.InitContext context = underTest.newContext(request, response, identityProvider);
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The server url should be configured in https, please update the property 'sonar.core.serverBaseURL'");
context.getCallbackUrl();
}