Beispiel #1
0
 private void setValue(CredentialEntity credentialEntity, UserCredentialModel cred) {
   byte[] salt = getSalt();
   int hashIterations = 1;
   PasswordPolicy policy = realm.getPasswordPolicy();
   if (policy != null) {
     hashIterations = policy.getHashIterations();
     if (hashIterations == -1) hashIterations = 1;
   }
   credentialEntity.setCreatedDate(Time.toMillis(Time.currentTime()));
   credentialEntity.setValue(
       new Pbkdf2PasswordEncoder(salt).encode(cred.getValue(), hashIterations));
   credentialEntity.setSalt(salt);
   credentialEntity.setHashIterations(hashIterations);
 }
Beispiel #2
0
  @Override
  public void updateCredentialDirectly(UserCredentialValueModel credModel) {
    CredentialEntity credentialEntity = getCredentialEntity(user, credModel.getType());

    if (credentialEntity == null) {
      credentialEntity = new CredentialEntity();
      //    credentialEntity.setId(KeycloakModelUtils.generateId());
      credentialEntity.setType(credModel.getType());
      //    credentialEntity.setUser(user);
      credModel.setCreatedDate(credModel.getCreatedDate());
      user.getCredentials().add(credentialEntity);
    }

    credentialEntity.setValue(credModel.getValue());
    credentialEntity.setSalt(credModel.getSalt());
    credentialEntity.setDevice(credModel.getDevice());
    credentialEntity.setHashIterations(credModel.getHashIterations());
  }