001    // RealtimeSecurity.java, created by wbeebee
002    // Copyright (C) 2001 Wes Beebee <wbeebee@mit.edu>
003    // Licensed under the terms of the GNU GPL; see COPYING for details.
004    package javax.realtime;
005    
006    /**
007     * @author Wes Beebee <<a href="mailto:wbeebee@mit.edu">wbeebee@mit.edu</a>>
008     */
009    
010    /** Security policy object for real-time specific issues. Primarily
011     *  used to control access to physical memory.
012     */
013    public class RealtimeSecurity {
014    
015        private static boolean accessPhysical = true;
016        private static boolean setFactory = false;
017        private static boolean setScheduler = false;
018        private static boolean setFilter = true;
019    
020        /** Create a <code>RealtimeSecurity</code> object. */
021        public RealtimeSecurity() {}
022    
023        /** Check whether the application is allowed to access physical memory.
024         *
025         *  @throws java.lang.SecurityException The application doesn't have
026         *                                      permission to access physical memory.
027         */
028        public void checkAccessPhysical() throws SecurityException
029        {
030            if (!accessPhysical) {
031                throw new SecurityException("Not allowed to access physical memory.");
032            }
033        }
034        
035        /** Check whether the application is allowed to access physical 
036         *  memory within the specified range.
037         *
038         *  @param base The beginning of the address range.
039         *  @param size The size of the address range.
040         *  @throws java.lang.SecurityException The application doesn't have permission
041         *                                      to acess the memory in the given range.
042         */
043        public void checkAccessPhysicalRange(long base, long size) 
044            throws SecurityException
045        {
046            throw new SecurityException("Not allowed to access " +
047                                        base + ":" + size+ ".");
048        }
049    
050        /** Check whether the application is allowed to set filter objects.
051         *
052         *  @throws java.lang.SecurityException The application doesn't have
053         *                                      permission to set filter objects.
054         */
055        public void checkSetFilter() throws SecurityException {
056            if (!setFilter) {
057                throw new SecurityException("Not allowed to set filter objects.");
058            }
059        }
060        
061        /** Check whether the application is allowed to set the scheduler.
062         *
063         *  @throws java.lang.SecurityException The application doesn't have
064         *                                      permission to set the scheduler.
065         */
066        public void checkSetScheduler()
067            throws SecurityException
068        {
069            if (!setScheduler) {
070                throw new SecurityException("Not allowed to set the scheduler.");
071            }
072        }
073    
074        /** Check whether the application is allowed to set factory objects.
075         *
076         *  @throws java.lang.SecurityException The application doesn't have
077         *                                      permission to set the factory.
078         */
079        public void checkSetFactory()
080            throws SecurityException
081        {
082            if (!setFactory) {
083                throw new SecurityException("Not allowed to set factory objects.");
084            }
085        }
086    }