use of org.keycloak.models.jpa.entities.FederatedIdentityEntity in project keycloak by keycloak.
the class JpaUserProvider method getFederatedIdentitiesStream.
@Override
public Stream<FederatedIdentityModel> getFederatedIdentitiesStream(RealmModel realm, UserModel user) {
TypedQuery<FederatedIdentityEntity> query = em.createNamedQuery("findFederatedIdentityByUser", FederatedIdentityEntity.class);
UserEntity userEntity = em.getReference(UserEntity.class, user.getId());
query.setParameter("user", userEntity);
return closing(query.getResultStream().map(entity -> new FederatedIdentityModel(entity.getIdentityProvider(), entity.getUserId(), entity.getUserName(), entity.getToken())).distinct());
}
use of org.keycloak.models.jpa.entities.FederatedIdentityEntity in project keycloak by keycloak.
the class JpaUserProvider method removeFederatedIdentity.
@Override
public boolean removeFederatedIdentity(RealmModel realm, UserModel user, String identityProvider) {
FederatedIdentityEntity entity = findFederatedIdentity(user, identityProvider, LockModeType.PESSIMISTIC_WRITE);
if (entity != null) {
em.remove(entity);
em.flush();
return true;
} else {
return false;
}
}
use of org.keycloak.models.jpa.entities.FederatedIdentityEntity in project keycloak by keycloak.
the class JpaUserProvider method updateFederatedIdentity.
@Override
public void updateFederatedIdentity(RealmModel realm, UserModel federatedUser, FederatedIdentityModel federatedIdentityModel) {
FederatedIdentityEntity federatedIdentity = findFederatedIdentity(federatedUser, federatedIdentityModel.getIdentityProvider(), LockModeType.PESSIMISTIC_WRITE);
federatedIdentity.setToken(federatedIdentityModel.getToken());
em.persist(federatedIdentity);
em.flush();
}
use of org.keycloak.models.jpa.entities.FederatedIdentityEntity in project keycloak by keycloak.
the class JpaUserProvider method findFederatedIdentity.
private FederatedIdentityEntity findFederatedIdentity(UserModel user, String identityProvider, LockModeType lockMode) {
TypedQuery<FederatedIdentityEntity> query = em.createNamedQuery("findFederatedIdentityByUserAndProvider", FederatedIdentityEntity.class);
UserEntity userEntity = em.getReference(UserEntity.class, user.getId());
query.setParameter("user", userEntity);
query.setParameter("identityProvider", identityProvider);
query.setLockMode(lockMode);
List<FederatedIdentityEntity> results = query.getResultList();
return results.size() > 0 ? results.get(0) : null;
}
use of org.keycloak.models.jpa.entities.FederatedIdentityEntity in project keycloak by keycloak.
the class JpaUserProvider method addFederatedIdentity.
@Override
public void addFederatedIdentity(RealmModel realm, UserModel user, FederatedIdentityModel identity) {
FederatedIdentityEntity entity = new FederatedIdentityEntity();
entity.setRealmId(realm.getId());
entity.setIdentityProvider(identity.getIdentityProvider());
entity.setUserId(identity.getUserId());
entity.setUserName(identity.getUserName().toLowerCase());
entity.setToken(identity.getToken());
UserEntity userEntity = em.getReference(UserEntity.class, user.getId());
entity.setUser(userEntity);
em.persist(entity);
em.flush();
}
Aggregations