Code example for X509Certificate

Methods: getSubjectX500Principal

     * @return true if the subject DN common name matches the set of trusted names, false otherwise 
    protected boolean processSubjectDNCommonName(X509Certificate certificate, Set<String> trustedNames) {
        log.debug("Processing subject DN common name");
        X500Principal subjectPrincipal = certificate.getSubjectX500Principal();
        List<String> commonNames = X509Util.getCommonNames(subjectPrincipal);
        if (commonNames == null || commonNames.isEmpty()) {
            return false; 
        // TODO We only check the first one returned by X509Util. Maybe we should check all, 
        // if there are multiple CN AVA's from the same (first) RDN. 
        String commonName = commonNames.get(0);
        log.debug("Extracted common name from certificate: {}", commonName);
        if (DatatypeHelper.isEmpty(commonName)) {
            return false; 
        if (trustedNames.contains(commonName)) {
            log.debug("Matched subject DN common name to trusted names: {}", commonName);