You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2010/06/24 03:59:01 UTC
svn commit: r957402 -
/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/
Author: peter_firmstone
Date: Thu Jun 24 01:59:00 2010
New Revision: 957402
URL: http://svn.apache.org/viewvc?rev=957402&view=rev
Log:
River-340 Further Refactoring
Modified:
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CertificateGrant.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ClassLoaderGrant.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CodeSourceGrant.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrant.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrantBuilder.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PrincipalGrant.java
incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ProtectionDomainGrant.java
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CertificateGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CertificateGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CertificateGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CertificateGrant.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -32,8 +45,8 @@ class CertificateGrant extends CodeSourc
}
}
+ @Override
public boolean implies(ProtectionDomain pd) {
- CodeSource codeSource = null;
Certificate[] c = null;
Principal[] pals = null;
if (pd != null){
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ClassLoaderGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ClassLoaderGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ClassLoaderGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ClassLoaderGrant.java Thu Jun 24 01:59:00 2010
@@ -1,21 +1,27 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
import java.lang.ref.WeakReference;
-import java.security.CodeSource;
import java.security.Permission;
import java.security.Principal;
import java.security.ProtectionDomain;
-import java.security.cert.Certificate;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
/**
*
@@ -29,6 +35,7 @@ class ClassLoaderGrant extends Protectio
super(domain, groups, perm);
}
+ @Override
public boolean implies(ProtectionDomain pd) {
ClassLoader cl = null;
Principal[] pals = null;
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CodeSourceGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CodeSourceGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CodeSourceGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/CodeSourceGrant.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -70,18 +83,6 @@ class CodeSourceGrant extends PrincipalG
return implies(codeSource, pals);
}
- public boolean implies(ClassLoader cl, Principal[] pal) {
- return impliesClassLoader(cl) && implies(pal);
- }
-
- public boolean implies(CodeSource codeSource, Principal[] pal) {
- return impliesCodeSource(codeSource) && implies(pal);
- }
-
- public boolean implies(Certificate[] signers, Principal[] pal) {
- return impliesCertificates(signers) && implies(pal);
- }
-
public Collection<Permission> getPermissions() {
return Collections.unmodifiableCollection(permissions);
}
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrant.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -13,67 +26,47 @@ import java.security.cert.Certificate;
import java.util.Collection;
/**
- *
- * @author peter
+ * PermissionGrant's are expected to be effectively immutable,
+ * threadsafe and have a good hashCode implementation to perform well in
+ * Collections.
+ * @author Peter Firmstone
*/
public interface PermissionGrant {
- // Implied Context of Grant
- public static final int CLASSLOADER = 0;
- public static final int CODESOURCE = 1;
- public static final int PROTECTIONDOMAIN = 2;
- public static final int CODESOURCE_CERTS = 3;
/**
- * This is a multi comparison runtime permissions check for Policy's
- * this method must test based on the context.
+ * A DynamicPolicy implementation can use a PermissionGrant as a container
+ * for Dynamic Grant's. A PermissionGrant is first asked by the Policy
+ * if it implies a Particular ProtectionDomain, if it does, the Policy
+ * calls getPermissions.
* @param pd ProtectionDomain
* @return
*/
public boolean implies(ProtectionDomain pd);
/**
- * Checks if passed ClassLoader matches this PolicyEntry. Null ProtectionDomain of
- * PolicyEntry implies any ClassLoader, unless the ProtectionDomain has
- * become garbage collected, in which case it will be false;
- *
- * This implies is public to assist in removal of Permission grants
- * from a ClassLoader space. In other words it ignores context.
- *
- * It isn't very smart, it misses other grants, so isn't a guarantee that
- * a permission grant won't apply to a particluar ClassLoader, in the
- * case of Principals and Certificate grants.
- *
- * non-null ProtectionDomain's are
- * compared with equals();
+ * Checks if this PermissionGrant applies to the passed in ClassLoader
+ * and Principal's.
*/
public boolean implies(ClassLoader cl, Principal[] pal);
/**
- * Checks if passed CodeSource matches this PolicyEntry. Null CodeSource of
- * PolicyEntry implies any CodeSource; non-null CodeSource forwards to its
- * imply() method.
+ * Checks if this PermissionGrant applies to the passed in CodeSource
+ * and Principal's.
* @param cs
* @return
*/
public boolean implies(CodeSource codeSource, Principal[] pal);
/**
- * Checks if specified Principals match this PolicyEntry. Null or empty set
- * of Principals of PolicyEntry implies any Principals; otherwise specified
- * array must contain all Principals of this PolicyEntry.
- * @param prs
- * @return
- */
- public boolean implies(Principal[] prs);
- /**
- * Certificate was chosen as it allows multiple different implementations
- * even if a CodeSource was created with CodeSigner.
+ * Checks if this PermissionGrant applies to the passed in Certificate's
+ * and Principal's.
*/
public boolean implies(Certificate[] certs, Principal[] pal);
/**
- * Returns unmodifiable collection of permissions defined by this
+ * Returns an unmodifiable collection of permissions defined by this
* PolicyEntry, may be <code>null</code>.
* @return
*/
public Collection<Permission> getPermissions();
/**
- * Returns true if this PolicyEntry defines no Permissions, false otherwise.
+ * Returns true if this PermissionGrant defines no Permissions, or if
+ * a PermissionGrant was made to a ProtectionDomain that no longer exists.
*/
public boolean isVoid();
@Override
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrantBuilder.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrantBuilder.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrantBuilder.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PermissionGrantBuilder.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -13,10 +26,20 @@ import java.security.ProtectionDomain;
import java.security.cert.Certificate;
/**
+ * The PermissionGrantBuilder creates Dynamic PermissionGrant's based on
+ * information provided by the user.
+ *
* Single Thread use only.
* @author Peter Firmstone.
*/
public class PermissionGrantBuilder {
+ /**
+ * Implied Context of Grant
+ */
+ public static final int CLASSLOADER = 0;
+ public static final int CODESOURCE = 1;
+ public static final int PROTECTIONDOMAIN = 2;
+ public static final int CODESOURCE_CERTS = 3;
// Store CodeSource
private CodeSource cs;
private Certificate[] certs;
@@ -31,15 +54,25 @@ public class PermissionGrantBuilder {
reset();
}
+ /**
+ * Resets builder back to initial state, ready to recieve new information
+ * for building a new PermissionGrant.
+ */
public void reset(){
cs = null;
certs = null;
domain = null;
principals = null;
permissions = null;
- context = PermissionGrant.CODESOURCE;
+ context = CODESOURCE;
}
+ /**
+ * This method set's the Context of the applied Grant, that is if a
+ * Permission is to be granted directly to a PermissionDomain
+ * @param context
+ * @return
+ */
public PermissionGrantBuilder context(int context){
if ( context < 0 ){
throw new IllegalStateException("context must be >= 0");
@@ -56,7 +89,7 @@ public class PermissionGrantBuilder {
return this;
}
- public PermissionGrantBuilder clazz(Class cl){
+ public PermissionGrantBuilder clazz(Class cl){
domain = new WeakReference<ProtectionDomain>(cl.getProtectionDomain());
return this;
}
@@ -79,13 +112,13 @@ public class PermissionGrantBuilder {
public PermissionGrant build(){
switch (context){
- case PermissionGrant.CLASSLOADER:
+ case CLASSLOADER:
return new ClassLoaderGrant(domain, principals, permissions);
- case PermissionGrant.CODESOURCE:
+ case CODESOURCE:
return new CodeSourceGrant(cs, principals, permissions);
- case PermissionGrant.CODESOURCE_CERTS:
+ case CODESOURCE_CERTS:
return new CertificateGrant(certs, principals, permissions);
- case PermissionGrant.PROTECTIONDOMAIN:
+ case PROTECTIONDOMAIN:
return new ProtectionDomainGrant(domain, principals, permissions);
default:
return null;
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PrincipalGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PrincipalGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PrincipalGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/PrincipalGrant.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -10,6 +23,7 @@ import java.security.CodeSigner;
import java.security.CodeSource;
import java.security.Principal;
import java.security.acl.Group;
+import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -68,7 +82,7 @@ abstract class PrincipalGrant implements
}
/**
- * Utility Method, really belongs somewhere else.
+ * Utility Method, really belongs somewhere else, but most subclasses use it.
* @param codeSource
* @return
*/
@@ -89,5 +103,23 @@ abstract class PrincipalGrant implements
}
return result;
}
+
+ public boolean implies(ClassLoader cl, Principal[] pal) {
+ return impliesClassLoader(cl) && implies(pal);
+ }
+
+ public boolean implies(CodeSource codeSource, Principal[] pal) {
+ return impliesCodeSource(codeSource) && implies(pal);
+ }
+
+ public boolean implies(Certificate[] certs, Principal[] pal) {
+ return impliesCertificates(certs) && implies(pal);
+ }
+
+ protected abstract boolean impliesCertificates(Certificate[] certs);
+
+ protected abstract boolean impliesClassLoader(ClassLoader cl);
+
+ protected abstract boolean impliesCodeSource(CodeSource codeSource);
}
Modified: incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ProtectionDomainGrant.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ProtectionDomainGrant.java?rev=957402&r1=957401&r2=957402&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ProtectionDomainGrant.java (original)
+++ incubator/river/jtsk/trunk/src/org/apache/river/imp/security/policy/util/ProtectionDomainGrant.java Thu Jun 24 01:59:00 2010
@@ -1,6 +1,19 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * 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 org.apache.river.imp.security.policy.util;
@@ -43,23 +56,21 @@ class ProtectionDomainGrant extends Prin
this.permissions.addAll(Arrays.asList(perm));
}
}
- // for grant
- public boolean implies(ProtectionDomain pd) {
- // ProtectionDomain comparison
- return impliesProtectionDomain(pd);
- }
-
- /**
+
+ /*
* Checks if passed ProtectionDomain matches this PolicyEntry. Null ProtectionDomain of
* PolicyEntry implies any ProtectionDomain; non-null ProtectionDomain's are
* compared with equals();
- */
- protected boolean impliesProtectionDomain(ProtectionDomain pd) {
+ */
+ // for grant
+ public boolean implies(ProtectionDomain pd) {
+ // ProtectionDomain comparison
if (hasDomain == false) return true;
if (pd == null) return false;
if (domain.get() == null ) return false; // hasDomain already true
return pd.equals(domain.get()); // pd not null
}
+
// This is only here for revoke.
protected boolean impliesClassLoader(ClassLoader cl) {
if (hasDomain == false) return true;
@@ -96,17 +107,5 @@ class ProtectionDomainGrant extends Prin
if (hasDomain == true && domain.get() == null) return true;
return false;
}
-
- public boolean implies(ClassLoader cl, Principal[] pal) {
- return impliesClassLoader(cl) && implies(pal);
- }
-
- public boolean implies(CodeSource codeSource, Principal[] pal) {
- return impliesCodeSource(codeSource) && implies(pal);
- }
-
- public boolean implies(Certificate[] certs, Principal[] pal) {
- return impliesCertificates(certs) && implies(pal);
- }
}