Search in sources :

Example 1 with ParsingException

use of com.sun.enterprise.security.provider.PolicyParser.ParsingException in project Payara by payara.

the class PolicyConfigurationImpl method loadExcludedPolicy.

private Permissions loadExcludedPolicy() {
    Permissions result = null;
    String name = getPolicyFileName(false);
    FileReader reader = null;
    PolicyParser parser = new PolicyParser(false);
    try {
        captureFileTime(false);
        reader = new FileReader(name);
        parser.read(reader);
    } catch (java.io.FileNotFoundException fnf) {
        // Just means there is no excluded Policy file, which
        // is the typical case
        parser = null;
    } catch (java.io.IOException ioe) {
        String defMsg = "Error reading Policy file: " + name;
        String msg = localStrings.getLocalString("pc.file_read_error", defMsg, new Object[] { name, ioe });
        logger.log(Level.SEVERE, msg);
        throw new RuntimeException(defMsg);
    } catch (ParsingException pe) {
        String defMsg = "Unable to parse Policy file: " + name;
        String msg = localStrings.getLocalString("pc.policy_parsing_exception", defMsg, new Object[] { name, pe });
        logger.log(Level.SEVERE, msg);
        throw new RuntimeException(defMsg);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                String defMsg = "Unable to close Policy file: " + name;
                String msg = localStrings.getLocalString("pc.file_close_error", defMsg, new Object[] { name, e });
                logger.log(Level.SEVERE, msg);
                throw new RuntimeException(defMsg);
            }
        }
    }
    if (parser != null) {
        Enumeration grants = parser.grantElements();
        while (grants.hasMoreElements()) {
            GrantEntry grant = (GrantEntry) grants.nextElement();
            if (grant.codeBase != null || grant.signedBy != null || grant.principals.size() != 0) {
                String msg = localStrings.getLocalString("pc.excluded_grant_context_ignored", "ignore excluded grant context", new Object[] { grant });
                logger.log(Level.WARNING, msg);
            } else {
                Enumeration perms = grant.permissionEntries.elements();
                while (perms.hasMoreElements()) {
                    PermissionEntry entry = (PermissionEntry) perms.nextElement();
                    Permission p = loadPermission(entry.permission, entry.name, entry.action);
                    if (result == null) {
                        result = new Permissions();
                    }
                    result.add(p);
                }
            }
        }
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) java.io(java.io) ParsingException(com.sun.enterprise.security.provider.PolicyParser.ParsingException) ParsingException(com.sun.enterprise.security.provider.PolicyParser.ParsingException) PermissionEntry(com.sun.enterprise.security.provider.PolicyParser.PermissionEntry) GrantEntry(com.sun.enterprise.security.provider.PolicyParser.GrantEntry)

Aggregations

GrantEntry (com.sun.enterprise.security.provider.PolicyParser.GrantEntry)1 ParsingException (com.sun.enterprise.security.provider.PolicyParser.ParsingException)1 PermissionEntry (com.sun.enterprise.security.provider.PolicyParser.PermissionEntry)1 java.io (java.io)1 Enumeration (java.util.Enumeration)1