| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package org.acegisecurity.acls; |
| 16 |
|
|
| 17 |
|
import org.springframework.util.Assert; |
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
public final class AclFormattingUtils { |
| 27 |
|
|
| 28 |
|
|
| 29 |
0 |
private AclFormattingUtils() { |
| 30 |
0 |
} |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
public static String demergePatterns(String original, String removeBits) { |
| 35 |
6 |
Assert.notNull(original, "Original string required"); |
| 36 |
6 |
Assert.notNull(removeBits, "Bits To Remove string required"); |
| 37 |
6 |
Assert.isTrue(original.length() == removeBits.length(), |
| 38 |
|
"Original and Bits To Remove strings must be identical length"); |
| 39 |
|
|
| 40 |
6 |
char[] replacement = new char[original.length()]; |
| 41 |
|
|
| 42 |
198 |
for (int i = 0; i < original.length(); i++) { |
| 43 |
192 |
if (removeBits.charAt(i) == Permission.RESERVED_OFF) { |
| 44 |
186 |
replacement[i] = original.charAt(i); |
| 45 |
|
} else { |
| 46 |
6 |
replacement[i] = Permission.RESERVED_OFF; |
| 47 |
|
} |
| 48 |
|
} |
| 49 |
|
|
| 50 |
6 |
return new String(replacement); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
public static String mergePatterns(String original, String extraBits) { |
| 54 |
24 |
Assert.notNull(original, "Original string required"); |
| 55 |
24 |
Assert.notNull(extraBits, "Extra Bits string required"); |
| 56 |
24 |
Assert.isTrue(original.length() == extraBits.length(), |
| 57 |
|
"Original and Extra Bits strings must be identical length"); |
| 58 |
|
|
| 59 |
24 |
char[] replacement = new char[extraBits.length()]; |
| 60 |
|
|
| 61 |
792 |
for (int i = 0; i < extraBits.length(); i++) { |
| 62 |
768 |
if (extraBits.charAt(i) == Permission.RESERVED_OFF) { |
| 63 |
744 |
replacement[i] = original.charAt(i); |
| 64 |
|
} else { |
| 65 |
24 |
replacement[i] = extraBits.charAt(i); |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
|
|
| 69 |
24 |
return new String(replacement); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
private static String printBinary(int i, char on, char off) { |
| 73 |
38 |
String s = Integer.toString(i, 2); |
| 74 |
38 |
String pattern = Permission.THIRTY_TWO_RESERVED_OFF; |
| 75 |
38 |
String temp2 = pattern.substring(0, pattern.length() - s.length()) + s; |
| 76 |
|
|
| 77 |
38 |
return temp2.replace('0', off).replace('1', on); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
public static String printBinary(int i) { |
| 89 |
0 |
return AclFormattingUtils.printBinary(i, '*', Permission.RESERVED_OFF); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
public static String printBinary(int mask, char code) { |
| 102 |
38 |
Assert.doesNotContain(new Character(code).toString(), new Character(Permission.RESERVED_ON).toString(), |
| 103 |
|
Permission.RESERVED_ON + " is a reserved character code"); |
| 104 |
38 |
Assert.doesNotContain(new Character(code).toString(), new Character(Permission.RESERVED_OFF).toString(), |
| 105 |
|
Permission.RESERVED_OFF + " is a reserved character code"); |
| 106 |
|
|
| 107 |
38 |
return AclFormattingUtils.printBinary(mask, Permission.RESERVED_ON, Permission.RESERVED_OFF) |
| 108 |
|
.replace(Permission.RESERVED_ON, code); |
| 109 |
|
} |
| 110 |
|
} |