有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为accestype public的客户机使用KeyClope管理客户机以编程方式创建用户

我刚开始使用KeyClope,似乎遇到了障碍。我无法使用KeyClope admin client for java以编程方式创建用户。我的keydape服务器版本是8.0.0,library/jar版本也一样。当我尝试创建一个用户时,我的程序只是坐在那里等待,在日志中我可以看到登录错误

2019-12-03 20:10:19,842 WARN  [org.keycloak.events] (default task-26) type=LOGIN_ERROR, realmId=root-admin, clientId=demo-app, userId=null, ipAddress=192.x.x.x, error=not_allowed, auth_method=oauth_credentials, grant_type=password, client_auth_method=client-secret


Keycloak keycloak = KeycloakBuilder.builder() //
                .serverUrl("http://192.x.x.x:8080/auth") //
                .realm("root-admin") //
                .grantType(OAuth2Constants.PASSWORD) //
                .clientId("demo-app")
                .clientSecret("")////
                .username("genghis khan") //
                .password("1234") //
                .build();
        CredentialRepresentation credential = new CredentialRepresentation();
        credential.setType(CredentialRepresentation.PASSWORD);
        credential.setValue("12345678");
        UserRepresentation user = new UserRepresentation();
        user.setEnabled(true);
        user.setUsername("michaeljackson");
        user.setFirstName("michael");
        user.setLastName("jackson");
        user.setCredentials(Arrays.asList(credential));

        Response resp=keycloak.realm("root-admin").users().create(user);
        System.out.println(resp.getStatus());

我的客户端是一个面向公众的应用程序,所以它的访问类型设置为public,因此不会为它生成客户端密码,而且成吉思汗用户的角色是admin,根管理员域是由我创建的。需要关于如何使其工作的帮助吗


共 (1) 个答案