// During callback, the callback URL is by definition not needed, but the Saml2Settings does never allow this setting to be empty...
samlData.put("onelogin.saml2.sp.assertion_consumer_service.url", callbackUrl != null ? callbackUrl : ANY_URL);
- SettingsBuilder builder = new SettingsBuilder();
- return builder
- .fromValues(samlData)
- .build();
+
+ var saml2Settings = new SettingsBuilder().fromValues(samlData).build();
+ if (samlSettings.getServiceProviderPrivateKey().isPresent() && saml2Settings.getSPkey() == null) {
+ LOGGER.error("Error in parsing service provider private key, please make sure that it is in PKCS 8 format.");
+ }
+ return saml2Settings;
}
private static HttpServletRequest useProxyHeadersInRequest(HttpServletRequest request) {
import org.sonar.api.server.authentication.UnauthorizedException;
import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.LogAndArguments;
+import org.sonar.api.utils.log.LogTester;
import org.sonar.db.DbTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.sonar.api.utils.log.LoggerLevel.ERROR;
public class SamlIdentityProviderTest {
private static final String SQ_CALLBACK_URL = "http://localhost:9000/oauth2/callback/saml";
@Rule
public DbTester db = DbTester.create();
+ @Rule
+ public LogTester log = new LogTester();
private final MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, SamlSettings.definitions()));
private final SamlIdentityProvider underTest = new SamlIdentityProvider(new SamlSettings(settings.asConfig()), new SamlMessageIdChecker(db.getDbClient()));
assertThat(callbackContext.userIdentity.getGroups()).isEmpty();
}
+ @Test
+ public void log_clear_error_when_private_key_is_not_pkcs8() {
+ var WRONG_FORMAT_PRIVATE_KEY = "MIIEpAIBAAKCAQEA0haE9+9QtP5JWbj4LymxiLZJk2n+QsHjVy/Lt/PXffGjl0aQ0O5mk13Vf1vlXC/L1FoPMhup5/AkcMHmJxkzXZ/VAHYYJJ78UHt6atxMDicpbOBaYqumE4fg0H4mVEIs4xYwzq/xhuTtpTb00ZCOF2Y/151o0alWc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SQXG2tUCr9MyaQoyAaRjiNsIceeGBcB+qouPxfFtSWdi3B47FRvyH1qVMj3ImPihxHRlaz4snNOGb5KrrulqZizyemZaFK722sYBmBfuMkQAxdXnK6mIOqJyWOjVBVSnhyPk3STwn++WkytrxghI8W7VPKKIjkJpvECgYBBnvWXa8Ez/azEN+Y2Lc1PnU9OpNa/QRPUPApq15dB8Cu9e2Vm6F+CdGKBY8WQvDw7DJd6eOjCfN6ymy1O9vLiooNQJGaO/znncU1r3s42dfpQ8owthILl24GNXnEgth2yYfYPr/EVLoVsbgO0WKFvdsVbSo/upeLzGnVT+DMqfA==";
+ setSettings(true);
+ settings.setProperty("sonar.auth.saml.sp.privateKey.secured", WRONG_FORMAT_PRIVATE_KEY);
+ DumbCallbackContext callbackContext = new DumbCallbackContext(request, response, "encoded_minimal_response.txt", SQ_CALLBACK_URL);
+
+ underTest.callback(callbackContext);
+
+ assertThat(log.getLogs(ERROR))
+ .extracting(LogAndArguments::getFormattedMsg)
+ .contains("Error in parsing service provider private key, please make sure that it is in PKCS 8 format.");
+ }
+
@Test
public void callback_does_not_sync_group_when_group_setting_is_not_set() {
setSettings(true);