Search in sources :

Example 1 with FederatedUserAttributeEntity

use of org.keycloak.storage.jpa.entity.FederatedUserAttributeEntity in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method persistAttributeValue.

private void persistAttributeValue(RealmModel realm, String userId, String name, String value) {
    FederatedUserAttributeEntity attr = new FederatedUserAttributeEntity();
    attr.setId(KeycloakModelUtils.generateId());
    attr.setName(name);
    attr.setValue(value);
    attr.setUserId(userId);
    attr.setRealmId(realm.getId());
    attr.setStorageProviderId(new StorageId(userId).getProviderId());
    em.persist(attr);
}
Also used : FederatedUserAttributeEntity(org.keycloak.storage.jpa.entity.FederatedUserAttributeEntity) StorageId(org.keycloak.storage.StorageId)

Example 2 with FederatedUserAttributeEntity

use of org.keycloak.storage.jpa.entity.FederatedUserAttributeEntity in project keycloak by keycloak.

the class JpaUserFederatedStorageProvider method getAttributes.

@Override
public MultivaluedHashMap<String, String> getAttributes(RealmModel realm, String userId) {
    TypedQuery<FederatedUserAttributeEntity> query = em.createNamedQuery("getFederatedAttributesByUser", FederatedUserAttributeEntity.class);
    List<FederatedUserAttributeEntity> list = query.setParameter("userId", userId).setParameter("realmId", realm.getId()).getResultList();
    MultivaluedHashMap<String, String> result = new MultivaluedHashMap<>();
    for (FederatedUserAttributeEntity entity : list) {
        result.add(entity.getName(), entity.getValue());
    }
    return result;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) FederatedUserAttributeEntity(org.keycloak.storage.jpa.entity.FederatedUserAttributeEntity)

Aggregations

FederatedUserAttributeEntity (org.keycloak.storage.jpa.entity.FederatedUserAttributeEntity)2 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)1 StorageId (org.keycloak.storage.StorageId)1