admin管理员组

文章数量:1356908

In a Quarkus application I'm trying to automate tests with Keycloak dev service integration with these props:

%test.quarkus.oidc.enabled=true
%test.quarkus.keycloak.devservices.enabled=true
%test.quarkus.keycloak.devservices.realm-path=quarkus-realm.json

and these dependencies:

implementation 'io.quarkus:quarkus-oidc'
implementation 'io.quarkus:quarkus-oidc-client'
implementation("io.quarkus:quarkus-keycloak-admin-client")

where the quarkus-realm.json is this:

{
  "realm": "quarkus",
  "enabled": true,
  "groups": [
    {
      "name": "AziendaXXX"
    },
    {
      "name": "AziendaYYY"
    }
  ],
  "users": [
    {
      "username": "alice",
      "enabled": true,
      "emailVerified": true,
      "firstName": "Alice",
      "lastName": "Wonderland",
      "credentials": [
        {
          "type": "password",
          "value": "alice"
        }
      ],
      "clientRoles": {
        "realm-management": [
          "view-clients",
          "manage-users",
          "view-users"
        ],
        "front-end": [
          "ADMIN"
        ]
      },
      "groups": [
        "/AziendaXXX",
        "/AziendaYYY"
      ],
      "attributes": {
        "phoneNumber": "1234567890",
        "profilePic": "alice-pic-base64",
        "authType": "keycloak"
      }
    },
    {
      "username": "bob",
      "enabled": true,
      "emailVerified": true,
      "firstName": "Bob",
      "lastName": "Builder",
      "credentials": [
        {
          "type": "password",
          "value": "bob"
        }
      ],
      "clientRoles": {
        "realm-management": [
          "view-clients",
          "manage-users",
          "view-users"
        ],
        "front-end": [
          "ADMIN"
        ]
      },
      "groups": [
        "/AziendaXXX"
      ],
      "attributes": {
        "phoneNumber": "0987654321",
        "profilePic": "bob-pic-base64",
        "authType": "keycloak"
      }
    }
  ],
  "clients": [
    {
      "clientId": "back-end",
      "enabled": true,
      "secret": "xxx",
      "clientAuthenticatorType": "client-secret",
      "redirectUris": [
        "*"
      ],
      "webOrigins": [
        "*"
      ],
      "publicClient": false,
      "protocol": "openid-connect",
      "serviceAccountsEnabled": true,
      "directAccessGrantsEnabled": true
    },
    {
      "clientId": "front-end",
      "enabled": true,
      "publicClient": true,
      "protocol": "openid-connect",
      "redirectUris": [
        "*"
      ],
      "webOrigins": [
        "*"
      ],
      "directAccessGrantsEnabled": true,
      "standardFlowEnabled": true,
      "implicitFlowEnabled": false,
      "serviceAccountsEnabled": false,
      "protocolMappers": [
        {
          "name": "roles",
          "protocol": "openid-connect",
          "protocolMapper": "oidc-usermodel-client-role-mapper",
          "consentRequired": false,
          "config": {
            "multivalued": "true",
            "userinfo.token.claim": "true",
            "id.token.claim": "true",
            "access.token.claim": "true",
            "claim.name": "roles",
            "jsonType.label": "String",
            "client.id": "front-end"
          }
        },
        {
          "name": "groups-to-aziende",
          "protocol": "openid-connect",
          "protocolMapper": "oidc-group-membership-mapper",
          "consentRequired": false,
          "config": {
            "claim.name": "aziende",
            "full.path": "false",
            "id.token.claim": "true",
            "access.token.claim": "true",
            "userinfo.token.claim": "true"
          }
        }
      ]
    }
  ],
  "roles": {
    "client": {
      "front-end": [
        {
          "name": "ADMIN",
          "description": "",
          "composite": false,
          "clientRole": true
        }
      ]
    }
  }
}

If I get an existing user (alice or bob) the attributes are correctly showed, but when I try to create a new user and update the attributes with this method:

    private void setUserAttributes(String userId, Map<String, List<String>> attributes) {

        UserResource userResource = keycloak.realm(realm).users().get(userId);
        UserRepresentation user = userResource.toRepresentation();

        if (attributes != null && !attributes.isEmpty()) {
            user.setAttributes(attributes);
            userResource.update(user);
        }
    }

The attributes of the new user are null.

Like the user.setAttributes(attributes); and userResource.update(user); does nothing.

Why?

本文标签: javaWhy quarkuskeycloakadminclient does not add attributes to userStack Overflow