You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/06/24 23:49:31 UTC
svn commit: r416966 - in
/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security:
./ fortress/
Author: ndbeyer
Date: Sat Jun 24 14:49:30 2006
New Revision: 416966
URL: http://svn.apache.org/viewvc?rev=416966&view=rev
Log:
Refactor, cleanup with generifications.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/DefaultPolicyScanner.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/PolicyEntry.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicy.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/PolicyUtils.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityAccess.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityUtils.java
incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/Services.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/DefaultPolicyScanner.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/DefaultPolicyScanner.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/DefaultPolicyScanner.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/DefaultPolicyScanner.java Sat Jun 24 14:49:30 2006
@@ -113,8 +113,8 @@
* @throws InvalidFormatException
* if unexpected or unknown token encountered
*/
- public void scanStream(Reader r, Collection/* <GrantEntry> */grantEntries,
- List/* <KeystoreEntry> */keystoreEntries) throws IOException,
+ public void scanStream(Reader r, Collection<GrantEntry> grantEntries,
+ List<KeystoreEntry> keystoreEntries) throws IOException,
InvalidFormatException {
StreamTokenizer st = configure(new StreamTokenizer(r));
//main parsing loop
@@ -153,7 +153,7 @@
*
* </pre>
*
- * @return succesfully parsed KeystoreEntry
+ * @return successfully parsed KeystoreEntry
* @throws IOException
* if stream reading failed
* @throws InvalidFormatException
@@ -194,7 +194,7 @@
*
* </pre>
*
- * @return succesfully parsed GrantEntry
+ * @return successfully parsed GrantEntry
* @throws IOException
* if stream reading failed
* @throws InvalidFormatException
@@ -253,10 +253,10 @@
*
* </pre>
*
- * Both class and name may be wildcards, wildcarded name should not
+ * Both class and name may be wildcards, wildcard names should not
* surrounded by quotes.
*
- * @return succesfully parsed PrincipalEntry
+ * @return successfully parsed PrincipalEntry
* @throws IOException
* if stream reading failed
* @throws InvalidFormatException
@@ -297,16 +297,15 @@
*
* List is terminated by '}' (closing curly brace) symbol.
*
- * @return collection of succesfully parsed PermissionEntries
+ * @return collection of successfully parsed PermissionEntries
* @throws IOException
* if stream reading failed
* @throws InvalidFormatException
* if unexpected or unknown token encountered
*/
- protected Collection/* <PermissionEntry> */readPermissionEntries(
+ protected Collection<PermissionEntry> readPermissionEntries(
StreamTokenizer st) throws IOException, InvalidFormatException {
- // FIXME 1.5 signature
- Collection/* <PermissionEntry> */permissions = new HashSet();
+ Collection<PermissionEntry> permissions = new HashSet<PermissionEntry>();
parsing: while (true) {
switch (st.nextToken()) {
@@ -443,14 +442,12 @@
/**
* Collection of PrincipalEntries of grant clause.
*/
- // FIXME 1.5 signature
- public Collection/* <PrincipalEntry> */principals;
+ public Collection<PrincipalEntry> principals;
/**
* Collection of PermissionEntries of grant clause.
*/
- // FIXME 1.5 signature
- public Collection/* <PermissionEntry> */permissions;
+ public Collection<PermissionEntry> permissions;
/**
* Adds specified element to the <code>principals</code> collection.
@@ -458,7 +455,7 @@
*/
public void addPrincipal(PrincipalEntry pe) {
if (principals == null) {
- principals = new HashSet();
+ principals = new HashSet<PrincipalEntry>();
}
principals.add(pe);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/PolicyEntry.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/PolicyEntry.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/PolicyEntry.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/PolicyEntry.java Sat Jun 24 14:49:30 2006
@@ -22,6 +22,7 @@
package org.apache.harmony.security;
import java.security.CodeSource;
+import java.security.Permission;
import java.security.Principal;
import java.util.Collection;
import java.util.Collections;
@@ -44,19 +45,20 @@
// Array of principals
private final Principal[] principals;
- // Permossions collection
- private final Collection permissions;
+ // Permissions collection
+ private final Collection<Permission> permissions;
/**
* Constructor with initialization parameters. Passed collections are not
* referenced directly, but copied.
*/
- public PolicyEntry(CodeSource cs, Collection prs, Collection permissions) {
+ public PolicyEntry(CodeSource cs, Collection<? extends Principal> prs,
+ Collection<? extends Permission> permissions) {
this.cs = cs;
- this.principals = (prs == null || prs.size() == 0) ? null : (Principal[])prs
- .toArray(new Principal[prs.size()]);
- this.permissions = (permissions == null || permissions.size() == 0)
- ? null : Collections.unmodifiableCollection(permissions);
+ this.principals = (prs == null || prs.isEmpty()) ? null
+ : (Principal[]) prs.toArray(new Principal[prs.size()]);
+ this.permissions = (permissions == null || permissions.isEmpty()) ? null
+ : Collections.unmodifiableCollection(permissions);
}
/**
@@ -81,7 +83,7 @@
* Returns unmodifiable collection of permissions defined by this
* PolicyEntry, may be <code>null</code>.
*/
- public Collection getPermissions() {
+ public Collection<Permission> getPermissions() {
return permissions;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicy.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicy.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicy.java Sat Jun 24 14:49:30 2006
@@ -25,6 +25,7 @@
import java.net.URL;
import java.security.AccessController;
import java.security.CodeSource;
+import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Policy;
import java.security.ProtectionDomain;
@@ -129,7 +130,7 @@
* This implementation is thread-safe. The policy caches sets of calculated
* permissions for the requested objects (ProtectionDomains and CodeSources) via
* WeakHashMap; the cache is cleaned either explicitly during refresh()
- * invokation, or naturally by garbage-collecting the corresponding objects.
+ * invocation, or naturally by garbage-collecting the corresponding objects.
*
* @see org.apache.harmony.security.PolicyUtils#getPolicyURLs(Properties, String,
* String)
@@ -148,13 +149,13 @@
public static final String POLICY_URL_PREFIX = "policy.url.";
// A set of PolicyEntries constituting this Policy.
- private final Set/* <PolicyEntry> */grants = new HashSet();
+ private final Set<PolicyEntry> grants = new HashSet<PolicyEntry>();
// Calculated Permissions cache, organized as
// Map{Object->Collection<Permission>}.
// The Object is a ProtectionDomain, a CodeSource or
// any other permissions-granted entity.
- private final Map cache = new WeakHashMap();
+ private final Map<Object, Collection<Permission>> cache = new WeakHashMap<Object, Collection<Permission>>();
// A specific parser for a particular policy file format.
private final DefaultPolicyParser parser;
@@ -184,7 +185,7 @@
/**
* Returns collection of permissions allowed for the domain
- * according to the policy. The evalueated characteristics of the
+ * according to the policy. The evaluated characteristics of the
* domain are it's codesource and principals; they are assumed
* to be <code>null</code> if the domain is <code>null</code>.
*/
@@ -196,17 +197,17 @@
}
}
}
- Collection pc = (Collection)cache.get(pd);
+ Collection<Permission> pc = cache.get(pd);
if (pc == null) {
//have to synchronize to exclude cache pollution after refresh
synchronized (cache) {
// double check in case value has been put to cache
// while we've been awaiting monitor
- pc = (Collection)cache.get(pd);
+ pc = cache.get(pd);
if (pc == null) {
- pc = new HashSet();
- Iterator it = grants.iterator();
+ pc = new HashSet<Permission>();
+ Iterator<PolicyEntry> it = grants.iterator();
while (it.hasNext()) {
PolicyEntry ge = (PolicyEntry)it.next();
if (ge.impliesPrincipals(pd == null ? null : pd.getPrincipals())
@@ -235,17 +236,17 @@
}
}
}
- Collection pc = (Collection)cache.get(cs);
+ Collection<Permission> pc = cache.get(cs);
if (pc == null) {
//have to synchronize to exclude cache pollution after refresh
synchronized (cache) {
// double check in case value has been put to cache
// while we've been awaiting monitor
- pc = (Collection)cache.get(cs);
+ pc = cache.get(cs);
if (pc == null) {
- pc = new HashSet();
- Iterator it = grants.iterator();
+ pc = new HashSet<Permission>();
+ Iterator<PolicyEntry> it = grants.iterator();
while (it.hasNext()) {
PolicyEntry ge = (PolicyEntry)it.next();
if (ge.impliesPrincipals(null)
@@ -269,9 +270,9 @@
* @see PolicyUtils#getPolicyURLs(Properties, String, String)
*/
public synchronized void refresh() {
- Set fresh = new HashSet();
- Properties system = new Properties((Properties)AccessController
- .doPrivileged(new PolicyUtils.SystemKit()));
+ Set<PolicyEntry> fresh = new HashSet<PolicyEntry>();
+ Properties system = new Properties(AccessController
+ .doPrivileged(new PolicyUtils.SystemKit()));
system.setProperty("/", File.separator);
URL[] policyLocations = PolicyUtils.getPolicyURLs(system,
JAVA_SECURITY_POLICY,
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java Sat Jun 24 14:49:30 2006
@@ -48,6 +48,10 @@
import org.apache.harmony.security.DefaultPolicyScanner;
import org.apache.harmony.security.PolicyEntry;
import org.apache.harmony.security.UnresolvedPrincipal;
+import org.apache.harmony.security.DefaultPolicyScanner.GrantEntry;
+import org.apache.harmony.security.DefaultPolicyScanner.KeystoreEntry;
+import org.apache.harmony.security.DefaultPolicyScanner.PermissionEntry;
+import org.apache.harmony.security.DefaultPolicyScanner.PrincipalEntry;
/**
@@ -105,18 +109,16 @@
* @return a collection of PolicyEntry objects, may be empty
* @throws Exception IO error while reading location or file syntax error
*/
- // FIXME 1.5 signature
- public Collection/*<PolicyEntry>*/parse(URL location, Properties system)
+ public Collection<PolicyEntry>parse(URL location, Properties system)
throws Exception {
boolean resolve = PolicyUtils.canExpandProperties();
Reader r = new BufferedReader(new InputStreamReader(
- (InputStream) AccessController
+ AccessController
.doPrivileged(new PolicyUtils.URLLoader(location))));
- // FIXME 1.5 signature
- Collection/*<GrantEntry>*/grantEntries = new HashSet();
- List/*<KeystoreEntry>*/keystores = new ArrayList();
+ Collection<GrantEntry> grantEntries = new HashSet<GrantEntry>();
+ List<KeystoreEntry> keystores = new ArrayList<KeystoreEntry>();
try {
scanner.scanStream(r, grantEntries, keystores);
@@ -128,10 +130,9 @@
//XXX KeyStore could be loaded lazily...
KeyStore ks = initKeyStore(keystores, location, system, resolve);
- // FIXME 1.5 signature
- Collection/*<PolicyEntry>*/result = new HashSet();
- for (Iterator iter = grantEntries.iterator(); iter.hasNext();) {
- DefaultPolicyScanner.GrantEntry ge = (DefaultPolicyScanner.GrantEntry) iter
+ Collection<PolicyEntry> result = new HashSet<PolicyEntry>();
+ for (Iterator<GrantEntry> iter = grantEntries.iterator(); iter.hasNext();) {
+ DefaultPolicyScanner.GrantEntry ge = iter
.next();
try {
PolicyEntry pe = resolveGrant(ge, ks, system, resolve);
@@ -185,9 +186,8 @@
URL codebase = null;
Certificate[] signers = null;
- // FIXME 1.5 signature
- Set/*<Principal>*/principals = new HashSet();
- Set/*<Permission>*/permissions = new HashSet();
+ Set<Principal>principals = new HashSet<Principal>();
+ Set<Permission>permissions = new HashSet<Permission>();
if (ge.codebase != null) {
codebase = new URL(resolve ? PolicyUtils.expandURL(ge.codebase,
system) : ge.codebase);
@@ -199,8 +199,8 @@
signers = resolveSigners(ks, ge.signers);
}
if (ge.principals != null) {
- for (Iterator iter = ge.principals.iterator(); iter.hasNext();) {
- DefaultPolicyScanner.PrincipalEntry pe = (DefaultPolicyScanner.PrincipalEntry) iter
+ for (Iterator<PrincipalEntry> iter = ge.principals.iterator(); iter.hasNext();) {
+ DefaultPolicyScanner.PrincipalEntry pe = iter
.next();
if (resolve) {
pe.name = PolicyUtils.expand(pe.name, system);
@@ -213,8 +213,8 @@
}
}
if (ge.permissions != null) {
- for (Iterator iter = ge.permissions.iterator(); iter.hasNext();) {
- DefaultPolicyScanner.PermissionEntry pe = (DefaultPolicyScanner.PermissionEntry) iter
+ for (Iterator<PermissionEntry> iter = ge.permissions.iterator(); iter.hasNext();) {
+ DefaultPolicyScanner.PermissionEntry pe = iter
.next();
try {
permissions.add(resolvePermission(pe, ge, ks, system,
@@ -270,7 +270,7 @@
Certificate[] signers = (pe.signers == null) ? null : resolveSigners(
ks, pe.signers);
try {
- Class klass = Class.forName(pe.klass);
+ Class<?> klass = Class.forName(pe.klass);
if (PolicyUtils.matchSubset(signers, klass.getSigners())) {
return PolicyUtils.instantiatePermission(klass, pe.name,
pe.actions);
@@ -326,9 +326,9 @@
//need expanding to list of principals in grant clause
if (ge.principals != null && ge.principals.size() != 0) {
StringBuffer sb = new StringBuffer();
- for (Iterator iter = ge.principals.iterator(); iter
+ for (Iterator<PrincipalEntry> iter = ge.principals.iterator(); iter
.hasNext();) {
- DefaultPolicyScanner.PrincipalEntry pr = (DefaultPolicyScanner.PrincipalEntry) iter
+ DefaultPolicyScanner.PrincipalEntry pr = iter
.next();
if (pr.klass == null) {
// aliased X500Principal
@@ -393,13 +393,13 @@
+ signers + "\"");
}
- Collection certs = new HashSet();
+ Collection<Certificate> certs = new HashSet<Certificate>();
StringTokenizer snt = new StringTokenizer(signers, ",");
while (snt.hasMoreTokens()) {
//XXX cache found certs ??
certs.add(ks.getCertificate(snt.nextToken().trim()));
}
- return (Certificate[]) certs.toArray(new Certificate[certs.size()]);
+ return certs.toArray(new Certificate[certs.size()]);
}
/**
@@ -447,12 +447,12 @@
* @param resolve flag enabling/disabling property expansion
* @return the first successfully loaded KeyStore or <code>null</code>
*/
- protected KeyStore initKeyStore(List/*<KeystoreEntry>*/keystores,
+ protected KeyStore initKeyStore(List<KeystoreEntry>keystores,
URL base, Properties system, boolean resolve) {
for (int i = 0; i < keystores.size(); i++) {
try {
- DefaultPolicyScanner.KeystoreEntry ke = (DefaultPolicyScanner.KeystoreEntry) keystores
+ DefaultPolicyScanner.KeystoreEntry ke = keystores
.get(i);
if (resolve) {
ke.url = PolicyUtils.expandURL(ke.url, system);
@@ -465,7 +465,7 @@
}
KeyStore ks = KeyStore.getInstance(ke.type);
URL location = new URL(base, ke.url);
- InputStream is = (InputStream) AccessController
+ InputStream is = AccessController
.doPrivileged(new PolicyUtils.URLLoader(location));
try {
ks.load(is, null);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/PolicyUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/PolicyUtils.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/PolicyUtils.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/PolicyUtils.java Sat Jun 24 14:49:30 2006
@@ -22,6 +22,7 @@
package org.apache.harmony.security.fortress;
import java.io.File;
+import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.security.AccessController;
@@ -50,7 +51,7 @@
/**
* Auxiliary action for opening InputStream from specified location.
*/
- public static class URLLoader implements PrivilegedExceptionAction {
+ public static class URLLoader implements PrivilegedExceptionAction<InputStream> {
/**
* URL of target location.
@@ -67,7 +68,7 @@
/**
* Returns InputStream from the target URL.
*/
- public Object run() throws Exception {
+ public InputStream run() throws Exception {
return location.openStream();
}
}
@@ -75,12 +76,12 @@
/**
* Auxiliary action for accessing system properties in a bundle.
*/
- public static class SystemKit implements PrivilegedAction {
+ public static class SystemKit implements PrivilegedAction<Properties> {
/**
* Returns system properties.
*/
- public Object run() {
+ public Properties run() {
return System.getProperties();
}
}
@@ -88,7 +89,7 @@
/**
* Auxiliary action for accessing specific system property.
*/
- public static class SystemPropertyAccessor implements PrivilegedAction {
+ public static class SystemPropertyAccessor implements PrivilegedAction<String> {
/**
* A key of a required system property.
@@ -107,7 +108,7 @@
* "provide key and supply action" code block,
* for reusing existing action instance.
*/
- public PrivilegedAction key(String key) {
+ public PrivilegedAction<String> key(String key) {
this.key = key;
return this;
}
@@ -115,7 +116,7 @@
/**
* Returns specified system property.
*/
- public Object run() {
+ public String run() {
return System.getProperty(key);
}
}
@@ -123,19 +124,27 @@
/**
* Auxiliary action for accessing specific security property.
*/
- public static class SecurityPropertyAccessor extends SystemPropertyAccessor {
+ public static class SecurityPropertyAccessor implements PrivilegedAction<String> {
+ private String key;
+
/**
* Constructor with a property key parameter.
*/
public SecurityPropertyAccessor(String key) {
- super(key);
+ super();
+ this.key = key;
}
+ public PrivilegedAction<String> key(String key) {
+ this.key = key;
+ return this;
+ }
+
/**
* Returns specified security property.
*/
- public Object run() {
+ public String run() {
return Security.getProperty(key);
}
}
@@ -143,20 +152,23 @@
/**
* Auxiliary action for loading a provider by specific security property.
*/
- public static class ProviderLoader extends SystemPropertyAccessor {
+ public static class ProviderLoader<T> implements PrivilegedAction<T> {
+ private String key;
+
/**
* Acceptable provider superclass.
*/
- public Class expectedType;
+ private Class<T> expectedType;
/**
* Constructor taking property key and acceptable provider
* superclass parameters.
*/
- public ProviderLoader(String key, Class expected) {
- super(key);
- expectedType = expected;
+ public ProviderLoader(String key, Class<T> expected) {
+ super();
+ this.key = key;
+ this.expectedType = expected;
}
/**
@@ -164,10 +176,10 @@
* The <code>key</code> should map to a fully qualified classname.
*
* @throws SecurityException if no value specified for the key
- * in security properties or if an Exception has occured
+ * in security properties or if an Exception has occurred
* during classloading and instantiating.
*/
- public Object run() {
+ public T run() {
String klassName = Security.getProperty(key);
if (klassName == null || klassName.length() == 0) {
throw new SecurityException("Provider implementation should be specified via \""
@@ -175,7 +187,7 @@
}
// TODO accurate classloading
try {
- Class klass = Class.forName(klassName, true,
+ Class<?> klass = Class.forName(klassName, true,
Thread.currentThread().getContextClassLoader());
if (expectedType != null && klass.isAssignableFrom(expectedType)){
throw new SecurityException("Provided class "
@@ -183,7 +195,8 @@
+ " does not implement "
+ expectedType.getName());
}
- return klass.newInstance();
+ //FIXME expectedType.cast(klass.newInstance());
+ return (T)klass.newInstance();
}
catch (SecurityException se){
throw se;
@@ -240,7 +253,7 @@
final int START_OFFSET = START_MARK.length();
final int END_OFFSET = END_MARK.length();
- StringBuffer result = new StringBuffer(str);
+ StringBuilder result = new StringBuilder(str);
int start = result.indexOf(START_MARK);
while (start >= 0) {
int end = result.indexOf(END_MARK, start);
@@ -306,7 +319,7 @@
final int START_OFFSET = START_MARK.length();
final int END_OFFSET = END_MARK.length();
- StringBuffer result = new StringBuffer(str);
+ StringBuilder result = new StringBuilder(str);
int start = result.indexOf(START_MARK);
while (start >= 0) {
int end = result.indexOf(END_MARK, start);
@@ -357,7 +370,7 @@
* @see #expand(String, Properties)
*/
public static boolean canExpandProperties() {
- return !FALSE.equalsIgnoreCase((String) AccessController
+ return !FALSE.equalsIgnoreCase(AccessController
.doPrivileged(new SecurityPropertyAccessor(POLICY_EXPAND)));
}
@@ -398,12 +411,12 @@
final SecurityPropertyAccessor security = new SecurityPropertyAccessor(
null);
- final List urls = new ArrayList();
+ final List<URL> urls = new ArrayList<URL>();
boolean dynamicOnly = false;
URL dynamicURL = null;
//first check if policy is set via system properties
- if (!FALSE.equalsIgnoreCase((String) AccessController
+ if (!FALSE.equalsIgnoreCase(AccessController
.doPrivileged(security.key(POLICY_ALLOW_DYNAMIC)))) {
String location = system.getProperty(systemUrlKey);
if (location != null) {
@@ -416,10 +429,10 @@
location = expandURL(location, system);
// location can be a file, but we need an url...
final File f = new File(location);
- dynamicURL = (URL) AccessController
- .doPrivileged(new PrivilegedExceptionAction() {
+ dynamicURL = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<URL>() {
- public Object run() throws Exception {
+ public URL run() throws Exception {
if (f.exists()) {
return f.toURI().toURL();
} else {
@@ -441,8 +454,8 @@
if (!dynamicOnly) {
int i = 1;
while (true) {
- String location = (String) AccessController
- .doPrivileged(security.key(new StringBuffer(
+ String location = AccessController
+ .doPrivileged(security.key(new StringBuilder(
securityUrlPrefix).append(i++).toString()));
if (location == null) {
break;
@@ -463,22 +476,22 @@
if (dynamicURL != null) {
urls.add(dynamicURL);
}
- return (URL[]) urls.toArray(new URL[urls.size()]);
+ return urls.toArray(new URL[urls.size()]);
}
/**
* Converts common-purpose collection of Permissions to PermissionCollection.
*
* @param perms a collection containing arbitrary permissions, may be null
- * @return mutable heterogeneous PermissionCollection containg all Permissions
+ * @return mutable heterogeneous PermissionCollection containing all Permissions
* from the specified collection
*/
public static PermissionCollection toPermissionCollection(
- Collection/*<Permission>*/perms) {
+ Collection<Permission> perms) {
Permissions pc = new Permissions();
if (perms != null) {
- for (Iterator iter = perms.iterator(); iter.hasNext();) {
- Permission element = (Permission) iter.next();
+ for (Iterator<Permission> iter = perms.iterator(); iter.hasNext();) {
+ Permission element = iter.next();
pc.add(element);
}
}
@@ -505,7 +518,7 @@
* @throws IllegalArgumentException if no suitable constructor found
* @throws Exception any exception thrown by Constructor.newInstance()
*/
- public static Permission instantiatePermission(Class targetType,
+ public static Permission instantiatePermission(Class<?> targetType,
String targetName, String targetActions) throws Exception {
// let's guess the best order for trying constructors
@@ -528,8 +541,8 @@
// finally try to instantiate actual permission
for (int i = 0; i < argTypes.length; i++) {
try {
- Constructor ctor = targetType.getConstructor(argTypes[i]);
- return (Permission) ctor.newInstance(args[i]);
+ Constructor<?> ctor = targetType.getConstructor(argTypes[i]);
+ return (Permission)ctor.newInstance(args[i]);
}
catch (NoSuchMethodException ignore) {}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityAccess.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityAccess.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityAccess.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityAccess.java Sat Jun 24 14:49:30 2006
@@ -41,7 +41,7 @@
* @param s
* @return
*/
- public Iterator getAliases(Provider.Service s);
+ public Iterator<String> getAliases(Provider.Service s);
/**
* Access to Provider.getService(String type)
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityUtils.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityUtils.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/SecurityUtils.java Sat Jun 24 14:49:30 2006
@@ -34,7 +34,7 @@
/**
* The class is used to perform an exchange of information between
* java.lang.Thread and java.security.AccessController.<br>
- * The data to excnahge is inherited contexts for the Thread-s.
+ * The data to exchange is inherited contexts for the Thread-s.
*
*/
public final class SecurityUtils {
@@ -42,7 +42,7 @@
// A map used to store inherited contexts.<br>
// A thread is used as a key for the map and AccessControlContext
// passed to the putContext is used as a value.
- private static WeakHashMap map = new WeakHashMap();
+ private static final WeakHashMap<Thread, AccessControlContext> ACC_CACHE = new WeakHashMap<Thread, AccessControlContext>();
/**
* This method to be invoked in the Thread's constructor. The first argument
@@ -72,17 +72,17 @@
if (thread == null) {
throw new NullPointerException("thread can not be null");
}
- synchronized (map) {
- if (map.containsKey(thread)) {
+ synchronized (ACC_CACHE) {
+ if (ACC_CACHE.containsKey(thread)) {
throw new SecurityException("You can not modify this map.");
}
if (context == null) {
// this only allowed once - for the very first thread.
- if (map.containsValue(null)) {
+ if (ACC_CACHE.containsValue(null)) {
throw new Error("null context may be stored only once.");
}
}
- map.put(thread, context);
+ ACC_CACHE.put(thread, context);
}
}
@@ -104,9 +104,8 @@
}
*/
- synchronized (map) {
- AccessControlContext ctx = (AccessControlContext) map.get(thread);
- return ctx;
+ synchronized (ACC_CACHE) {
+ return ACC_CACHE.get(thread);
}
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/Services.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/Services.java?rev=416966&r1=416965&r2=416966&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/Services.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/Services.java Sat Jun 24 14:49:30 2006
@@ -22,11 +22,15 @@
package org.apache.harmony.security.fortress;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
@@ -39,7 +43,7 @@
// The HashMap that contains information about preferred implementations for
// all serviceName.algName in the registered providers
- private static HashMap services = new HashMap(512);
+ private static final Map<String, Provider.Service> services = new HashMap<String, Provider.Service>(512);
// Need refresh flag
private static boolean needRefresh; // = false;
@@ -50,13 +54,13 @@
public static int refreshNumber = 1;
// Registered providers
- private static ArrayList providers = new ArrayList(20);
+ private static final List<Provider> providers = new ArrayList<Provider>(20);
// Hash for quick provider access by name
- private static HashMap providersNames = new HashMap(20);
+ private static final Map<String, Provider> providersNames = new HashMap<String, Provider>(20);
static {
- AccessController.doPrivileged(new java.security.PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
loadProviders();
return null;
@@ -64,7 +68,7 @@
});
}
- // Load staticaly registered providers and init Services Info
+ // Load statically registered providers and init Services Info
private static void loadProviders() {
String providerClassName = null;
int i = 1;
@@ -92,7 +96,7 @@
* @return
*/
public static Provider[] getProviders() {
- return (Provider[]) providers.toArray(new Provider[providers.size()]);
+ return providers.toArray(new Provider[providers.size()]);
}
/**
@@ -100,8 +104,8 @@
*
* @return
*/
- public static java.util.List getProvidersList() {
- return new ArrayList(providers);
+ public static List<Provider> getProvidersList() {
+ return new ArrayList<Provider>(providers);
}
/**
@@ -114,7 +118,7 @@
if (name == null) {
return null;
}
- return (Provider) providersNames.get(name);
+ return providersNames.get(name);
}
/**
@@ -141,7 +145,7 @@
* @param providerNumber
*/
public static void removeProvider(int providerNumber) {
- Provider p = (Provider) providers.remove(providerNumber - 1);
+ Provider p = providers.remove(providerNumber - 1);
providersNames.remove(p.getName());
setNeedRefresh();
}
@@ -159,8 +163,8 @@
String alias;
StringBuffer sb = new StringBuffer(128);
- for (Iterator it1 = p.getServices().iterator(); it1.hasNext();) {
- serv = (Provider.Service) it1.next();
+ for (Iterator<Provider.Service> it1 = p.getServices().iterator(); it1.hasNext();) {
+ serv = it1.next();
type = serv.getType();
sb.delete(0, sb.length());
key = sb.append(type).append(".").append(
@@ -168,8 +172,8 @@
if (!services.containsKey(key)) {
services.put(key, serv);
}
- for (Iterator it2 = Engine.door.getAliases(serv); it2.hasNext();) {
- alias = (String) it2.next();
+ for (Iterator<String> it2 = Engine.door.getAliases(serv); it2.hasNext();) {
+ alias = it2.next();
sb.delete(0, sb.length());
key = sb.append(type).append(".").append(alias.toUpperCase())
.toString();
@@ -182,19 +186,19 @@
/**
*
- * Updates services hashtable for all registerd providers
+ * Updates services hashtable for all registered providers
*
*/
public static void updateServiceInfo() {
services.clear();
- for (Iterator it = providers.iterator(); it.hasNext();) {
- initServiceInfo((Provider) it.next());
+ for (Iterator<Provider> it = providers.iterator(); it.hasNext();) {
+ initServiceInfo(it.next());
}
needRefresh = false;
}
/**
- * Returns true if sevices contain any provider information
+ * Returns true if services contain any provider information
* @return
*/
public static boolean isEmpty() {
@@ -204,13 +208,13 @@
/**
*
* Returns service description.
- * Call refresh() befor.
+ * Call refresh() before.
*
* @param key
* @return
*/
public static Provider.Service getService(String key) {
- return (Provider.Service) services.get(key);
+ return services.get(key);
}
/**
@@ -219,9 +223,9 @@
// FIXME remove debug function
public static void printServices() {
refresh();
- java.util.Set s = services.keySet();
- for (java.util.Iterator i = s.iterator(); i.hasNext();) {
- Object key = i.next();
+ Set<String> s = services.keySet();
+ for (Iterator<String> i = s.iterator(); i.hasNext();) {
+ String key = i.next();
System.out.println(key + "=" + services.get(key));
}
}