Search in sources :

Example 1 with TamperException

use of net.sourceforge.processdash.security.TamperDeterrent.TamperException in project processdash by dtuma.

the class PermissionsManager method readRoles.

/**
     * Read the roles that are defined in this dataset.
     */
private void readRoles() throws IOException, TamperException {
    Map roles = new TreeMap();
    if (Settings.isTeamMode() && rolesFile.isFile()) {
        verifyFile(rolesFile);
        try {
            // open, parse, and load the roles XML file
            InputStream in = new BufferedInputStream(new FileInputStream(rolesFile));
            Element xml = XMLUtils.parse(in).getDocumentElement();
            readRolesFromXml(roles, xml);
            // store the timestamp for role data
            rolesTimestamp = XMLUtils.getXMLDate(xml, TIMESTAMP_ATTR);
            if (rolesTimestamp == null)
                rolesTimestamp = new Date(rolesFile.lastModified());
        } catch (Exception e) {
            throw new IOException(rolesFile.getName(), e);
        }
    } else {
        // no file present? read default roles from extension points
        long ts = 1;
        for (Element xml : ExtensionManager.getXmlConfigurationElements(STANDARD_ROLES_TAG)) {
            readRolesFromXml(roles, xml);
            ts = Math.max(ts, ExtensionManager.getModTimeOfSource(xml));
            // overrides to the standard roles.)
            if (Settings.isPersonalMode())
                break;
        }
        rolesTimestamp = new Date(ts);
    }
    this.roles = Collections.synchronizedMap(roles);
    this.rolesDirty = false;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) FileInputStream(java.io.FileInputStream) Date(java.util.Date) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) TamperException(net.sourceforge.processdash.security.TamperDeterrent.TamperException) IOException(java.io.IOException) HttpException(net.sourceforge.processdash.util.HttpException)

Example 2 with TamperException

use of net.sourceforge.processdash.security.TamperDeterrent.TamperException in project processdash by dtuma.

the class PermissionsManager method readUsers.

/**
     * Read the users that are defined in this dataset.
     */
private void readUsers() throws IOException, TamperException {
    Map users = new TreeMap();
    if (Settings.isTeamMode() && usersFile.isFile()) {
        verifyFile(usersFile);
        try {
            // open and parse the users XML file
            InputStream in = new BufferedInputStream(new FileInputStream(usersFile));
            Element xml = XMLUtils.parse(in).getDocumentElement();
            // find and parse the <user> tags in the document
            NodeList nl = xml.getElementsByTagName(USER_TAG);
            for (int i = 0; i < nl.getLength(); i++) {
                User u = readUser((Element) nl.item(i));
                users.put(u.getUsernameLC(), u);
            }
            // store the timestamp for user data
            usersTimestamp = XMLUtils.getXMLDate(xml, TIMESTAMP_ATTR);
            if (usersTimestamp == null)
                usersTimestamp = new Date(usersFile.lastModified());
        } catch (Exception e) {
            throw new IOException(usersFile.getName(), e);
        }
    } else {
        // no file present? create a catch-all user definition
        String catchAllName = resources.getString("All_Other_Users");
        User u = new User(catchAllName, CATCH_ALL_USER_ID, false, Collections.singletonList(STANDARD_ROLE_ID));
        users.put(u.getUsernameLC(), u);
        usersTimestamp = new Date(1);
    }
    this.users = Collections.synchronizedMap(users);
    this.usersDirty = false;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) TreeMap(java.util.TreeMap) FileInputStream(java.io.FileInputStream) Date(java.util.Date) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) TamperException(net.sourceforge.processdash.security.TamperDeterrent.TamperException) IOException(java.io.IOException) HttpException(net.sourceforge.processdash.util.HttpException) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 TamperException (net.sourceforge.processdash.security.TamperDeterrent.TamperException)2 HttpException (net.sourceforge.processdash.util.HttpException)2 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)1