Beispiel #1
0
 private void setValue(CredentialEntity credentialEntity, UserCredentialModel cred) {
   UserCredentialValueModel encoded = PasswordHashManager.encode(session, realm, cred.getValue());
   credentialEntity.setCreatedDate(Time.toMillis(Time.currentTime()));
   credentialEntity.setAlgorithm(encoded.getAlgorithm());
   credentialEntity.setValue(encoded.getValue());
   credentialEntity.setSalt(encoded.getSalt());
   credentialEntity.setHashIterations(encoded.getHashIterations());
 }
Beispiel #2
0
  public static boolean isPasswordSet(UserModel user) {
    boolean passwordSet = false;

    if (user.getFederationLink() != null) {
      passwordSet = true;
    }

    for (UserCredentialValueModel c : user.getCredentialsDirectly()) {
      if (c.getType().equals(CredentialRepresentation.PASSWORD)) {
        passwordSet = true;
      }
    }
    return passwordSet;
  }
 @Override
 public Set<String> getSupportedCredentialTypes(UserModel local) {
   Set<String> supportedCredentialTypes = new HashSet<String>(this.supportedCredentialTypes);
   if (editMode == EditMode.UNSYNCED) {
     for (UserCredentialValueModel cred : local.getCredentialsDirectly()) {
       if (cred.getType().equals(UserCredentialModel.PASSWORD)) {
         // User has changed password in KC local database. Use KC password instead of LDAP
         // password
         supportedCredentialTypes.remove(UserCredentialModel.PASSWORD);
       }
     }
   }
   return supportedCredentialTypes;
 }
Beispiel #4
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());
  }
Beispiel #5
0
  @Override
  public List<UserCredentialValueModel> getCredentialsDirectly() {
    List<CredentialEntity> credentials = new ArrayList<CredentialEntity>(user.getCredentials());
    List<UserCredentialValueModel> result = new ArrayList<UserCredentialValueModel>();

    for (CredentialEntity credEntity : credentials) {
      UserCredentialValueModel credModel = new UserCredentialValueModel();
      credModel.setType(credEntity.getType());
      credModel.setDevice(credEntity.getDevice());
      credModel.setCreatedDate(credEntity.getCreatedDate());
      credModel.setValue(credEntity.getValue());
      credModel.setSalt(credEntity.getSalt());
      credModel.setHashIterations(credEntity.getHashIterations());

      result.add(credModel);
    }

    return result;
  }
Beispiel #6
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.setCreatedDate(credModel.getCreatedDate());
      credentialEntity.setUser(user);
      em.persist(credentialEntity);
      user.getCredentials().add(credentialEntity);
    }

    credentialEntity.setValue(credModel.getValue());
    credentialEntity.setSalt(credModel.getSalt());
    credentialEntity.setDevice(credModel.getDevice());
    credentialEntity.setHashIterations(credModel.getHashIterations());
    credentialEntity.setCounter(credModel.getCounter());
    credentialEntity.setAlgorithm(credModel.getAlgorithm());
    credentialEntity.setDigits(credModel.getDigits());
    credentialEntity.setPeriod(credModel.getPeriod());

    em.flush();
  }