[精讚] [會員登入]
346

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

你可能感興趣的文章

java-身份証字號驗証 FormatCheck.java public class FormatCheck { private volatile

spring boot 使用jdbc連接mariadb spring boot, mariadb, jdbc, rowmapper

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

[vue.js] 設定 content type 今天在wickt 端怎麼就是收不到vue.js 以post 傳過來的資料 找了好久才發現 application/jso

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

Arrays.asList 後想再add出現 UnsupportedOperationException 這個問題真是搞死我了 List<String> fruits = Arrays.asList("a

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

centos 7 移机出現 dracut-initqueue timeout centos 7 移机出現 dracut-initqueue timeout 處理

vim 特定範圍行數開頭加上# 註解 vim 特定範圍行數開頭加上# 註解

刪除資料夾內的檔案 lambda 一行文 Arrays.stream(new File("/folder/path").

Spring Boot Maven wrappers maven, mvnw, build command

scratch 不重覆隨機取陣列值 隨機取數是在設計遊戲時, 很常用到的技巧 最簡單的就是使用運算積木裡的隨機取數範圍 但是, 如果我是想全部取出且不重覆,