Skip to content

Commit c22f768

Browse files
authored
Move doLogin to AbstractOAuthClient (#37638)
Closes #37637 Signed-off-by: stianst <[email protected]>
1 parent acb7abc commit c22f768

File tree

226 files changed

+1197
-3787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+1197
-3787
lines changed

js/apps/account-ui/maven-resources/theme/keycloak.v3/account/index.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
</#list>
124124
</#if>
125125
</head>
126-
<body>
126+
<body data-page-id="account">
127127
<div id="app">
128128
<main class="container">
129129
<div class="keycloak__loading-container">

js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/index.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
</#list>
124124
</#if>
125125
</head>
126-
<body>
126+
<body data-page-id="admin">
127127
<div id="app">
128128
<main class="container">
129129
<div class="keycloak__loading-container">

services/src/main/java/org/keycloak/forms/login/freemarker/FreeMarkerLoginFormsProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ protected Response processTemplate(Theme theme, String templateName, Locale loca
600600
if (!attributes.containsKey("templateName")) {
601601
attributes.put("templateName", templateName);
602602
}
603+
604+
attributes.put("pageId", templateName.substring(0, templateName.length() - 4));
605+
603606
String result = freeMarker.processTemplate(attributes, templateName, theme);
604607
Response.ResponseBuilder builder = Response.status(status == null ? Response.Status.OK : status).type(MediaType.TEXT_HTML_UTF_8_TYPE).language(locale).entity(result);
605608
for (Map.Entry<String, String> entry : httpResponseHeaders.entrySet()) {

services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ private static Map<String, Object> initAttributes(KeycloakSession session, Realm
188188
final var localeBean = new LocaleBean(realm, locale, session.getContext().getUri().getRequestUriBuilder(), messagesBundle);
189189
final var lang = realm.isInternationalizationEnabled() ? localeBean.getCurrentLanguageTag() : Locale.ENGLISH.toLanguageTag();
190190

191+
attributes.put("pageId", "error");
191192
attributes.put("statusCode", responseStatus.getStatusCode());
192193

193194
attributes.put("realm", realm);

test-framework/bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</dependency>
4848
<dependency>
4949
<groupId>org.keycloak.testframework</groupId>
50-
<artifactId>keycloak-test-framework-oauth-nimbus-poc</artifactId>
50+
<artifactId>keycloak-test-framework-oauth</artifactId>
5151
<version>${project.version}</version>
5252
<scope>test</scope>
5353
</dependency>

test-framework/examples/tests/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@
7272
<groupId>org.keycloak.testframework</groupId>
7373
<artifactId>keycloak-test-framework-oauth</artifactId>
7474
</dependency>
75-
<dependency>
76-
<groupId>org.keycloak.testframework</groupId>
77-
<artifactId>keycloak-test-framework-oauth-nimbus-poc</artifactId>
78-
</dependency>
7975
<dependency>
8076
<groupId>org.keycloak.testframework</groupId>
8177
<artifactId>keycloak-test-framework-email-server</artifactId>

test-framework/examples/tests/src/test/java/org/keycloak/test/examples/EmailTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.keycloak.test.examples;
22

3-
import com.nimbusds.oauth2.sdk.GeneralException;
43
import jakarta.mail.MessagingException;
54
import jakarta.mail.internet.MimeMessage;
65
import org.junit.jupiter.api.Assertions;
@@ -11,16 +10,15 @@
1110
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
1211
import org.keycloak.testframework.mail.MailServer;
1312
import org.keycloak.testframework.mail.annotations.InjectMailServer;
14-
import org.keycloak.testframework.oauth.nimbus.OAuthClient;
15-
import org.keycloak.testframework.oauth.nimbus.annotations.InjectOAuthClient;
13+
import org.keycloak.testframework.oauth.OAuthClient;
14+
import org.keycloak.testframework.oauth.annotations.InjectOAuthClient;
1615
import org.keycloak.testframework.realm.ManagedRealm;
1716
import org.keycloak.testframework.realm.ManagedUser;
1817
import org.keycloak.testframework.realm.RealmConfig;
1918
import org.keycloak.testframework.realm.RealmConfigBuilder;
2019
import org.keycloak.testframework.realm.UserConfig;
2120
import org.keycloak.testframework.realm.UserConfigBuilder;
2221

23-
import java.io.IOException;
2422
import java.util.Map;
2523

2624
@KeycloakIntegrationTest
@@ -39,8 +37,8 @@ public class EmailTest {
3937
OAuthClient oAuthClient;
4038

4139
@Test
42-
public void testEmail() throws GeneralException, IOException, MessagingException {
43-
oAuthClient.resourceOwnerCredentialGrant(user.getUsername(), "invalid");
40+
public void testEmail() throws MessagingException {
41+
oAuthClient.doPasswordGrantRequest(user.getUsername(), "invalid");
4442

4543
Map<String, String> smtpServer = realm.admin().toRepresentation().getSmtpServer();
4644
Assertions.assertEquals("[email protected]", smtpServer.get("from"));

test-framework/examples/tests/src/test/java/org/keycloak/test/examples/EventsTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.keycloak.test.examples;
22

3-
import com.nimbusds.oauth2.sdk.GeneralException;
43
import org.junit.jupiter.api.Assertions;
54
import org.junit.jupiter.api.Test;
65
import org.keycloak.events.EventType;
@@ -9,14 +8,12 @@
98
import org.keycloak.testframework.annotations.InjectRealm;
109
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
1110
import org.keycloak.testframework.events.Events;
12-
import org.keycloak.testframework.oauth.nimbus.OAuthClient;
13-
import org.keycloak.testframework.oauth.nimbus.annotations.InjectOAuthClient;
11+
import org.keycloak.testframework.oauth.OAuthClient;
12+
import org.keycloak.testframework.oauth.annotations.InjectOAuthClient;
1413
import org.keycloak.testframework.realm.ManagedRealm;
1514
import org.keycloak.testframework.remote.timeoffset.InjectTimeOffSet;
1615
import org.keycloak.testframework.remote.timeoffset.TimeOffSet;
1716

18-
import java.io.IOException;
19-
2017
@KeycloakIntegrationTest
2118
public class EventsTest {
2219

@@ -34,31 +31,31 @@ public class EventsTest {
3431

3532
@Test
3633
public void testFailedLogin() {
37-
oAuthClient.resourceOwnerCredentialGrant("invalid", "invalid");
34+
oAuthClient.doPasswordGrantRequest("invalid", "invalid");
3835

3936
EventRepresentation event = events.poll();
4037
Assertions.assertEquals(EventType.LOGIN_ERROR.name(), event.getType());
4138
Assertions.assertEquals("invalid", event.getDetails().get("username"));
4239

43-
oAuthClient.resourceOwnerCredentialGrant("invalid2", "invalid");
40+
oAuthClient.doPasswordGrantRequest("invalid2", "invalid");
4441

4542
event = events.poll();
4643
Assertions.assertEquals(EventType.LOGIN_ERROR.name(), event.getType());
4744
Assertions.assertEquals("invalid2", event.getDetails().get("username"));
4845
}
4946

5047
@Test
51-
public void testTimeOffset() throws GeneralException, IOException {
48+
public void testTimeOffset() {
5249
timeOffSet.set(60);
5350

54-
oAuthClient.clientCredentialGrant();
51+
oAuthClient.doClientCredentialsGrantAccessTokenRequest();
5552

5653
Assertions.assertEquals(EventType.CLIENT_LOGIN.name(), events.poll().getType());
5754
}
5855

5956
@Test
60-
public void testClientLogin() throws GeneralException, IOException {
61-
oAuthClient.clientCredentialGrant();
57+
public void testClientLogin() {
58+
oAuthClient.doClientCredentialsGrantAccessTokenRequest();
6259

6360
Assertions.assertEquals(EventType.CLIENT_LOGIN.name(), events.poll().getType());
6461
}

test-framework/examples/tests/src/test/java/org/keycloak/test/examples/NimbusOAuthClientTest.java

Lines changed: 0 additions & 103 deletions
This file was deleted.

test-framework/examples/tests/src/test/java/org/keycloak/test/examples/OAuthClientTest.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,89 @@
22

33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.Test;
5-
import org.keycloak.testframework.annotations.InjectClient;
65
import org.keycloak.testframework.annotations.InjectRealm;
76
import org.keycloak.testframework.annotations.InjectUser;
87
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
98
import org.keycloak.testframework.oauth.OAuthClient;
109
import org.keycloak.testframework.oauth.annotations.InjectOAuthClient;
11-
import org.keycloak.testframework.realm.ClientConfig;
12-
import org.keycloak.testframework.realm.ClientConfigBuilder;
13-
import org.keycloak.testframework.realm.ManagedClient;
1410
import org.keycloak.testframework.realm.ManagedRealm;
1511
import org.keycloak.testframework.realm.ManagedUser;
1612
import org.keycloak.testframework.realm.UserConfig;
1713
import org.keycloak.testframework.realm.UserConfigBuilder;
1814
import org.keycloak.testsuite.util.oauth.AccessTokenResponse;
15+
import org.keycloak.testsuite.util.oauth.AuthorizationEndpointResponse;
1916
import org.keycloak.testsuite.util.oauth.TokenRevocationResponse;
2017
import org.keycloak.testsuite.util.oauth.UserInfoResponse;
2118

2219
@KeycloakIntegrationTest
2320
public class OAuthClientTest {
2421

2522
@InjectOAuthClient
26-
OAuthClient oAuthClient;
23+
OAuthClient oauth;
2724

2825
@InjectRealm
2926
ManagedRealm managedRealm;
3027

31-
@InjectClient(config = OAuthClientConfig.class)
32-
ManagedClient client;
33-
3428
@InjectUser(config = OAuthUserConfig.class)
3529
ManagedUser user;
3630

3731
@Test
3832
public void testConfig() {
39-
Assertions.assertEquals(managedRealm.getName(), oAuthClient.config().getRealm());
40-
Assertions.assertEquals(managedRealm.getBaseUrl() + "/protocol/openid-connect/token", oAuthClient.getEndpoints().getToken());
33+
Assertions.assertEquals(managedRealm.getName(), oauth.config().getRealm());
34+
Assertions.assertEquals(managedRealm.getBaseUrl() + "/protocol/openid-connect/token", oauth.getEndpoints().getToken());
35+
}
36+
37+
@Test
38+
public void testLogin() {
39+
AuthorizationEndpointResponse response = oauth.doLogin(user.getUsername(), user.getPassword());
40+
Assertions.assertTrue(response.isRedirected());
4141
}
4242

4343
@Test
4444
public void testPasswordGrant() {
45-
AccessTokenResponse accessTokenResponse = oAuthClient.doPasswordGrantRequest(user.getUsername(), user.getPassword());
45+
AccessTokenResponse accessTokenResponse = oauth.doPasswordGrantRequest(user.getUsername(), user.getPassword());
4646
Assertions.assertTrue(accessTokenResponse.isSuccess());
4747

48-
accessTokenResponse = oAuthClient.passwordGrantRequest(user.getUsername(), "invalid").send();
48+
accessTokenResponse = oauth.passwordGrantRequest(user.getUsername(), "invalid").send();
4949
Assertions.assertFalse(accessTokenResponse.isSuccess());
5050
Assertions.assertEquals("Invalid user credentials", accessTokenResponse.getErrorDescription());
5151
}
5252

5353
@Test
5454
public void testClientCredential() {
55-
AccessTokenResponse accessTokenResponse = oAuthClient.doClientCredentialsGrantAccessTokenRequest();
55+
AccessTokenResponse accessTokenResponse = oauth.doClientCredentialsGrantAccessTokenRequest();
5656
Assertions.assertTrue(accessTokenResponse.isSuccess());
5757
}
5858

5959
@Test
6060
public void testUserInfo() {
61-
AccessTokenResponse accessTokenResponse = oAuthClient.doPasswordGrantRequest(user.getUsername(), user.getPassword());
61+
AccessTokenResponse accessTokenResponse = oauth.doPasswordGrantRequest(user.getUsername(), user.getPassword());
6262

63-
UserInfoResponse userInfoResponse = oAuthClient.doUserInfoRequest(accessTokenResponse.getAccessToken());
63+
UserInfoResponse userInfoResponse = oauth.doUserInfoRequest(accessTokenResponse.getAccessToken());
6464
Assertions.assertTrue(userInfoResponse.isSuccess());
6565
Assertions.assertEquals(user.getUsername(), userInfoResponse.getUserInfo().getPreferredUsername());
6666
}
6767

6868
@Test
6969
public void testRefresh() {
70-
AccessTokenResponse accessTokenResponse = oAuthClient.doPasswordGrantRequest(user.getUsername(), user.getPassword());
70+
AccessTokenResponse accessTokenResponse = oauth.doPasswordGrantRequest(user.getUsername(), user.getPassword());
7171

72-
AccessTokenResponse refreshResponse = oAuthClient.doRefreshTokenRequest(accessTokenResponse.getRefreshToken());
72+
AccessTokenResponse refreshResponse = oauth.doRefreshTokenRequest(accessTokenResponse.getRefreshToken());
7373
Assertions.assertTrue(refreshResponse.isSuccess());
7474
Assertions.assertNotEquals(accessTokenResponse.getAccessToken(), refreshResponse.getAccessToken());
7575
}
7676

7777
@Test
7878
public void testRevocation() {
79-
AccessTokenResponse accessTokenResponse = oAuthClient.doPasswordGrantRequest(user.getUsername(), user.getPassword());
79+
AccessTokenResponse accessTokenResponse = oauth.doPasswordGrantRequest(user.getUsername(), user.getPassword());
8080

81-
TokenRevocationResponse tokenRevocationResponse = oAuthClient.doTokenRevoke(accessTokenResponse.getRefreshToken());
81+
TokenRevocationResponse tokenRevocationResponse = oauth.doTokenRevoke(accessTokenResponse.getRefreshToken());
8282
Assertions.assertTrue(tokenRevocationResponse.isSuccess());
8383

84-
AccessTokenResponse refreshResponse = oAuthClient.doRefreshTokenRequest(accessTokenResponse.getRefreshToken());
84+
AccessTokenResponse refreshResponse = oauth.doRefreshTokenRequest(accessTokenResponse.getRefreshToken());
8585
Assertions.assertFalse(refreshResponse.isSuccess());
8686
}
8787

88-
public static class OAuthClientConfig implements ClientConfig {
89-
90-
@Override
91-
public ClientConfigBuilder configure(ClientConfigBuilder client) {
92-
return client.clientId("myclient").secret("mysecret").directAccessGrants().serviceAccount();
93-
}
94-
}
95-
9688
public static class OAuthUserConfig implements UserConfig {
9789

9890
@Override

0 commit comments

Comments
 (0)