Exemplo n.º 1
0
  @Override
  public void updateCredential(UserCredentialModel cred) {

    if (cred.getType().equals(UserCredentialModel.PASSWORD)) {
      updatePasswordCredential(cred);
    } else {
      CredentialEntity credentialEntity = getCredentialEntity(user, cred.getType());

      if (credentialEntity == null) {
        credentialEntity = setCredentials(user, cred);
        credentialEntity.setValue(cred.getValue());
        user.getCredentials().add(credentialEntity);
      } else {
        credentialEntity.setValue(cred.getValue());
      }
    }
  }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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());
  }