|
|
@@ -0,0 +1,37 @@
|
|
|
+package com.inspur.customer;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.keycloak.admin.client.Keycloak;
|
|
|
+import org.keycloak.representations.idm.UserRepresentation;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zengweijie
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2022/6/22 17:32
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@SpringBootTest
|
|
|
+public class KeycloakTest {
|
|
|
+ @Resource
|
|
|
+ Keycloak keycloak;
|
|
|
+ @Value("${keycloak.realm}")
|
|
|
+ private String realm;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test() {
|
|
|
+ List<UserRepresentation> userRepresentations = keycloak.realm(realm).users().searchByAttributes("wechat-applet-openid:oLBkj42qubLayXZWmFlGnKh5X");
|
|
|
+ for (UserRepresentation userRepresentation : userRepresentations) {
|
|
|
+ log.info(userRepresentation.toString());
|
|
|
+ log.info(userRepresentation.getUsername());
|
|
|
+ Optional.ofNullable(userRepresentation.getAttributes()).ifPresent(t -> log.info(t.toString()));
|
|
|
+ log.info("_______________________________");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|