I've attached PCodeSource, it extends CodeSource and overrides toString() and has a getRequiredPerms() method for retrieving the Permissions the CodeSource requires to execute. These can be added to any AuthPermission's required and granted dynamically by clients.

PCodeSource will contain the permission's declared in META-INF/permissions.perm

I intend to implement findClass(String name) in PreferredClassLoader, allowing us to use PCodeSource as a replacement for CodeSource, to be included in ProtectionDomain's.

Once this is implemented when you've got debugging enabled, the AccessControlContext will print out the ProtectionDomain when an AccessControlException is thrown, so in the printout, you'll get the CodeSource, the Permission's it requires to execute, any Principals and the Permission's the ProtectionDomain has.

I earlier stated that the AccessControlException containing the information could be wrapped in a RemoteException, but this is incorrect.

It will enable me to implement a new method in net.jini.security.Security:

public Permission[] getRequired(Class cl);

BasicProxyPreparer has the following method:

   /**
    * Returns the permissions to grant to proxies, or an empty array if no
    * permissions should be granted. The return value need not be newly
    * created, but cannot be <code>null</code>. <p>
    *
    * The default implementation returns the value of {@link
    * #permissions}. <p>
    *
    * Subclasses may wish to override this method, for example, to grant
    * permissions that depend on principal constraints found on the proxy.
    *
    * @param proxy the proxy being prepared
    * @return the permissions to grant to the proxy
    */
   protected Permission[] getPermissions(Object proxy) {
   return permissions;
   }

So I'd need to extend BasicProxyPreparer to return the required permissions as well as those specified in the BasicProxyPreparer.

Question, you download a proxy, authenticate and verify it, but it needs some additional permissions to run:

Does the client need to know the permission's being requested?

public Permission[] getRequired(Object proxy);

Or should we just let the user's GrantPermission's limit the requested permissions?

My experience is, it's usually not advisable to ask a user if a list of permissions should be granted.

What do you think?

Regards,

Peter.

P.S. I've cc'd some very capable alumni, I'm hoping they might find time to drop in n say hello and occasionally lend some advice.
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.jini.loader.pref;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.security.CodeSource;
import java.security.Permission;
import java.security.cert.Certificate;

/**
 *
 * @author peter
 */
public class PCodeSource extends CodeSource {
    private static final long serialVersionUID = 1L;
    private Permission[] permissions;
    
    public PCodeSource(URL codebase, Certificate[] certs, Permission[] perms){
        super(codebase, certs );
        permissions = perms.clone();
    }
    
    public String toString(){
        StringBuilder sb = new StringBuilder(120);
        sb.append(super.toString())
                .append("\n")
                .append("Information only, minimum Permissions required for execution:\n");
        int l = permissions.length;
        for (int i = 0; i < l ; i++){
            sb.append(permissions[i].toString());
        }
        return sb.toString();
    }
    
    public Permission [] getRequiredPerms(){
        return permissions.clone();
    }
    
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
        in.defaultReadObject();
        // defensive copy of array reference to prevent stolen reference
        permissions = permissions.clone();
    }
    
    private void writeObject(ObjectOutputStream out) throws IOException{
        out.defaultWriteObject();
    }
}

Reply via email to