1478 + "in the grant clause. "
1479 + "SELF-based target names are "
1480 + "only valid in the context "
1481 + "of a Principal-based grant entry."
1482 );
1483 }
1484 return;
1485 }
1486 int startIndex = 0;
1487 int v;
1488 StringBuilder sb = new StringBuilder();
1489 while ((v = sp.getSelfName().indexOf(SELF, startIndex)) != -1) {
1490
1491 // add non-SELF string
1492 sb.append(sp.getSelfName().substring(startIndex, v));
1493
1494 // expand SELF
1495 Iterator<PolicyParser.PrincipalEntry> pli = entryPs.iterator();
1496 while (pli.hasNext()) {
1497 PolicyParser.PrincipalEntry pppe = pli.next();
1498 String[][] principalInfo = getPrincipalInfo(pppe,pdp);
1499 for (int i = 0; i < principalInfo.length; i++) {
1500 if (i != 0) {
1501 sb.append(", ");
1502 }
1503 sb.append(principalInfo[i][0] + " " +
1504 "\"" + principalInfo[i][1] + "\"");
1505 }
1506 if (pli.hasNext()) {
1507 sb.append(", ");
1508 }
1509 }
1510 startIndex = v + SELF.length();
1511 }
1512 // add remaining string (might be the entire string)
1513 sb.append(sp.getSelfName().substring(startIndex));
1514
1515 if (debug != null) {
1516 debug.println(" expanded:\n\t" + sp.getSelfName()
1517 + "\n into:\n\t" + sb.toString());
1518 }
1519 try {
1520 // first try to instantiate the permission
1521 perms.add(getInstance(sp.getSelfType(),
1522 sb.toString(),
1523 sp.getSelfActions()));
1524 } catch (ClassNotFoundException cnfe) {
1757 }
1758 return canonCs;
1759 }
1760
1761 // Wrapper to return a canonical path that avoids calling getCanonicalPath()
1762 // with paths that are intended to match all entries in the directory
1763 private static String canonPath(String path) throws IOException {
1764 if (path.endsWith("*")) {
1765 path = path.substring(0, path.length()-1) + "-";
1766 path = new File(path).getCanonicalPath();
1767 return path.substring(0, path.length()-1) + "*";
1768 } else {
1769 return new File(path).getCanonicalPath();
1770 }
1771 }
1772
1773 private String printPD(ProtectionDomain pd) {
1774 Principal[] principals = pd.getPrincipals();
1775 String pals = "<no principals>";
1776 if (principals != null && principals.length > 0) {
1777 StringBuilder palBuf = new StringBuilder("(principals ");
1778 for (int i = 0; i < principals.length; i++) {
1779 palBuf.append(principals[i].getClass().getName() +
1780 " \"" + principals[i].getName() +
1781 "\"");
1782 if (i < principals.length-1)
1783 palBuf.append(", ");
1784 else
1785 palBuf.append(")");
1786 }
1787 pals = palBuf.toString();
1788 }
1789 return "PD CodeSource: "
1790 + pd.getCodeSource()
1791 +"\n\t" + "PD ClassLoader: "
1792 + pd.getClassLoader()
1793 +"\n\t" + "PD Principals: "
1794 + pals;
1795 }
1796
1797 /**
1798 * return true if no replacement was performed,
1799 * or if replacement succeeded.
1800 */
1801 private boolean replacePrincipals(
1802 List<PolicyParser.PrincipalEntry> principals, KeyStore keystore) {
1803
1804 if (principals == null || principals.isEmpty() || keystore == null)
1805 return true;
1806
1807 for (PolicyParser.PrincipalEntry pppe : principals) {
1867 startIndex = e+2;
1868 continue;
1869 } else if (prefix.equalsIgnoreCase("alias")) {
1870 // get the suffix and perform keystore alias replacement
1871 if (colonIndex == -1) {
1872 MessageFormat form = new MessageFormat
1873 (ResourcesMgr.getString
1874 ("alias.name.not.provided.pe.name."));
1875 Object[] source = {pe.name};
1876 throw new Exception(form.format(source));
1877 }
1878 suffix = value.substring(colonIndex+1);
1879 if ((suffix = getDN(suffix, keystore)) == null) {
1880 MessageFormat form = new MessageFormat
1881 (ResourcesMgr.getString
1882 ("unable.to.perform.substitution.on.alias.suffix"));
1883 Object[] source = {value.substring(colonIndex+1)};
1884 throw new Exception(form.format(source));
1885 }
1886
1887 sb.append(X500PRINCIPAL + " \"" + suffix + "\"");
1888 startIndex = e+2;
1889 } else {
1890 MessageFormat form = new MessageFormat
1891 (ResourcesMgr.getString
1892 ("substitution.value.prefix.unsupported"));
1893 Object[] source = {prefix};
1894 throw new Exception(form.format(source));
1895 }
1896 }
1897
1898 // copy the rest of the value
1899 sb.append(pe.name.substring(startIndex));
1900
1901 // replace the name with expanded value
1902 if (debug != null) {
1903 debug.println(" Permission name expanded from:\n\t" +
1904 pe.name + "\nto\n\t" + sb.toString());
1905 }
1906 pe.name = sb.toString();
1907 }
|
1478 + "in the grant clause. "
1479 + "SELF-based target names are "
1480 + "only valid in the context "
1481 + "of a Principal-based grant entry."
1482 );
1483 }
1484 return;
1485 }
1486 int startIndex = 0;
1487 int v;
1488 StringBuilder sb = new StringBuilder();
1489 while ((v = sp.getSelfName().indexOf(SELF, startIndex)) != -1) {
1490
1491 // add non-SELF string
1492 sb.append(sp.getSelfName().substring(startIndex, v));
1493
1494 // expand SELF
1495 Iterator<PolicyParser.PrincipalEntry> pli = entryPs.iterator();
1496 while (pli.hasNext()) {
1497 PolicyParser.PrincipalEntry pppe = pli.next();
1498 String[][] principalInfo = getPrincipalInfo(pppe, pdp);
1499 for (int i = 0; i < principalInfo.length; i++) {
1500 if (i != 0) {
1501 sb.append(", ");
1502 }
1503 sb.append(principalInfo[i][0]).append(' ').append('"')
1504 .append(principalInfo[i][1]).append('"');
1505 }
1506 if (pli.hasNext()) {
1507 sb.append(", ");
1508 }
1509 }
1510 startIndex = v + SELF.length();
1511 }
1512 // add remaining string (might be the entire string)
1513 sb.append(sp.getSelfName().substring(startIndex));
1514
1515 if (debug != null) {
1516 debug.println(" expanded:\n\t" + sp.getSelfName()
1517 + "\n into:\n\t" + sb.toString());
1518 }
1519 try {
1520 // first try to instantiate the permission
1521 perms.add(getInstance(sp.getSelfType(),
1522 sb.toString(),
1523 sp.getSelfActions()));
1524 } catch (ClassNotFoundException cnfe) {
1757 }
1758 return canonCs;
1759 }
1760
1761 // Wrapper to return a canonical path that avoids calling getCanonicalPath()
1762 // with paths that are intended to match all entries in the directory
1763 private static String canonPath(String path) throws IOException {
1764 if (path.endsWith("*")) {
1765 path = path.substring(0, path.length()-1) + "-";
1766 path = new File(path).getCanonicalPath();
1767 return path.substring(0, path.length()-1) + "*";
1768 } else {
1769 return new File(path).getCanonicalPath();
1770 }
1771 }
1772
1773 private String printPD(ProtectionDomain pd) {
1774 Principal[] principals = pd.getPrincipals();
1775 String pals = "<no principals>";
1776 if (principals != null && principals.length > 0) {
1777 StringBuilder palSB = new StringBuilder("(principals ");
1778 for (int i = 0; i < principals.length; i++) {
1779 palSB.append(principals[i].getClass().getName())
1780 .append(" \"").append(principals[i].getName())
1781 .append('"');
1782 if (i < principals.length-1)
1783 palSB.append(", ");
1784 else
1785 palSB.append(')');
1786 }
1787 pals = palSB.toString();
1788 }
1789 return "PD CodeSource: "
1790 + pd.getCodeSource()
1791 +"\n\t" + "PD ClassLoader: "
1792 + pd.getClassLoader()
1793 +"\n\t" + "PD Principals: "
1794 + pals;
1795 }
1796
1797 /**
1798 * return true if no replacement was performed,
1799 * or if replacement succeeded.
1800 */
1801 private boolean replacePrincipals(
1802 List<PolicyParser.PrincipalEntry> principals, KeyStore keystore) {
1803
1804 if (principals == null || principals.isEmpty() || keystore == null)
1805 return true;
1806
1807 for (PolicyParser.PrincipalEntry pppe : principals) {
1867 startIndex = e+2;
1868 continue;
1869 } else if (prefix.equalsIgnoreCase("alias")) {
1870 // get the suffix and perform keystore alias replacement
1871 if (colonIndex == -1) {
1872 MessageFormat form = new MessageFormat
1873 (ResourcesMgr.getString
1874 ("alias.name.not.provided.pe.name."));
1875 Object[] source = {pe.name};
1876 throw new Exception(form.format(source));
1877 }
1878 suffix = value.substring(colonIndex+1);
1879 if ((suffix = getDN(suffix, keystore)) == null) {
1880 MessageFormat form = new MessageFormat
1881 (ResourcesMgr.getString
1882 ("unable.to.perform.substitution.on.alias.suffix"));
1883 Object[] source = {value.substring(colonIndex+1)};
1884 throw new Exception(form.format(source));
1885 }
1886
1887 sb.append(X500PRINCIPAL).append(" \"").append(suffix).append('"');
1888 startIndex = e+2;
1889 } else {
1890 MessageFormat form = new MessageFormat
1891 (ResourcesMgr.getString
1892 ("substitution.value.prefix.unsupported"));
1893 Object[] source = {prefix};
1894 throw new Exception(form.format(source));
1895 }
1896 }
1897
1898 // copy the rest of the value
1899 sb.append(pe.name.substring(startIndex));
1900
1901 // replace the name with expanded value
1902 if (debug != null) {
1903 debug.println(" Permission name expanded from:\n\t" +
1904 pe.name + "\nto\n\t" + sb.toString());
1905 }
1906 pe.name = sb.toString();
1907 }
|