我尝试使用 keycloak 客户端管理员在我的 keycloak 中创建一个用户
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>6.0.1</version>
</dependency>
并使用此代码:
Keycloak keycloak = KeycloakBuilder.builder() //
.serverUrl(serverUrl) //
.realm(realm) //
.grantType(OAuth2Constants.PASSWORD) //
.clientId(clientId) //
.clientSecret(clientSecret) //
.username("idm-admin") //
.password("admin") //
.build();
UserRepresentation user = new UserRepresentation();
user.setEnabled(true);
user.setUsername("tester1");
user.setFirstName("First");
user.setLastName("Last");
user.setEmail("tom+tester1@tdlabs.local");
user.setAttributes(Collections.singletonMap("origin", Arrays.asList("demo")));
// Get realm
RealmResource realmResource = keycloak.realm(realm);
UsersResource userRessource = realmResource.users();
// Create user (requires manage-users role)
Response response = userRessource.create(user);
System.out.println("Repsonse: " + response.getStatusInfo());
System.out.println(response.getLocation());
String userId = response.getLocation().getPath().replaceAll(".*/([^/]+)$", "$1");
System.out.printf("User created with userId: %s%n", userId);
// Get realm role "tester" (requires view-realm role)
RoleRepresentation testerRealmRole = realmResource.roles()//
.get("tester").toRepresentation();
// Assign realm role tester to user
userRessource.get(userId).roles().realmLevel() //
.add(Arrays.asList(testerRealmRole));
但在我的行 Response response = userRessource.create(user); IDE 显示错误:无法访问 javax.ws.rs.core.Response;我正在使用 spring-boot 2.0.5.RELEASE 和 java 1.8
慕沐林林
海绵宝宝撒
互换的青春
相关分类