当前位置: 首页>>代码示例>>Java>>正文


Java BasicPermission类代码示例

本文整理汇总了Java中java.security.BasicPermission的典型用法代码示例。如果您正苦于以下问题:Java BasicPermission类的具体用法?Java BasicPermission怎么用?Java BasicPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

BasicPermission类属于java.security包,在下文中一共展示了BasicPermission类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testEquals

import java.security.BasicPermission; //导入依赖的package包/类
/**
 * two BasicPermissions are equal if name and class are equal;
 * equal permissions should have the same hash code
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "equals",
    args = {java.lang.Object.class}
)
public void testEquals()
{
    BasicPermission b1 = new BasicPermissionImpl("abc");
    BasicPermission b2 = null;
    assertTrue(b1.equals(b1));
    assertFalse(b1.equals(null));
    assertFalse(b1.equals(new Object()));
    assertFalse(b1.equals("abc"));
    assertTrue(b1.equals(b2 = new BasicPermissionImpl("abc")));
    assertTrue(b1.hashCode() == b2.hashCode());
    assertFalse(b1.equals(new BasicPermission("abc"){}));
    assertFalse(b1.equals(new BasicPermissionImpl("abc.*")));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:BasicPermissionTest.java


示例2: testImplies

import java.security.BasicPermission; //导入依赖的package包/类
/**
 * implies() should return true if a permission is equal to or is implied
 * by wildcarded permission, false otherwise.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "implies",
    args = {java.security.Permission.class}
)
public void testImplies()
{
    BasicPermission b1 = new BasicPermissionImpl("a.b.c");
    assertTrue(b1.implies(b1));
    assertTrue(b1.implies(new BasicPermissionImpl("a.b.c")));
    assertFalse(b1.implies(new BasicPermissionImpl("a.b.c.*")));
    assertFalse(b1.implies(new BasicPermission("a.b.c"){}));
    assertTrue(new BasicPermissionImpl("a.b.*").implies(b1));
    assertTrue(new BasicPermissionImpl("a.*").implies(b1));
    assertTrue(new BasicPermissionImpl("*").implies(b1));
    assertFalse(new BasicPermissionImpl("a.b*").implies(b1));
    assertFalse(new BasicPermissionImpl("a.b.c.*").implies(b1));
    assertTrue(new BasicPermissionImpl("1.*").implies(new BasicPermissionImpl("1.234.*")));
    assertTrue(new BasicPermissionImpl("*").implies(new BasicPermissionImpl("*")));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:BasicPermissionTest.java


示例3: testEquals

import java.security.BasicPermission; //导入依赖的package包/类
/** Any of AllPermission instances are equal and have the same hash code */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "equals",
    args = {java.lang.Object.class}
)
public void testEquals()
{
    AllPermission a1 = new AllPermission();
    AllPermission a2 = new AllPermission();
    assertTrue(a1.equals(a2));
    assertTrue(a1.hashCode() == a2.hashCode());
    assertFalse(a1.equals(null));
    assertFalse(a1.equals(new BasicPermission("hgf"){}));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:AllPermissionTest.java


示例4: main

import java.security.BasicPermission; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	System.setSecurityManager(new SecurityManager());
	java.net.URL[] urls = new java.net.URL[1];
	Class<?> c = null;
	java.net.URLClassLoader ucl = null;
	try {
		URL url = new URL(args[0]);
		urls[0] = url;
		ucl = URLClassLoader.newInstance(urls, null);
		c = Class.forName("coucou.FileAccess", true, ucl);
	} catch (Exception e) {
		e.printStackTrace();
	}
	ProtectionDomain pd = c.getProtectionDomain();
	PermissionCollection coll = Policy.getPolicy().getPermissions(pd);
	Class<?> myPermission = Class.forName("mypackage.MyPermission");
	BasicPermission myperm = (BasicPermission) myPermission.newInstance();
	System.out.println(coll.implies(new java.io.FilePermission("test1.txt",
			"write"))
			+ ","
			+ coll.implies(myperm)
			+ ","
			+ coll
					.implies(new java.io.FilePermission("test2.txt",
							"write")) + ",");
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:27,代码来源:Support_PermissionCollection.java


示例5: main

import java.security.BasicPermission; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");

    StringBuffer sb = new StringBuffer();

    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");

    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");

    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            sb.append("BP breaks equals spec\n");
        }
    }
    if (!bp1.getName().equals(bp2.getName())) {
        if (bp1.equals(bp2)) {
            sb.append("BP breaks equals spec in another way\n");
        }
    }

    // Tests against common knowledge: If equals, then hashCode should be same
    if (bp1.equals(bp2)) {
        if (bp1.hashCode() != bp2.hashCode()) {
            sb.append("Equal objects have unequal hashCode?\n");
        }
    }

    if (sb.length() > 0) {
        throw new Exception(sb.toString());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:ExitVMEquals.java


示例6: main

import java.security.BasicPermission; //导入依赖的package包/类
public static void main (String argv[]) throws Exception {
     try {
         AccessController.checkPermission(
                     new BasicPermission("no such permission"){});
     } catch (NullPointerException npe) {
        throw new Exception("Unexpected NullPointerException for security" +
                     " debug option, -Djava.security.debug=failure");
     } catch (AccessControlException ace) {
     }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:FailureDebugOption.java


示例7: testAdd

import java.security.BasicPermission; //导入依赖的package包/类
/**
 * Can add any type of permissions. Cannot add if collection is read-only.
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "add",
    args = {java.security.Permission.class}
)
public void testAdd() {
    Permissions ps = new Permissions();
    Permission ap = new AllPermission();
    Permission bp = new BasicPermission("jhb23jhg5") {
    };
    Permission sp0 = new SecurityPermission("abc");
    Permission sp1 = new SecurityPermission("a.b.c");
    Permission sp2 = new SecurityPermission("a.b.*");
    Permission sp3 = new SecurityPermission("a.*");
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
        "26r ytf", new java.security.cert.Certificate[0]);
    Permission[] arr = new Permission[] {
        up1, up2, ap, bp, sp0, sp1, sp2, sp3,  };
    for (int i = 0; i < arr.length; i++) {
        ps.add(arr[i]);
    }

    //test add duplicate
    ps.add(up1);
    ps.add(sp0);

    ps.setReadOnly();
    try {
        ps.add(up1);
        fail("read-only flag is ignored");
    } catch (SecurityException ok) {
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:39,代码来源:PermissionsTest.java


示例8: testCollection

import java.security.BasicPermission; //导入依赖的package包/类
/**
     * newPermissionCollection() should return new BasicPermissionCollection on every invocation
     */
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "newPermissionCollection",
        args = {}
    )
    public void testCollection()
    {
        BasicPermission b1 = new BasicPermissionImpl("a.b.c");
        PermissionCollection pc1 = b1.newPermissionCollection();
        PermissionCollection pc2 = b1.newPermissionCollection();
//        assertTrue((pc1 instanceof BasicPermissionCollection) && (pc2 instanceof BasicPermissionCollection));
        assertNotSame(pc1, pc2);
    }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:18,代码来源:BasicPermissionTest.java


示例9: testImplies

import java.security.BasicPermission; //导入依赖的package包/类
/** AllPermission implies any other permission */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "Null parameter checking missed",
    method = "implies",
    args = {java.security.Permission.class}
)
public void testImplies()
{
    AllPermission a1 = new AllPermission();
    assertTrue(a1.implies(new AllPermission()));
    assertTrue(a1.implies(new BasicPermission("2323"){}));
    assertTrue(a1.implies(new UnresolvedPermission("2323", "", "", null)));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:15,代码来源:AllPermissionTest.java


示例10: testEquals

import java.security.BasicPermission; //导入依赖的package包/类
@SuppressWarnings("serial")
public void testEquals() {
    DelegationPermission dp1 = new DelegationPermission("\"AAA\" \"BBB\"");
    DelegationPermission dp2 = new DelegationPermission("\"AAA\" \"BBB\"");
    
    assertTrue(dp1.equals(dp1));
    assertFalse(dp1.equals(new DelegationPermission("\"aaa\" \"bbb\"")));
    assertTrue(dp2.equals(dp1));
    assertTrue(dp1.equals(dp2));
    assertTrue(dp1.hashCode() == dp2.hashCode());
    assertFalse(dp1.equals(new BasicPermission("\"AAA\""){}));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:DelegationPermissionTest.java


示例11: main

import java.security.BasicPermission; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	System.setSecurityManager(new SecurityManager());
	java.net.URL[] urls = new java.net.URL[1];
	Class<?> c = null;
	java.net.URLClassLoader ucl = null;
	try {
		URL url = new URL(args[0]);
		urls[0] = url;
		ucl = URLClassLoader.newInstance(urls, null);
		c = Class.forName("coucou.FileAccess", true, ucl);
	} catch (Exception e) {
		e.printStackTrace();
	}
	ProtectionDomain pd = c.getProtectionDomain();
	PermissionCollection coll = Policy.getPolicy().getPermissions(pd);
	Class<?> myPermission = Class.forName("mypackage.MyPermission");
	BasicPermission myperm = (BasicPermission) myPermission.newInstance();
	System.out.println(
	        coll.implies(new java.io.FilePermission("test1.txt", "write"))
			+ ","
			+ coll.implies(myperm)
               + ","
               + coll.implies(new java.io.FilePermission("test2.txt", "write"))
			+ ","
			+ coll.implies(new java.io.FilePermission("test3.txt", "read"))
			+ ",");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:28,代码来源:Support_PermissionCollection.java


示例12: combine

import java.security.BasicPermission; //导入依赖的package包/类
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, 
                                          ProtectionDomain[] assignedDomains) 
        {            
            log.info("MyDomainCombiner.combine() has been called");
            if (currentDomains[0] == null) {
                throw new RuntimeException ("A protection domain of the main execution thread is null. Test failed.");
            }
            
            //log.info("A " + (index + 1) + " call for DomainCombiner.combine() method");
            ProtectionDomain originalPD = currentDomains[1];
            PermissionCollection perms = AccessTestClass.policy.getPermissions(originalPD);
            //log.info("A set of permissions of the protection domain of the main execution thread is:");
            //log.info(perms);
            if (!perms.isReadOnly())
            {
                BasicPermission p = new PropertyPermission(propertyName, "read");
                log.info("A permission which will be added: " + p+ "\n");
                perms.add(p);                
                perms.setReadOnly();
            }
            
            //currentDomains[1] = new ProtectionDomain(originalPD.getCodeSource(), perms, originalPD.getClassLoader(), null);
            ProtectionDomain[] pd = new ProtectionDomain[1];
            pd[0] = new ProtectionDomain(originalPD.getCodeSource(), perms, originalPD.getClassLoader(), null);
//            dummyCurrentDomains[index] = currentDomains;
//            dummyAssignedDomains[index] = assignedDomains;
            //index++;

            //return currentDomains;
            return pd;
        }
 
开发者ID:freeVM,项目名称:freeVM,代码行数:32,代码来源:F_AccessControllerTest_03.java


示例13: testElements

import java.security.BasicPermission; //导入依赖的package包/类
/**
 * Should return non-null empty enumeration for empty collection. For
 * non-empty collection, should always return enumeration over unique
 * elements.
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "elements",
    args = {}
)
public void testElements() {
    Permissions ps = new Permissions();
    Permission ap = new AllPermission();
    Permission bp = new BasicPermission("jhb23jhg5") {

        public PermissionCollection newPermissionCollection() {
            return null;
        }
    };
    Permission sp = new SecurityPermission("abc");
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
        "26r ytf", new java.security.cert.Certificate[0]);

    Enumeration<Permission> en = ps.elements();
    assertNotNull(en);
    assertFalse(en.hasMoreElements());

    ps.add(up1);
    en = ps.elements();
    assertTrue(en.hasMoreElements());
    assertTrue(up1.equals(en.nextElement()));
    assertFalse(en.hasMoreElements());

    ps.add(up1);
    en = ps.elements();
    assertTrue(en.hasMoreElements());
    assertTrue(up1.equals(en.nextElement()));
    //assertFalse(en.hasMoreElements());

    Permission[] arr = new Permission[] {
        ap, bp, sp, up1, up2 };
    for (int i = 0; i < arr.length; i++) {
        ps.add(arr[i]);
    }
    en = ps.elements();
    Collection<Permission> els = new ArrayList<Permission>();
    while (en.hasMoreElements()) {
        els.add(en.nextElement());
    }
    //assertEquals(5, els.size());
    assertTrue(els.containsAll(Arrays.asList(arr)));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:55,代码来源:PermissionsTest.java



注:本文中的java.security.BasicPermission类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。