本文整理汇总了C#中Permission.getClass方法的典型用法代码示例。如果您正苦于以下问题:C# Permission.getClass方法的具体用法?C# Permission.getClass怎么用?C# Permission.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permission
的用法示例。
在下文中一共展示了Permission.getClass方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add
/**
* Adds a permission to the collection. The first added permission must be a
* subclass of BasicPermission, next permissions must be of the same class
* as the first one.
*
* @see java.security.PermissionCollection#add(java.security.Permission)
*/
public override void add(Permission permission)
{
if (isReadOnly()) {
throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$
}
if (permission == null) {
throw new java.lang.IllegalArgumentException("invalid null permission"); //$NON-NLS-1$
}
java.lang.Class inClass = permission.getClass();
if (permClass != null) {
if (permClass != inClass) {
throw new java.lang.IllegalArgumentException("invalid permission: "+permission);
}
} else if( !(permission is BasicPermission)) {
throw new java.lang.IllegalArgumentException("invalid permission: " + permission);
}
else
{
// this is the first element provided that another thread did not add
lock (this) {
if (permClass != null && inClass != permClass) {
throw new java.lang.IllegalArgumentException("invalid permission: " + permission);
}
permClass = inClass;
}
}
String name = permission.getName();
items.put(name, permission);
allEnabled = allEnabled || (name.length() == 1 && '*' == name.charAt(0));
}
示例2: add
/**
* Adds an unresolved permission to this {@code
* UnresolvedPermissionCollection}.
*
* @param permission
* the permission to be added.
* @throws SecurityException
* if this collection is read only.
* @throws IllegalArgumentException
* if {@code permission} is {@code null} or not an {@code
* UnresolvedPermission}.
*/
public override void add(Permission permission)
{
if (isReadOnly())
{
throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$
}
if (permission == null
|| permission.getClass() != typeof(UnresolvedPermission).getClass())
{
throw new java.lang.IllegalArgumentException("invalid permission: " + permission);
}
lock (klasses)
{
String klass = permission.getName();
java.util.Collection<Permission> klassMates = (java.util.Collection<Permission>)klasses.get(klass);
if (klassMates == null)
{
klassMates = new java.util.HashSet<Permission>();
klasses.put(klass, klassMates);
}
klassMates.add(permission);
}
}
示例3: resolveCollection
/**
* Resolves all permissions of the same class as the specified target
* permission and adds them to the specified collection. If passed
* collection is {@code null} and some unresolved permissions were resolved,
* an appropriate new collection is instantiated and used. All resolved
* permissions are removed from this unresolved collection, and collection
* with resolved ones is returned.
*
* @param target
* a kind of permissions to be resolved.
* @param holder
* an existing collection for storing resolved permissions.
* @return a collection containing resolved permissions (if any found)
*/
internal PermissionCollection resolveCollection(Permission target,
PermissionCollection holder)
{
String klass = target.getClass().getName();
if (klasses.containsKey(klass))
{
lock (klasses)
{
java.util.Collection<Object> klassMates = (java.util.Collection<Object>)klasses.get(klass);
for (java.util.Iterator<Object> iter = klassMates.iterator(); iter.hasNext(); )
{
UnresolvedPermission element = (UnresolvedPermission)iter
.next();
Permission resolved = element.resolve(target.getClass());
if (resolved != null)
{
if (holder == null)
{
holder = target.newPermissionCollection();
if (holder == null)
{
holder = new PermissionsHash();
}
}
holder.add(resolved);
iter.remove();
}
}
if (klassMates.size() == 0)
{
klasses.remove(klass);
}
}
}
return holder;
}
示例4: hasUnresolved
/**
* Returns true if this collection contains unresolved permissions
* with the same classname as argument permission.
*/
internal bool hasUnresolved(Permission permission)
{
return klasses.containsKey(permission.getClass().getName());
}
示例5: implies
/**
* Indicates whether the argument permission is implied by the receiver.
*
* @return boolean {@code true} if the argument permission is implied by the
* receiver, and {@code false} if it is not.
* @param permission
* the permission to check.
* @see Permission
*/
public override bool implies(Permission permission)
{
if (permission == null || permission.getClass() != permClass) {
return false;
}
if (allEnabled) {
return true;
}
String checkName = permission.getName();
//first check direct coincidence
if (items.containsKey(checkName)) {
return true;
}
//Special treat with RuntimePermission exitVM.*
if(items.containsKey("exitVM") || items.containsKey("exitVM.*")){
if(checkName.endsWith("exitVM")){
return true;
}
if(checkName.startsWith("exitVM.") && checkName.length() > "exitVM.".length()){
return true;
}
}
//now check if there are suitable wildcards
//suppose we have "a.b.c", let's check "a.b.*" and "a.*"
char[] name = checkName.toCharArray();
//I presume that "a.b.*" does not imply "a.b."
//so the dot at end is ignored
int pos = name.Length - 2;
for (; pos >= 0; pos--) {
if (name[pos] == '.') {
break;
}
}
while (pos >= 0) {
name[pos + 1] = '*';
if (items.containsKey(new String(name, 0, pos + 2))) {
return true;
}
for (--pos; pos >= 0; pos--) {
if (name[pos] == '.') {
break;
}
}
}
return false;
}
示例6: implies
/**
* Indicates whether the specified permission is implied by this permission.
*
* @param permission
* the permission to check against this permission.
* @return {@code true} if the specified permission is implied by this
* permission, {@code false} otherwise.
*/
public override bool implies(Permission permission)
{
if (permission != null && permission.getClass() == this.getClass())
{
String name = getName();
String thatName = permission.getName();
if (this is java.lang.RuntimePermission)
{
if (thatName.equals("exitVM"))
{
thatName = "exitVM.*";
}
if (name.equals("exitVM"))
{
name = "exitVM.*";
}
}
return nameImplies(name, thatName);
}
return false;
}