java 模式匹配

1、参加源码SubjectDnX509PrincipalExtractor

 

private Pattern subjectDnPattern;

 

    public Object extractPrincipal(X509Certificate clientCert) {
           String subjectDN = clientCert.getSubjectDN().getName();

             Matcher matcher = subjectDnPattern.matcher(subjectDN);

        if (!matcher.find()) {
            throw new BadCredentialsException(messages.getMessage("SubjectDnX509PrincipalExtractor.noMatching",
                    new Object[] {subjectDN}, "No matching pattern was found in subject DN: {0}"));
        }

        if (matcher.groupCount() != 1) {
            throw new IllegalArgumentException("Regular expression must contain a single group ");
        }

        String username = matcher.group(1);

        logger.debug("Extracted Principal name is '" + username + "'");

        return username;
    }

 

 

   public void setSubjectDnRegex(String subjectDnRegex) {
               subjectDnPattern = Pattern.compile(subjectDnRegex, Pattern.CASE_INSENSITIVE);
    }

你可能感兴趣的:(java 模式匹配)