use of org.keycloak.storage.StorageId 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);
}
use of org.keycloak.storage.StorageId in project keycloak by keycloak.
the class JpaUserFederatedStorageProvider method joinGroup.
@Override
public void joinGroup(RealmModel realm, String userId, GroupModel group) {
createIndex(realm, userId);
FederatedUserGroupMembershipEntity entity = new FederatedUserGroupMembershipEntity();
entity.setUserId(userId);
entity.setStorageProviderId(new StorageId(userId).getProviderId());
entity.setGroupId(group.getId());
entity.setRealmId(realm.getId());
em.persist(entity);
}
use of org.keycloak.storage.StorageId in project keycloak by keycloak.
the class JpaUserFederatedStorageProvider method toConsentModel.
private UserConsentModel toConsentModel(RealmModel realm, FederatedUserConsentEntity entity) {
if (entity == null) {
return null;
}
StorageId clientStorageId = null;
if (entity.getClientId() == null) {
clientStorageId = new StorageId(entity.getClientStorageProvider(), entity.getExternalClientId());
} else {
clientStorageId = new StorageId(entity.getClientId());
}
ClientModel client = realm.getClientById(clientStorageId.getId());
UserConsentModel model = new UserConsentModel(client);
model.setCreatedDate(entity.getCreatedDate());
model.setLastUpdatedDate(entity.getLastUpdatedDate());
Collection<FederatedUserConsentClientScopeEntity> grantedClientScopeEntities = entity.getGrantedClientScopes();
if (grantedClientScopeEntities != null) {
for (FederatedUserConsentClientScopeEntity grantedClientScope : grantedClientScopeEntities) {
ClientScopeModel grantedClientScopeModel = realm.getClientScopeById(grantedClientScope.getScopeId());
if (grantedClientScopeModel == null) {
grantedClientScopeModel = realm.getClientById(grantedClientScope.getScopeId());
}
if (grantedClientScopeModel != null) {
model.addGrantedClientScope(grantedClientScopeModel);
}
}
}
return model;
}
use of org.keycloak.storage.StorageId in project keycloak by keycloak.
the class JpaUserFederatedStorageProvider method preRemove.
@Override
public void preRemove(RealmModel realm, ClientModel client) {
StorageId clientStorageId = new StorageId(client.getId());
if (clientStorageId.isLocal()) {
em.createNamedQuery("deleteFederatedUserConsentClientScopesByClient").setParameter("clientId", client.getId()).executeUpdate();
em.createNamedQuery("deleteFederatedUserConsentsByClient").setParameter("clientId", client.getId()).executeUpdate();
} else {
em.createNamedQuery("deleteFederatedUserConsentClientScopesByExternalClient").setParameter("clientStorageProvider", clientStorageId.getProviderId()).setParameter("externalClientId", clientStorageId.getExternalId()).executeUpdate();
em.createNamedQuery("deleteFederatedUserConsentsByExternalClient").setParameter("clientStorageProvider", clientStorageId.getProviderId()).setParameter("externalClientId", clientStorageId.getExternalId()).executeUpdate();
}
}
use of org.keycloak.storage.StorageId in project keycloak by keycloak.
the class JpaUserSessionPersisterProvider method getUserSessionsCount.
@Override
public int getUserSessionsCount(RealmModel realm, ClientModel clientModel, boolean offline) {
String offlineStr = offlineToString(offline);
Query query;
StorageId clientStorageId = new StorageId(clientModel.getId());
if (clientStorageId.isLocal()) {
query = em.createNamedQuery("findClientSessionsCountByClient");
query.setParameter("clientId", clientModel.getId());
} else {
query = em.createNamedQuery("findClientSessionsCountByExternalClient");
query.setParameter("clientStorageProvider", clientStorageId.getProviderId());
query.setParameter("externalClientId", clientStorageId.getExternalId());
}
// Note, that realm is unused here, since the clientModel id already determines the offline user-sessions bound to an owning realm.
query.setParameter("offline", offlineStr);
Number n = (Number) query.getSingleResult();
return n.intValue();
}
Aggregations