[精讚] [會員登入]
390

keycloak 透過java client lib新增user

使用keycloak-admin-client lib maven <dependency> <gro

分享此文連結 //n.sfs.tw/15093

分享連結 keycloak 透過java client lib新增user@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
最後編修
2021-05-10 08:48:34 By igogo
 

 

 

使用keycloak-admin-client lib

 

maven

	<dependency>
			<groupId>org.keycloak</groupId>
			<artifactId>keycloak-admin-client</artifactId>
			<version>12.0.4</version>
	</dependency>

 

 

 

    Keycloak keycloak = Keycloak.getInstance(keycloakserverurl, "master", "admin", "PASSWORD", "demoapp");
        RealmRepresentation realm = keycloak.realm("master").toRepresentation() ;
//          create a user
        UserRepresentation userRepresentation = new UserRepresentation();
        userRepresentation.setUsername("ccc");
        userRepresentation.setFirstName("first name");
        userRepresentation.setEmail("ddd@ccc");
//        userRepresentation.setRequiredActions(Collections.emptyList());
        userRepresentation.setEnabled(true);

        CredentialRepresentation credentialRepresentation = new CredentialRepresentation();
        credentialRepresentation.setType(CredentialRepresentation.PASSWORD);
        credentialRepresentation.setValue("1234");

        userRepresentation.setCredentials(Collections.singletonList(credentialRepresentation));

        Response response = keycloak.realm("master").users().create(userRepresentation);
        System.out.println("response status: " + response.getStatus());

 

參考

https://www.keycloak.org/docs/latest/server_development/

END

你可能感興趣的文章

ArrayList 與 HashMap 範例 public static void main(String[] args) { String titleIds = &

spring boot jpa 使用多個欄位排序 我有一entity 叫 team 資料欄下如下 @Id @GeneratedValue(strategy = Gener

java lambda files filter java, files filter, lambda

Spring Boot Maven wrappers maven, mvnw, build command

停止多執行緒 利用主程式呼叫多執行緒時, 要怎麼停止正在執行的多執行緒

java.time 時間 instant java.time

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

tmux 將終端機切割成多個視 窗 tmux, multiple terminal

apache 反向代理 80轉443轉8080 apache, proxy pass

編碼的順序 utf8 big5

雲端校務系統與OPENLDAP帳號整合(2) openldap,雲端校務

如何在docker 的nginx 做另一個container的反向代理 環境 docker 中一container 跑 nginx 對外服務80 port, http://server 另一c