@Test public void testPatternMatching() throws Exception { String patternStr = "CN=abcdefgh"; String patternR = (SigningPolicyParser.getPattern(patternStr)) .pattern(); assertTrue("CN=abcdefgh".equals(patternR)); String pattern1Str = "CN=*def?gh?"; Pattern pattern1 = SigningPolicyParser.getPattern(pattern1Str); String pattern1R = pattern1.pattern(); assertTrue(("CN=" + SigningPolicyParser.WILDCARD_PATTERN + "def" + SigningPolicyParser.SINGLE_PATTERN + "gh" + SigningPolicyParser.SINGLE_PATTERN).equals(pattern1R)); String pattern2Str = "/CN=abc*def*gh"; Pattern pattern2 = SigningPolicyParser.getPattern(pattern2Str); String pattern2R = pattern2.pattern(); assertTrue( ("/CN=abc" + SigningPolicyParser.WILDCARD_PATTERN + "def" + SigningPolicyParser.WILDCARD_PATTERN + "gh").equals( pattern2R)); Vector<Pattern> allowed = new Vector(); allowed.add(pattern2); X500Principal fooPrincipal = new X500Principal("CN=foo"); SigningPolicy policy = new SigningPolicy(fooPrincipal, allowed); X500Principal subject21 = new X500Principal("CN=abc12DEF34defdef56gh"); assertTrue(policy.isValidSubject(subject21)); X500Principal subject22 = new X500Principal("CN=123abc12def34defdef56gh"); assertFalse(policy.isValidSubject(subject22)); X500Principal subject23 = new X500Principal("CN=abc12def34defdef56gh123"); assertFalse(policy.isValidSubject(subject23)); String pattern3Str = "*abc*def*gh*"; Pattern pattern3 = SigningPolicyParser.getPattern(pattern3Str); allowed.clear(); allowed.add(pattern3); policy = new SigningPolicy(fooPrincipal, allowed); X500Principal subject31 = new X500Principal("CN=ABC12def34defdef56gh"); assertTrue(policy.isValidSubject(subject31)); X500Principal subject32 = new X500Principal("CN=123abc12def34defdef56gh555"); assertTrue(policy.isValidSubject(subject32)); String pattern4Str = "/C=US/O=GlobusCN=user-??"; Pattern pattern6 = SigningPolicyParser.getPattern(pattern6Str); allowed.clear(); allowed.add(pattern6); policy = new SigningPolicy(fooPrincipal, allowed); X500Principal subject61 = new X500Principal("CN=user-12,CN=foo,O=Globus,C=US"); assertFalse(policy.isValidSubject(subject61)); X500Principal subject62 = new X500Principal("CN=user-12,CN=foo,O=Global,C=US"); assertTrue(policy.isValidSubject(subject62)); X500Principal subject63 = new X500Principal("CN=user-12,CN=bar 1,CN=foo ,O=global,C=US"); assertTrue(policy.isValidSubject(subject63)); String pattern7Str = "/C=US/O=Globus/CN=*/CN=user-??"; Pattern pattern7 = SigningPolicyParser.getPattern(pattern7Str); allowed.add(pattern7); policy = new SigningPolicy(fooPrincipal, allowed); X500Principal subject71 = new X500Principal("CN=user-12, CN=bar 1, CN=foo , O=Globus,C=US"); assertTrue(policy.isValidSubject(subject71)); assertTrue(policy.isValidSubject(subject63)); }
public static Pattern getPattern(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException(); } int startIndex = 0; int endIndex = patternStr.length(); StringBuffer buffer = new StringBuffer(""); while (startIndex < endIndex) { int star = patternStr.indexOf(WILDCARD, startIndex); if (star == -1) { star = endIndex; String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr); } else { String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr).append(WILDCARD_PATTERN); } startIndex = star + 1; } String tmpPatternStr = buffer.toString(); startIndex = 0; endIndex = tmpPatternStr.length(); buffer = new StringBuffer(""); while (startIndex < endIndex) { int qMark = tmpPatternStr.indexOf(SINGLE_CHAR, startIndex); if (qMark == -1) { qMark = endIndex; String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr); } else { String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr).append(SINGLE_PATTERN); } startIndex = qMark + 1; } tmpPatternStr = buffer.toString(); LogFactory.getLog(SigningPolicyParser.class.getCanonicalName()).debug("String with replaced pattern is " + tmpPatternStr); return Pattern.compile(tmpPatternStr, Pattern.CASE_INSENSITIVE); }
SigningPolicyParser { public static Pattern getPattern(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException(); } int startIndex = 0; int endIndex = patternStr.length(); StringBuffer buffer = new StringBuffer(""); while (startIndex < endIndex) { int star = patternStr.indexOf(WILDCARD, startIndex); if (star == -1) { star = endIndex; String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr); } else { String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr).append(WILDCARD_PATTERN); } startIndex = star + 1; } String tmpPatternStr = buffer.toString(); startIndex = 0; endIndex = tmpPatternStr.length(); buffer = new StringBuffer(""); while (startIndex < endIndex) { int qMark = tmpPatternStr.indexOf(SINGLE_CHAR, startIndex); if (qMark == -1) { qMark = endIndex; String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr); } else { String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr).append(SINGLE_PATTERN); } startIndex = qMark + 1; } tmpPatternStr = buffer.toString(); LogFactory.getLog(SigningPolicyParser.class.getCanonicalName()).debug("String with replaced pattern is " + tmpPatternStr); return Pattern.compile(tmpPatternStr, Pattern.CASE_INSENSITIVE); } }
SigningPolicyParser { public static Pattern getPattern(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException(); } int startIndex = 0; int endIndex = patternStr.length(); StringBuffer buffer = new StringBuffer(""); while (startIndex < endIndex) { int star = patternStr.indexOf(WILDCARD, startIndex); if (star == -1) { star = endIndex; String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr); } else { String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr).append(WILDCARD_PATTERN); } startIndex = star + 1; } String tmpPatternStr = buffer.toString(); startIndex = 0; endIndex = tmpPatternStr.length(); buffer = new StringBuffer(""); while (startIndex < endIndex) { int qMark = tmpPatternStr.indexOf(SINGLE_CHAR, startIndex); if (qMark == -1) { qMark = endIndex; String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr); } else { String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr).append(SINGLE_PATTERN); } startIndex = qMark + 1; } tmpPatternStr = buffer.toString(); LogFactory.getLog(SigningPolicyParser.class.getCanonicalName()).debug("String with replaced pattern is " + tmpPatternStr); return Pattern.compile(tmpPatternStr, Pattern.CASE_INSENSITIVE); }  }
SigningPolicyParser { public static Pattern getPattern(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException(); } int startIndex = 0; int endIndex = patternStr.length(); StringBuffer buffer = new StringBuffer(""); while (startIndex < endIndex) { int star = patternStr.indexOf(WILDCARD, startIndex); if (star == -1) { star = endIndex; String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr); } else { String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr).append(WILDCARD_PATTERN); } startIndex = star + 1; } String tmpPatternStr = buffer.toString(); startIndex = 0; endIndex = tmpPatternStr.length(); buffer = new StringBuffer(""); while (startIndex < endIndex) { int qMark = tmpPatternStr.indexOf(SINGLE_CHAR, startIndex); if (qMark == -1) { qMark = endIndex; String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr); } else { String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr).append(SINGLE_PATTERN); } startIndex = qMark + 1; } tmpPatternStr = buffer.toString(); LogFactory.getLog(SigningPolicyParser.class.getCanonicalName()).debug("String with replaced pattern is " + tmpPatternStr); return Pattern.compile(tmpPatternStr, Pattern.CASE_INSENSITIVE); }  Map<X500Principal, SigningPolicy> parse(String fileName); Map<X500Principal, SigningPolicy> parse(Reader reader); static Pattern getPattern(String patternStr); }
SigningPolicyParser { public static Pattern getPattern(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException(); } int startIndex = 0; int endIndex = patternStr.length(); StringBuffer buffer = new StringBuffer(""); while (startIndex < endIndex) { int star = patternStr.indexOf(WILDCARD, startIndex); if (star == -1) { star = endIndex; String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr); } else { String preStr = patternStr.substring(startIndex, star); buffer = buffer.append(preStr).append(WILDCARD_PATTERN); } startIndex = star + 1; } String tmpPatternStr = buffer.toString(); startIndex = 0; endIndex = tmpPatternStr.length(); buffer = new StringBuffer(""); while (startIndex < endIndex) { int qMark = tmpPatternStr.indexOf(SINGLE_CHAR, startIndex); if (qMark == -1) { qMark = endIndex; String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr); } else { String preStr = tmpPatternStr.substring(startIndex, qMark); buffer = buffer.append(preStr).append(SINGLE_PATTERN); } startIndex = qMark + 1; } tmpPatternStr = buffer.toString(); LogFactory.getLog(SigningPolicyParser.class.getCanonicalName()).debug("String with replaced pattern is " + tmpPatternStr); return Pattern.compile(tmpPatternStr, Pattern.CASE_INSENSITIVE); }  Map<X500Principal, SigningPolicy> parse(String fileName); Map<X500Principal, SigningPolicy> parse(Reader reader); static Pattern getPattern(String patternStr); static final String ACCESS_ID_PREFIX; static final String ACCESS_ID_CA; static final String DEF_AUTH_X509; static final String DEF_AUTH_GLOBUS; static final String POS_RIGHTS; static final String NEG_RIGHTS; static final String CONDITION_PREFIX; static final String CONDITION_SUBJECT; static final String VALUE_CA_SIGN; static final String SINGLE_CHAR; static final String WILDCARD; static final String SINGLE_PATTERN; static final String WILDCARD_PATTERN; }