001: // httpdSecurityManager.java
002: // $Id: httpdSecurityManager.java,v 1.3 2002/06/19 14:22:46 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.http;
007:
008: /**
009: * The <b>jhttpd</b> security manager.
010: * You really need this if you plan to accept agent execution on your server.
011: * Although, in next versions, the security manager may be used to limit
012: * your server users in what entities they can export.
013: * <p>Add the <b>-s</b> command line argument to <b>jhttpd</b> invocation to
014: * set the security manager to an instance of this class.
015: */
016:
017: public class httpdSecurityManager extends SecurityManager {
018: /**
019: * Name of the property indicating if agents are allowed to accept().
020: * When <strong>true</strong>, this property indicates that agents are
021: * allowed to use the <em>accept</em> method of ServerSockets.
022: * <p>This property defaults to <strong>false</strong>.
023: */
024: public static final String SM_AGENT_ACCEPT_P = "org.w3c.jigsaw.security.agent.accept";
025: /**
026: * Name of the property indicating if agents are allowed to write().
027: * When <strong>true</strong>, this property indicates that agents
028: * are allowed to use the <em>write</em> method of output streams.
029: * <p>This property defaults to <strong>false</strong>.
030: */
031: public static final String SM_AGENT_WRITE_P = "org.w3c.jigsaw.security.write";
032: /**
033: * Name of the property indicating if security maneger is debuged.
034: * When <strong>true</strong> this property makes the security manager
035: * emits debugging traces.
036: * <p>This property defaults to <strong>false</strong>.
037: */
038: public static final String SM_DEBUG_P = "org.w3c.jigsaw.debug";
039:
040: private static boolean debug = false;
041: private static boolean agent_accept = false;
042: private static boolean agent_write = false;
043:
044: static {
045: // Get properties:
046: agent_accept = Boolean.getBoolean(SM_AGENT_ACCEPT_P);
047: agent_write = Boolean.getBoolean(SM_AGENT_WRITE_P);
048: debug = Boolean.getBoolean(SM_DEBUG_P);
049: }
050:
051: protected final boolean inAgent() {
052: // ClassLoader loader = currentClassLoader() ;
053: // Agent are not available yet with new Jigsaw design
054: // if ( loader == null ) {
055: // return false ;
056: // } else if ( loader instanceof org.w3c.jigsaw.agent.AgentClassLoader ) {
057: // return true ;
058: // } else {
059: // throw new SecurityException ("Unknown class loader: " + loader) ;
060: // }
061: return false;
062: }
063:
064: protected void trace(String msg) {
065: if (inAgent())
066: System.out.println("[agent-security] " + msg);
067: else
068: System.out.println("[httpd-security] " + msg);
069: }
070:
071: public void checkAccept(String host, int port) {
072: if (debug)
073: trace("checkAccept: " + host + "@" + port);
074: if (inAgent() && (!agent_accept))
075: throw new SecurityException();
076: return;
077: }
078:
079: public void checkAccess(Thread thr) {
080: if (debug)
081: trace("checkAccess: " + thr.getName());
082: if (inAgent())
083: throw new SecurityException("Access denied to agents.");
084: return;
085: }
086:
087: public void checkCreateClassLoader() {
088: if (debug)
089: trace("checkCreateClassLoader.");
090: if (inAgent())
091: throw new SecurityException(
092: "createClassLoader denied to agents.");
093: return;
094: }
095:
096: public void checkListen(int port) {
097: if (debug)
098: trace("checkListen: " + port);
099: if (inAgent())
100: throw new SecurityException("Listen denied to agents.");
101: return;
102: }
103:
104: public void checkPropertiesAccess() {
105: if (debug)
106: trace("checkPropertiesAccess.");
107: if (inAgent())
108: throw new SecurityException("Properties denied to agents");
109: return;
110: }
111:
112: public void checkRead(String file) {
113: if (debug)
114: trace("checkRead: " + file);
115: if (inAgent())
116: throw new SecurityException("Read(file) denied to agents.");
117:
118: return;
119: }
120:
121: public void checkRead(int fd) {
122: if (debug)
123: trace("checkRead: " + fd);
124: if (inAgent())
125: throw new SecurityException("Read(fd) denied to agents.");
126: return;
127: }
128:
129: public void checkWrite(int fd) {
130: if (debug)
131: trace("checkWrite: " + fd);
132: if (inAgent())
133: throw new SecurityException("Write(fd) denied to agents.");
134: return;
135: }
136:
137: public void checkWrite(String file) {
138: if (debug)
139: trace("checkWrite: " + file);
140: if (inAgent() && (!agent_write))
141: throw new SecurityException("write(file) denied to agents.");
142: return;
143: }
144:
145: }
|