Org.keycloak.admin.client and keycloak setup

I have hours ferkeling with code and am struggling to get a connection, by code, through to kecycloak.

//    	Keycloak keycloak = KeycloakBuilder.builder() //
//				.serverUrl(keycloakServerURL+"/auth") //
//				.realm("master")//
//				.username("xxx@xxxxx.nz") //
//				.password("password") //
//				.clientId("xxxxxx") //
//				.clientSecret("====================")
//				.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) //
//				.build();
				
//    	// (serverUrl, realm, clientId, authToken)
		Keycloak keycloak = Keycloak.getInstance(
				keycloakServerURL+"/auth",
			    "TheREALMTOCONNECTTO",
			    "THEUSERCREATEDINTHEREALMWITHCONFIDENTIALSOITHASASECRET",
			    "THESECRET"
			    );
//		
//    	Keycloak keycloak = KeycloakBuilder.builder() //
//				.serverUrl(keycloakServerURL+"/auth") //
//				.realm("TheREALMTOCONNECTTO")//
//				.username(xxx@xxxxx.nz") //
//				.password("password") //
//				.grantType(OAuth2Constants.CLIENT_CREDENTIALS) //
//				.clientId("THEUSERCREATEDINTHEREALMWITHCONFIDENTIALSOITHASASECRET") //
//				.clientSecret("THESECRET")
//				.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) //
//				.build();
		
			RealmResource realmResource = keycloak.realm("TheREALMTOCONNECTTO");
		
			RealmRepresentation realm = realmResource.toRepresentation();
			
			List<UserRepresentation> users = realm.getUsers();
			
			logger.info("Number of users:" + users.size());
			
			return users;

Please can someone tell me what/who to set up in a NEW realm in Keycloak (8.0.2) such that I can actually get a connection.

From the hours of googling I think you have to set up a user in the new realm with certainroles/rights/privledges/scopes/??? and then the call has to authenticate somehow.

(from the code aboce; sometimes I get a 401 and sometimes a NPE depending how I cut the code and change settings in web.xml and standalone.xml

web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>xxxxxxx</web-resource-name>
        <url-pattern>/pages/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method> <-- **Changing this to KEYCLOAK seems to haev effects**
</login-config>

<security-role>
    <role-name>*</role-name>
</security-role>

standalone.xml

   <subsystem xmlns="urn:jboss:domain:keycloak:1.1">
  	<secure-deployment name="theplanetsparty.war">
  		<realm>XXXxxxxx</realm>
  		<auth-server-url>http://localhost:8180/auth/</auth-server-url>
  		<ssl-required>EXTERNAL</ssl-required>
  		<resource>xxxxxx</resource> <-- cahnging the user has effects
  		<credential name="secret">xxxxxx</credential>   <-- Adding / removing this has effects
  	</secure-deployment>
  </subsystem>

Any help would be appreciated…

The server is Wildfly 18.0.1.Final
The getting started docuementation was used to set up the server and the code is working fin (JSF project that jumps off to keycloak … and I have set up Goole auth etc.).

I need this to remove/add a role to a user (one they have become a member)…

Also; how do you get the “cancel” button (Login/Register) to come back to my server (only sumbit ends up coming back to the server)?

Some additional resources:

Ill just have to use stright REST calls.

Try Postman :slight_smile:

image

Ref: Flowable OAuth2 Resource Server