コード例 #1
0
  /** {@inheritDoc} */
  @Override
  public void contentHasChanged(boolean empty, String text) {
    if (labelHandler != null) {
      labelHandler.handleLabelStateFor(this, empty);
    }

    // check or unceheck sn / ski checkboxes
    final ServiceDigitalIdentityMultivalueAdapter serviceDigitalIdentityMultivalueAdapter =
        (ServiceDigitalIdentityMultivalueAdapter)
            certificateButton.getMultivaluePanel().getMultivalueModel();
    final List<DigitalIdentityType> digitalId =
        serviceDigitalIdentityMultivalueAdapter.getDigitalIdentityList().getDigitalId();

    boolean hasSn = false;
    boolean hasSki = false;

    for (Iterator<DigitalIdentityType> iterator = digitalId.iterator(); iterator.hasNext(); ) {
      DigitalIdentityType digitalIdentityType = iterator.next();
      if (digitalIdentityType.getX509SubjectName() != null) {
        hasSn = true;
      }
      if (digitalIdentityType.getX509SKI() != null) {
        hasSki = true;
      }
    }

    boxSN.setSelected(hasSn);
    boxSKI.setSelected(hasSki);

    alignSnSki();
  }
コード例 #2
0
  private void alignSnSki() {
    final ServiceDigitalIdentityMultivalueAdapter serviceDigitalIdentityMultivalueAdapter =
        (ServiceDigitalIdentityMultivalueAdapter)
            certificateButton.getMultivaluePanel().getMultivalueModel();
    final List<DigitalIdentityType> digitalId =
        serviceDigitalIdentityMultivalueAdapter.getDigitalIdentityList().getDigitalId();

    boolean useSn = boxSN.isSelected();
    boolean useSki = boxSKI.isSelected();
    serviceDigitalIdentityMultivalueAdapter.setSn(useSn);
    serviceDigitalIdentityMultivalueAdapter.setSki(useSki);

    boolean snAdded = false;
    boolean skiAdded = false;

    // cleanup existing SN & SKI (might not be aligned with the certificates chosen
    for (Iterator<DigitalIdentityType> iterator = digitalId.iterator(); iterator.hasNext(); ) {
      DigitalIdentityType digitalIdentityType = iterator.next();
      if (digitalIdentityType.getX509SubjectName() != null) {
        iterator.remove();
      }
      if (digitalIdentityType.getX509SKI() != null) {
        iterator.remove();
      }
    }

    // cleanup SubjetName display
    distinguishedName.setText("");
    distinguishedName.setCaretPosition(0);

    // search new values
    for (final String key : serviceDigitalIdentityMultivalueAdapter.getKeys()) {
      final DigitalIdentityModel digitalIdentityModel =
          serviceDigitalIdentityMultivalueAdapter.getValue(key);
      if (digitalIdentityModel != null) {
        final X509Certificate certificate = digitalIdentityModel.getCertificate();
        if (certificate != null) {

          final DigitalIdentityType digitalIdentitySN = new DigitalIdentityType();
          final String x509SubjectName =
              certificate.getSubjectX500Principal().getName(X500Principal.RFC2253);
          digitalIdentitySN.setX509SubjectName(x509SubjectName);

          // updateUI too
          // TODO: might be interesting to display all different subjectName (with error message) if
          // use has chosen different certificitates
          distinguishedName.setText(x509SubjectName);
          distinguishedName.setCaretPosition(0);

          if (!snAdded && useSn) {
            digitalId.add(digitalIdentitySN);
            snAdded = true;
          }
          if (!skiAdded && useSki) {
            final byte[] skiValue = DSSUtils.getSki(certificate);
            if (skiValue != null && skiValue.length > 0) {
              final DigitalIdentityType digitalIdentitySKI = new DigitalIdentityType();
              digitalIdentitySKI.setX509SKI(skiValue);
              digitalId.add(digitalIdentitySKI);
              skiAdded = true;
            }
          }
        }
      }
    }
  }