Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 76382 invoked from network); 24 Jun 2006 21:49:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Jun 2006 21:49:55 -0000 Received: (qmail 89437 invoked by uid 500); 24 Jun 2006 21:49:55 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 89395 invoked by uid 500); 24 Jun 2006 21:49:55 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 89384 invoked by uid 99); 24 Jun 2006 21:49:54 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Jun 2006 14:49:54 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Jun 2006 14:49:52 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 98BF11A983A; Sat, 24 Jun 2006 14:49:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r416966 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security: ./ fortress/ Date: Sat, 24 Jun 2006 21:49:31 -0000 To: harmony-commits@incubator.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060624214932.98BF11A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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/* */grantEntries, - List/* */keystoreEntries) throws IOException, + public void scanStream(Reader r, Collection grantEntries, + List keystoreEntries) throws IOException, InvalidFormatException { StreamTokenizer st = configure(new StreamTokenizer(r)); //main parsing loop @@ -153,7 +153,7 @@ * * * - * @return succesfully parsed KeystoreEntry + * @return successfully parsed KeystoreEntry * @throws IOException * if stream reading failed * @throws InvalidFormatException @@ -194,7 +194,7 @@ * * * - * @return succesfully parsed GrantEntry + * @return successfully parsed GrantEntry * @throws IOException * if stream reading failed * @throws InvalidFormatException @@ -253,10 +253,10 @@ * * * - * 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/* */readPermissionEntries( + protected Collection readPermissionEntries( StreamTokenizer st) throws IOException, InvalidFormatException { - // FIXME 1.5 signature - Collection/* */permissions = new HashSet(); + Collection permissions = new HashSet(); parsing: while (true) { switch (st.nextToken()) { @@ -443,14 +442,12 @@ /** * Collection of PrincipalEntries of grant clause. */ - // FIXME 1.5 signature - public Collection/* */principals; + public Collection principals; /** * Collection of PermissionEntries of grant clause. */ - // FIXME 1.5 signature - public Collection/* */permissions; + public Collection permissions; /** * Adds specified element to the principals collection. @@ -458,7 +455,7 @@ */ public void addPrincipal(PrincipalEntry pe) { if (principals == null) { - principals = new HashSet(); + principals = new HashSet(); } 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 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 prs, + Collection 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 null. */ - public Collection getPermissions() { + public Collection 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/* */grants = new HashSet(); + private final Set grants = new HashSet(); // 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> cache = new WeakHashMap>(); // 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 null if the domain is null. */ @@ -196,17 +197,17 @@ } } } - Collection pc = (Collection)cache.get(pd); + Collection 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(); + Iterator 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 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(); + Iterator 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 fresh = new HashSet(); + 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/**/parse(URL location, Properties system) + public Collectionparse(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/**/grantEntries = new HashSet(); - List/**/keystores = new ArrayList(); + Collection grantEntries = new HashSet(); + List keystores = new ArrayList(); 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/**/result = new HashSet(); - for (Iterator iter = grantEntries.iterator(); iter.hasNext();) { - DefaultPolicyScanner.GrantEntry ge = (DefaultPolicyScanner.GrantEntry) iter + Collection result = new HashSet(); + for (Iterator 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/**/principals = new HashSet(); - Set/**/permissions = new HashSet(); + Setprincipals = new HashSet(); + Setpermissions = new HashSet(); 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 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 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 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 certs = new HashSet(); 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 null */ - protected KeyStore initKeyStore(List/**/keystores, + protected KeyStore initKeyStore(Listkeystores, 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 { /** * 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 { /** * 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 { /** * 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 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 { + private String key; + /** * Constructor with a property key parameter. */ public SecurityPropertyAccessor(String key) { - super(key); + super(); + this.key = key; } + public PrivilegedAction 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 implements PrivilegedAction { + private String key; + /** * Acceptable provider superclass. */ - public Class expectedType; + private Class 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 expected) { + super(); + this.key = key; + this.expectedType = expected; } /** @@ -164,10 +176,10 @@ * The key 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 urls = new ArrayList(); 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() { - 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/**/perms) { + Collection perms) { Permissions pc = new Permissions(); if (perms != null) { - for (Iterator iter = perms.iterator(); iter.hasNext();) { - Permission element = (Permission) iter.next(); + for (Iterator 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 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.
- * 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.
// 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 ACC_CACHE = new WeakHashMap(); /** * 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 services = new HashMap(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 providers = new ArrayList(20); // Hash for quick provider access by name - private static HashMap providersNames = new HashMap(20); + private static final Map providersNames = new HashMap(20); static { - AccessController.doPrivileged(new java.security.PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { 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 getProvidersList() { + return new ArrayList(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 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 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 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 s = services.keySet(); + for (Iterator i = s.iterator(); i.hasNext();) { + String key = i.next(); System.out.println(key + "=" + services.get(key)); } }