KEYCLOAK-6676: Fix NPE if the redirect_uri parameter is missing

This commit is contained in:
Erlend Hamnaberg authored and Marek Posolda committed 2018-02-21 19:44:22 +01:00
1 parent 61d5425fdf
commit 208ecbc3f7
2 files changed
+16 -1

No files matched your search

@@ -308,7 +308,7 @@ public class TokenEndpoint {
String redirectUriParam = formParams.getFirst(OAuth2Constants.REDIRECT_URI);
// KEYCLOAK-4478 Backwards compatibility with the adapters earlier than KC 3.4.2
if (redirectUriParam.contains("session_state=")) {
if (redirectUriParam != null && redirectUriParam.contains("session_state=")) {
redirectUriParam = KeycloakUriBuilder.fromUri(redirectUriParam)
.replaceQueryParam(OAuth2Constants.SESSION_STATE, null)
.build().toString();
@@ -346,6 +346,21 @@ public class OAuthRedirectUriTest extends AbstractKeycloakTest {
checkRedirectUri("http://localhost/myapp2", false);
}
@Test
public void okThenNull() throws IOException {
oauth.clientId("test-wildcard");
oauth.redirectUri("http://localhost:8280/foo");
oauth.doLogin("test-user@localhost", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
Assert.assertNotNull(code);
oauth.redirectUri(null);
OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");
Assert.assertEquals("Expected 400, but got something else", 400, tokenResponse.getStatusCode());
}
private void checkRedirectUri(String redirectUri, boolean expectValid) throws IOException {
checkRedirectUri(redirectUri, expectValid, false);
}