<commit_before>
/*
 * Java core library component.
 *
 * Copyright (c) 1999
 *	<NAME>.  All rights reserved.
 * Copyright (c) 1999
 *	Transvirtual Technologies, Inc.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file.
 *
 * Author: <NAME> <<EMAIL>>
 */

package java.security;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

public final class Security {
	private static final String PROV_PREFIX = "security.provider.";
	private static final Properties props = new Properties();
	private static final Vector providers = new Vector();

	// Read in master security properties from "java.security" file
	static {
	  readProps: {

		// Read in java.security file properties
		File file = new File(
		    System.getProperties().getProperty("java.home")
			+ "/lib/kaffe/security/java.security");
		if (!file.exists()) {
			break readProps;
		}
		try {
			props.load(new BufferedInputStream(
			    new FileInputStream(file)));
		} catch (FileNotFoundException e) {
			break readProps;
		} catch (IOException e) {
			break readProps;
		}

		// Install configured security providers
		for (Iterator i = props.entrySet().iterator(); i.hasNext(); ) {
			Map.Entry ent = (Map.Entry)i.next();
			String key = (String)ent.getKey();
			int position = 0;

			if (!key.startsWith(PROV_PREFIX)) {
				continue;
			}
			try {
				insertProviderAt(
				    (Provider)Class.forName(
					(String)ent.getValue()).newInstance(),
				    Integer.parseInt(
					key.substring(PROV_PREFIX.length())));
			} catch (NumberFormatException e) {
			} catch (ClassNotFoundException e) {
			} catch (InstantiationException e) {
			} catch (IllegalAccessException e) {
			} catch (IllegalArgumentException e) {
			} catch (ClassCastException e) {
			}
		}

		// Should also read Policy stuff here...
	    }
	}

	// This class is not instantiable
	private Security() {
	}

	public static String getAlgorithmProperty(String alg, String prop) {

		throw new kaffe.util.NotImplemented(
		    Security.class.getName() + ".getAlgorithmProperty()");
	}

	public static int insertProviderAt(Provider provider, int position) {
		System.getSecurityManager().checkSecurityAccess(
		    "insertProvider." + provider.getName());<commit_msg>Add automatic fallback to default security provider if none is listed in java.security.<commit_after>
/*
 * Java core library component.
 *
 * Copyright (c) 1999
 *	<NAME>.  All rights reserved.
 * Copyright (c) 1999
 *	Transvirtual Technologies, Inc.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file.
 *
 * Author: <NAME> <<EMAIL>>
 */

package java.security;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

public final class Security {
	private static final String PROV_PREFIX = "security.provider.";
	private static final String DEF_PROV = "kaffe.security.provider.Kaffe";
	private static final Properties props = new Properties();
	private static final Vector providers = new Vector();

	static {

		// Set default security provider if none specified
		props.put(PROV_PREFIX + "1", DEF_PROV);

		// Read in master security properties from "java.security" file
		readProps: {
			File file = new File(
			    System.getProperties().getProperty("java.home")
				+ "/lib/kaffe/security/java.security");
			if (file.exists()) {
				try {
					props.load(
					    new BufferedInputStream(
					    new FileInputStream(file)));
				} catch (FileNotFoundException e) {
				} catch (IOException e) {
				}
			}
		}

		// Install configured security providers
		for (Iterator i = props.entrySet().iterator(); i.hasNext(); ) {
			Map.Entry ent = (Map.Entry)i.next();
			String key = (String)ent.getKey();
			int position = 0;

			if (!key.startsWith(PROV_PREFIX)) {
				continue;
			}
			try {
				insertProviderAt(
				    (Provider)Class.forName(
					(String)ent.getValue()).newInstance(),
				    Integer.parseInt(
					key.substring(PROV_PREFIX.length())));
			} catch (NumberFormatException e) {
			} catch (ClassNotFoundException e) {
			} catch (InstantiationException e) {
			} catch (IllegalAccessException e) {
			} catch (IllegalArgumentException e) {
			} catch (ClassCastException e) {
			}
		}

		// Should also read Policy stuff here...
	}

	// This class is not instantiable
	private Security() {
	}

	public static String getAlgorithmProperty(String alg, String prop) {

		throw new kaffe.util.NotImplemented(
		    Security.class.getName() + ".getAlgorithmProperty()");
	}

	public static int insertProviderAt(Provider provider, int position) {
		System.getSecurityManager().checkSecurityAccess(
		    "insertProvider." + provider.getName());
{'fraction_non_alphanumeric': 0.11743981209630065, 'fraction_numerical': 0.0037189273830495204, 'mean_word_length': 3.6202531645569622, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951268', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1458, 'n_words': 419}