Example usage for java.security.cert X509Certificate getSubjectX500Principal

List of usage examples for java.security.cert X509Certificate getSubjectX500Principal

Introduction

In this page you can find the example usage for java.security.cert X509Certificate getSubjectX500Principal.

Prototype

public X500Principal getSubjectX500Principal() 

Source Link

Document

Returns the subject (subject distinguished name) value from the certificate as an X500Principal .

Usage

From source file:de.zib.gndms.gndms.security.FullDNExtractor.java

@Override
public Object extractPrincipal(final X509Certificate x509Certificate) {

    return X509DnConverter.toOpenSslDn(x509Certificate.getSubjectX500Principal().getName());
}

From source file:org.apigw.authserver.x509.ClientX509PrincipalExtractor.java

@Override
public X509ClientPrincipal extractPrincipal(X509Certificate cert) {

    String subjectDN = cert.getSubjectX500Principal().getName(X500Principal.RFC1779);
    String issuerDN = cert.getIssuerX500Principal().getName(X500Principal.RFC1779);

    X509ClientPrincipal x509ClientPrincipal = new X509ClientPrincipal(subjectDN, issuerDN);
    log.trace("created principal: {}", x509ClientPrincipal);

    return x509ClientPrincipal;

}

From source file:be.fedict.trust.constraints.DistinguishedNameCertificateConstraint.java

public boolean check(X509Certificate certificate) {
    X500Principal certificateSubject = certificate.getSubjectX500Principal();
    LOG.debug("accepted subject: " + this.acceptedSubject);
    return this.acceptedSubject.equals(certificateSubject);
}

From source file:org.opensaml.xml.security.x509.tls.StrictHostnameVerifier.java

/** {@inheritDoc} */
public void check(String[] host, X509Certificate cert) throws SSLException {
    String[] cns = X509Util.getCommonNames(cert.getSubjectX500Principal()).toArray(new String[0]);
    String[] subjectAlts = Certificates.getDNSSubjectAlts(cert);
    //Note: could use X509Util for subject alt names also, per below.
    //List<String> subjectAltsList = X509Util.getAltNames(cert, new Integer[]{X509Util.DNS_ALT_NAME});
    //String[] subjectAlts = subjectAltsList.toArray(new String[0]);
    check(host, cns, subjectAlts);//from  w ww. ja v a 2  s. com
}

From source file:test.unit.be.fedict.eid.applet.service.signer.XPSSignatureVerifierTest.java

@Test
public void testSignedXPS() throws Exception {
    URL documentUrl = XPSSignatureVerifierTest.class.getResource("/hello-world-signed.xps");
    assertNotNull(documentUrl);/*from  w  ww. jav a  2s  . c  o m*/

    // operate
    XPSSignatureVerifier verifier = new XPSSignatureVerifier();
    List<X509Certificate> result = verifier.getSigners(documentUrl);

    // verify
    assertNotNull(result);
    assertEquals(1, result.size());
    X509Certificate signer = result.get(0);
    LOG.debug("signer: " + signer.getSubjectX500Principal());
    assertTrue(signer.getSubjectX500Principal().toString().contains("Frank Cornelis (Signature"));
}

From source file:org.italiangrid.storm.webdav.authz.VOMSAuthenticationFilter.java

protected String extractCN(X509Certificate cert) {

    String[] cns = X500NameUtils.getAttributeValues(cert.getSubjectX500Principal(), CN_OID);

    for (String cn : cns) {

        if (cn.equals("proxy") || cn.matches("\\d+")) {
            logger.debug("Skipping CN={}", cn);
            continue;
        }//from  ww w.ja v  a 2 s  .  c o  m

        return cn;
    }

    return null;
}

From source file:be.fedict.eid.dss.model.bean.SignerCertificateSignatureFacet.java

public void postSign(Element signatureElement, List<X509Certificate> signingCertificateChain) {
    HttpSession httpSession = HttpSessionTemporaryDataStorage.getHttpSession();
    DocumentRepository documentRepository = new DocumentRepository(httpSession);
    X509Certificate signerCertificate = signingCertificateChain.get(0);
    LOG.debug("signer certificate: " + signerCertificate.getSubjectX500Principal());
    documentRepository.setSignerCertificate(signerCertificate);
}

From source file:hu.fnf.devel.wishbox.gateway.GatewayREST.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/persistence/user/{userId}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String createUser(@PathVariable("userId") String userId, HttpServletRequest request) {
    StringBuilder content = new StringBuilder();
    StringBuilder stringBuilder = new StringBuilder();
    X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
    for (X509Certificate cert : certs) {
        stringBuilder.append(cert.getSubjectX500Principal().getName());
    }/*from   w  ww .j  a  v  a2 s  . c  om*/
    try {
        while (request.getReader().ready()) {
            content.append(request.getReader().readLine());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return userId + ": " + content + ": " + stringBuilder;
}

From source file:test.be.fedict.eid.applet.MSCAPITest.java

@Test
public void testMSCAPI() throws Exception {
    KeyStore keyStore = KeyStore.getInstance("Windows-MY");
    keyStore.load(null, null);/*from  w  w  w . j  a  va2  s  . co  m*/
    Enumeration<String> aliases = keyStore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        LOG.debug("alias: " + alias);
        X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias);
        LOG.debug("certificate subject: " + certificate.getSubjectX500Principal());
    }
}

From source file:be.fedict.eid.applet.beta.admin.AdministratorServiceBean.java

private String getUserId(X509Certificate adminCert) {
    X500Principal userPrincipal = adminCert.getSubjectX500Principal();
    String name = userPrincipal.toString();
    int serialNumberValueBeginIdx = name.indexOf("SERIALNUMBER=") + "SERIALNUMBER=".length();
    int serialNumberValueEndIdx = name.indexOf(",", serialNumberValueBeginIdx);
    if (-1 == serialNumberValueEndIdx) {
        serialNumberValueEndIdx = name.length();
    }/*from   w w  w.  jav  a  2s  . c  om*/
    String userId = name.substring(serialNumberValueBeginIdx, serialNumberValueEndIdx);
    return userId;
}