コード例 #1
0
ファイル: UserAdapter.java プロジェクト: hh201020/keycloak
 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());
 }
コード例 #2
0
ファイル: AccountService.java プロジェクト: rishiHPE/keycloak
  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;
  }
コード例 #3
0
 @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;
 }
コード例 #4
0
ファイル: UserAdapter.java プロジェクト: niuhw/keycloak
  @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());
  }
コード例 #5
0
ファイル: UserAdapter.java プロジェクト: niuhw/keycloak
  @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;
  }
コード例 #6
0
ファイル: UserAdapter.java プロジェクト: hh201020/keycloak
  @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();
  }