configfile.java

来自「JAVA 所有包」· Java 代码 · 共 622 行 · 第 1/2 页

JAVA
622
字号
	java.lang.SecurityManager sm = System.getSecurityManager();	if (sm != null)	    sm.checkPermission(new AuthPermission("refreshLoginConfiguration"));	java.security.AccessController.doPrivileged	    (new java.security.PrivilegedAction() {	    public Object run() {		try {		    init(url);		} catch (java.io.IOException ioe) {		    throw (SecurityException) new SecurityException				(ioe.getLocalizedMessage()).initCause(ioe);		}		return null;	    }	});    }    private void readConfig(Reader reader, HashMap newConfig)	throws IOException {	int linenum = 1; 	if (!(reader instanceof BufferedReader))	    reader = new BufferedReader(reader); 	st = new StreamTokenizer(reader);	st.quoteChar('"');	st.wordChars('$', '$');	st.wordChars('_', '_');	st.wordChars('-', '-');	st.lowerCaseMode(false);	st.slashSlashComments(true);	st.slashStarComments(true);	st.eolIsSignificant(true); 	lookahead = nextToken();	while (lookahead != StreamTokenizer.TT_EOF) {	    parseLoginEntry(newConfig);	}    }    private void parseLoginEntry(HashMap newConfig) throws IOException { 	String appName;	String moduleClass;	String sflag;	AppConfigurationEntry.LoginModuleControlFlag controlFlag;	LinkedList configEntries = new LinkedList(); 	// application name	appName = st.sval;	lookahead = nextToken(); 	if (debugParser != null) {	    debugParser.println("\tReading next config entry: " + appName);	} 	match("{"); 	// get the modules	while (peek("}") == false) {	    HashSet argSet = new HashSet(); 	    // get the module class name	    moduleClass = match("module class name"); 	    // controlFlag (required, optional, etc)	    sflag = match("controlFlag");	    if (sflag.equalsIgnoreCase("REQUIRED"))		controlFlag =			AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;	    else if (sflag.equalsIgnoreCase("REQUISITE"))		controlFlag =			AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;	    else if (sflag.equalsIgnoreCase("SUFFICIENT"))		controlFlag =			AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;	    else if (sflag.equalsIgnoreCase("OPTIONAL"))		controlFlag =			AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;	    else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tInvalid control flag, flag",			"sun.security.util.AuthResources"));		Object[] source = {sflag};		throw new IOException(form.format(source));	    } 	    // get the args	    HashMap options = new HashMap();	    String key;	    String value;	    while (peek(";") == false) {		key = match("option key");		match("=");		try {		    value = expand(match("option value"));		} catch (PropertyExpander.ExpandException peee) {		    throw new IOException(peee.getLocalizedMessage());		}		options.put(key, value);	    } 	    lookahead = nextToken(); 	    // create the new element	    if (debugParser != null) {		debugParser.println("\t\t" + moduleClass + ", " + sflag);		java.util.Iterator i = options.keySet().iterator();		while (i.hasNext()) {		    key = (String)i.next();		    debugParser.println("\t\t\t" +					key +					"=" +					(String)options.get(key));		}	    }	    AppConfigurationEntry entry = new AppConfigurationEntry							(moduleClass,							controlFlag,							options);	    configEntries.add(entry);	}	match("}");	match(";"); 	// add this configuration entry	if (newConfig.containsKey(appName)) {	    MessageFormat form = new MessageFormat(ResourcesMgr.getString		("Configuration Error:\n\t" +			"Can not specify multiple entries for appName",		"sun.security.util.AuthResources"));	    Object[] source = {appName};	    throw new IOException(form.format(source));	}	newConfig.put(appName, configEntries);    }    private String match(String expect) throws IOException { 	String value = null; 	switch(lookahead) {	case StreamTokenizer.TT_EOF: 	    MessageFormat form1 = new MessageFormat(ResourcesMgr.getString		("Configuration Error:\n\texpected [expect], " +			"read [end of file]",		"sun.security.util.AuthResources"));	    Object[] source1 = {expect};	    throw new IOException(form1.format(source1)); 	case '"':	case StreamTokenizer.TT_WORD:	    if (expect.equalsIgnoreCase("module class name") ||		expect.equalsIgnoreCase("controlFlag") ||		expect.equalsIgnoreCase("option key") ||		expect.equalsIgnoreCase("option value")) {		value = st.sval;		lookahead = nextToken();	    } else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: " +				"expected [expect], found [value]",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), expect, st.sval};		throw new IOException(form.format(source));	    }	    break; 	case '{': 	    if (expect.equalsIgnoreCase("{")) {		lookahead = nextToken();	    } else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: expected [expect]",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), expect, st.sval};		throw new IOException(form.format(source));	    }	    break;	case ';':	    if (expect.equalsIgnoreCase(";")) {		lookahead = nextToken();	    } else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: expected [expect]",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), expect, st.sval};		throw new IOException(form.format(source));	    }	    break; 	case '}': 	    if (expect.equalsIgnoreCase("}")) {		lookahead = nextToken();	    } else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: expected [expect]",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), expect, st.sval};		throw new IOException(form.format(source));	    }	    break;	case '=':	    if (expect.equalsIgnoreCase("=")) {		lookahead = nextToken();	    } else {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: expected [expect]",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), expect, st.sval};		throw new IOException(form.format(source));	    }	    break; 	default:	    MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: " +				"expected [expect], found [value]",			"sun.security.util.AuthResources"));	    Object[] source = {new Integer(linenum), expect, st.sval};	    throw new IOException(form.format(source));	}	return value;    }    private boolean peek(String expect) {	boolean found = false; 	switch (lookahead) {	case ',':	    if (expect.equalsIgnoreCase(","))		found = true;	    break;	case ';':	    if (expect.equalsIgnoreCase(";"))		found = true;	    break;	case '{':	    if (expect.equalsIgnoreCase("{"))		found = true;	    break;	case '}':	    if (expect.equalsIgnoreCase("}"))		found = true;	    break;	default:	}	return found;    }    private int nextToken() throws IOException {	int tok;	while ((tok = st.nextToken()) == StreamTokenizer.TT_EOL) {	    linenum++;	}	return tok;    }    /*     * Fast path reading from file urls in order to avoid calling     * FileURLConnection.connect() which can be quite slow the first time     * it is called. We really should clean up FileURLConnection so that     * this is not a problem but in the meantime this fix helps reduce     * start up time noticeably for the new launcher. -- DAC     */    private InputStream getInputStream(URL url) throws IOException {	if ("file".equals(url.getProtocol())) {	    String path = url.getFile().replace('/', File.separatorChar);	    return new FileInputStream(path);	} else {	    return url.openStream();	}    }    private String expand(String value)	throws PropertyExpander.ExpandException, IOException {	if ("".equals(value)) {	    return value;	}	if (expandProp) {	    String s = PropertyExpander.expand(value);	    if (s == null || s.length() == 0) {		MessageFormat form = new MessageFormat(ResourcesMgr.getString			("Configuration Error:\n\tLine line: " +			"system property [value] expanded to empty value",			"sun.security.util.AuthResources"));		Object[] source = {new Integer(linenum), value};		throw new IOException(form.format(source));	    }	    return s;	} else {	    return value;	}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?