use of org.keycloak.models.jpa.entities.CredentialEntity in project keycloak by keycloak.
the class JpaUserCredentialStore method getStoredCredentialById.
@Override
public CredentialModel getStoredCredentialById(RealmModel realm, UserModel user, String id) {
CredentialEntity entity = em.find(CredentialEntity.class, id);
if (!checkCredentialEntity(entity, user))
return null;
CredentialModel model = toModel(entity);
return model;
}
use of org.keycloak.models.jpa.entities.CredentialEntity in project keycloak by keycloak.
the class JpaUserCredentialStore method removeCredentialEntity.
CredentialEntity removeCredentialEntity(RealmModel realm, UserModel user, String id) {
CredentialEntity entity = em.find(CredentialEntity.class, id, LockModeType.PESSIMISTIC_WRITE);
if (!checkCredentialEntity(entity, user))
return null;
int currentPriority = entity.getPriority();
this.getStoredCredentialEntities(realm, user).forEach(cred -> {
if (cred.getPriority() > currentPriority) {
cred.setPriority(cred.getPriority() - PRIORITY_DIFFERENCE);
}
});
em.remove(entity);
em.flush();
return entity;
}
use of org.keycloak.models.jpa.entities.CredentialEntity in project keycloak by keycloak.
the class JpaUserCredentialStore method createCredentialEntity.
CredentialEntity createCredentialEntity(RealmModel realm, UserModel user, CredentialModel cred) {
CredentialEntity entity = new CredentialEntity();
String id = cred.getId() == null ? KeycloakModelUtils.generateId() : cred.getId();
entity.setId(id);
entity.setCreatedDate(cred.getCreatedDate());
entity.setUserLabel(cred.getUserLabel());
entity.setType(cred.getType());
entity.setSecretData(cred.getSecretData());
entity.setCredentialData(cred.getCredentialData());
UserEntity userRef = em.getReference(UserEntity.class, user.getId());
entity.setUser(userRef);
// add in linkedlist to last position
List<CredentialEntity> credentials = getStoredCredentialEntities(realm, user).collect(Collectors.toList());
int priority = credentials.isEmpty() ? PRIORITY_DIFFERENCE : credentials.get(credentials.size() - 1).getPriority() + PRIORITY_DIFFERENCE;
entity.setPriority(priority);
em.persist(entity);
return entity;
}
Aggregations