# Creating attributes on roles with Java and Spring

**URL:** <https://forum.keycloak.org/t/creating-attributes-on-roles-with-java-and-spring/8920>\
**Category:** Getting advice\
**Created:** [May 5, 2021, 6:43pm UTC](https://forum.keycloak.org/t/creating-attributes-on-roles-with-java-and-spring/8920 "2021-05-05T18:43:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbleeker](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/pbleeker/32/5959_2.png) [@pbleeker](https://forum.keycloak.org/u/pbleeker)\
**Post date:** [May 5, 2021, 6:43pm UTC](https://forum.keycloak.org/t/creating-attributes-on-roles-with-java-and-spring/8920/1 "2021-05-05T18:43:54Z")

</div>

I am trying to create Realm roles and attributes on the roles. The code below creates the roles, but the attributes are ignored. Any advice is appreciated.

```
private String createRole(String roleName, String rollDescription, String realm, HashMap<String, List<String>> map) throws JSONException {
	
	try {
		
		String keycloakRolesUri = "http://" + keycloakIPAddress + ":" + keycloakPort + "/auth/admin/realms/$REALM/roles";
		
		final String uri = keycloakRolesUri.replace("$REALM", realm);
		String adminToken = getAdminAccessTokenPWGrant();

		RestTemplate restTemplate = new RestTemplate();
		RoleRepresentation roleRepresentation = new RoleRepresentation();
        
        roleRepresentation.setAttributes(map);
        roleRepresentation.setClientRole(false);
		roleRepresentation.setName(roleName);
		roleRepresentation.setDescription(rollDescription);
		roleRepresentation.setComposite(false);
		
		HttpHeaders headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.set("Authorization", "Bearer " + adminToken);

		HttpEntity<RoleRepresentation> request = new HttpEntity<>(roleRepresentation, headers);
		restTemplate.postForObject(uri, request, RoleRepresentation.class);
	}
	catch(Exception e) {
		log.error(e.getMessage());
		return e.getMessage();
	}
	
	return "success";
}
```
