~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/authentication/src/main/java/com/eucalyptus/auth/policy/PatternUtils.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.auth.policy;
 
2
 
 
3
import java.util.regex.Pattern;
 
4
 
 
5
public class PatternUtils {
 
6
 
 
7
  private static final Pattern ESCAPE_PATTERN = Pattern.compile( "([^a-zA-z0-9*?])" );
 
8
  private static final Pattern WILDCARD_MULTIPLE_PATTERN = Pattern.compile( "([*])" );
 
9
  private static final Pattern WILDCARD_SINGLE_PATTERN = Pattern.compile( "([?])" );
 
10
  
 
11
  /**
 
12
   * Convert an IAM policy pattern (action pattern or resource pattern with * and ?)
 
13
   * to a canonical Java regex Pattern.
 
14
   * 
 
15
   * @param policyPattern
 
16
   * @return
 
17
   */
 
18
  public static String toJavaPattern( String pattern ) {
 
19
    String result = pattern;
 
20
    
 
21
    if ( pattern == null ) {
 
22
      return null;
 
23
    }
 
24
    result = ESCAPE_PATTERN.matcher( result ).replaceAll( "\\\\$1" );
 
25
    result = WILDCARD_SINGLE_PATTERN.matcher( result ).replaceAll( "." );
 
26
    result = WILDCARD_MULTIPLE_PATTERN.matcher( result ).replaceAll( ".*" );
 
27
    
 
28
    return result;
 
29
  }
 
30
 
 
31
}